diff --git a/java/api/src/main/java/com/exadel/frs/core/trainservice/cache/EmbeddingCollection.java b/java/api/src/main/java/com/exadel/frs/core/trainservice/cache/EmbeddingCollection.java index 7ff117626..2a9d22eb2 100644 --- a/java/api/src/main/java/com/exadel/frs/core/trainservice/cache/EmbeddingCollection.java +++ b/java/api/src/main/java/com/exadel/frs/core/trainservice/cache/EmbeddingCollection.java @@ -49,10 +49,10 @@ public static EmbeddingCollection from(final Stream } // TODO: provide immutable wrapper for EmbeddingCollection here - public T doWithReadLock(Function readAndDo) { + public T doWithReadLock(Function, T> readAndDo) { readLock.lock(); try { - return readAndDo.apply(this); + return readAndDo.apply(exposeMap()); } finally { readLock.unlock(); } @@ -69,7 +69,8 @@ Collection getEmbeddings() { return Collections.unmodifiableCollection(mapping.values()); } - public Map exposeMap() { + // package private for test purposes + Map exposeMap() { return Collections.unmodifiableMap(mapping); } diff --git a/java/api/src/main/java/com/exadel/frs/core/trainservice/component/classifiers/EuclideanDistanceClassifier.java b/java/api/src/main/java/com/exadel/frs/core/trainservice/component/classifiers/EuclideanDistanceClassifier.java index 7e7b23ac0..eb0ae8903 100644 --- a/java/api/src/main/java/com/exadel/frs/core/trainservice/component/classifiers/EuclideanDistanceClassifier.java +++ b/java/api/src/main/java/com/exadel/frs/core/trainservice/component/classifiers/EuclideanDistanceClassifier.java @@ -55,7 +55,7 @@ public List> predict(final double[] input, final String api var coefficients = getSimilarityCoefficients(); return embeddingCacheProvider.getOrLoad(apiKey) .doWithReadLock( - ec -> ec.exposeMap().entrySet() + ec -> ec.entrySet() .stream() .map(e -> Pair.of(e.getKey(), e.getValue().getDistance(inputFace))) .map(p -> Pair.of(p.getKey(), calculateSimilarity(p.getValue(), coefficients)))