File tree Expand file tree Collapse file tree 2 files changed +9
-9
lines changed
src/main/java/de/rwth/idsg/steve/service Expand file tree Collapse file tree 2 files changed +9
-9
lines changed Original file line number Diff line number Diff line change 33import com .google .common .cache .Cache ;
44import com .google .common .cache .CacheBuilder ;
55import de .rwth .idsg .steve .service .dto .UnidentifiedIncomingObject ;
6+ import lombok .extern .slf4j .Slf4j ;
67
78import java .util .Comparator ;
89import java .util .List ;
10+ import java .util .concurrent .ExecutionException ;
911import java .util .stream .Collectors ;
1012
1113/**
1416 * @author Sevket Goekay <goekay@dbis.rwth-aachen.de>
1517 * @since 20.03.2018
1618 */
19+ @ Slf4j
1720public class UnidentifiedIncomingObjectService {
1821
1922 private final Cache <String , UnidentifiedIncomingObject > objectsHolder ;
@@ -33,13 +36,11 @@ public List<UnidentifiedIncomingObject> getObjects() {
3336 }
3437
3538 public void processNewUnidentified (String key ) {
36- synchronized (objectsHolder ) {
37- UnidentifiedIncomingObject value = objectsHolder .getIfPresent (key );
38- if (value == null ) {
39- objectsHolder .put (key , new UnidentifiedIncomingObject (key ));
40- } else {
41- value .updateStats ();
42- }
39+ try {
40+ objectsHolder .get (key , () -> new UnidentifiedIncomingObject (key ))
41+ .updateStats ();
42+ } catch (ExecutionException e ) {
43+ log .error ("Error occurred" , e );
4344 }
4445 }
4546}
Original file line number Diff line number Diff line change @@ -18,10 +18,9 @@ public class UnidentifiedIncomingObject {
1818
1919 public UnidentifiedIncomingObject (String key ) {
2020 this .key = key ;
21- updateStats ();
2221 }
2322
24- public void updateStats () {
23+ public synchronized void updateStats () {
2524 numberOfAttempts ++;
2625 lastAttemptTimestamp = DateTime .now ();
2726 }
You can’t perform that action at this time.
0 commit comments