File tree 2 files changed +9
-9
lines changed
src/main/java/de/rwth/idsg/steve/service
2 files changed +9
-9
lines changed Original file line number Diff line number Diff line change 3
3
import com .google .common .cache .Cache ;
4
4
import com .google .common .cache .CacheBuilder ;
5
5
import de .rwth .idsg .steve .service .dto .UnidentifiedIncomingObject ;
6
+ import lombok .extern .slf4j .Slf4j ;
6
7
7
8
import java .util .Comparator ;
8
9
import java .util .List ;
10
+ import java .util .concurrent .ExecutionException ;
9
11
import java .util .stream .Collectors ;
10
12
11
13
/**
14
16
* @author Sevket Goekay <goekay@dbis.rwth-aachen.de>
15
17
* @since 20.03.2018
16
18
*/
19
+ @ Slf4j
17
20
public class UnidentifiedIncomingObjectService {
18
21
19
22
private final Cache <String , UnidentifiedIncomingObject > objectsHolder ;
@@ -33,13 +36,11 @@ public List<UnidentifiedIncomingObject> getObjects() {
33
36
}
34
37
35
38
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 );
43
44
}
44
45
}
45
46
}
Original file line number Diff line number Diff line change @@ -18,10 +18,9 @@ public class UnidentifiedIncomingObject {
18
18
19
19
public UnidentifiedIncomingObject (String key ) {
20
20
this .key = key ;
21
- updateStats ();
22
21
}
23
22
24
- public void updateStats () {
23
+ public synchronized void updateStats () {
25
24
numberOfAttempts ++;
26
25
lastAttemptTimestamp = DateTime .now ();
27
26
}
You can’t perform that action at this time.
0 commit comments