Browse code

UDL-218 Fix: dispose message if either pending or versions are null

Thomas Fricker authored on 13/04/2018 08:13:19
Showing 3 changed files
... ...
@@ -86,7 +86,7 @@ public class IndexOnDeliveryAction implements IDeliveryDoneAction {
86 86
 		}
87 87
 		if (pending.getVersions().isEmpty()) {
88 88
 			logger.warn("[{}] No pending versions", env.getId());
89
-			Activator.getActive().remove(env.getId());
89
+			IndexingFilter.deliveryFinished(env.getId());
90 90
 			return;
91 91
 		}
92 92
 
... ...
@@ -29,8 +29,14 @@ public final class ActiveDeliveries {
29 29
 
30 30
 	public ActiveDeliveries() {
31 31
 		// we can expire those as postfix will retry
32
-		pending = CacheBuilder.newBuilder().expireAfterWrite(1, TimeUnit.MINUTES).concurrencyLevel(4)
33
-				.initialCapacity(512).build();
32
+		CacheBuilder<Object, Object> builder = CacheBuilder.newBuilder().expireAfterAccess(5, TimeUnit.MINUTES)
33
+				.concurrencyLevel(4).initialCapacity(512);
34
+		pending = builder.removalListener(notif -> {
35
+			try {
36
+				((PendingInsert) notif.getValue()).getMessage().dispose();
37
+			} catch (Exception e) {
38
+			}
39
+		}).build();
34 40
 	}
35 41
 
36 42
 	public void put(String id, PendingInsert pi) {
... ...
@@ -46,8 +46,11 @@ public class IndexingFilter implements IMessageFilter {
46 46
 	}
47 47
 
48 48
 	public static void deliveryFinished(String id) {
49
-		Activator.getActive().get(id).getMessage().dispose();
50
-		Activator.getActive().remove(id);
49
+		PendingInsert pending = Activator.getActive().get(id);
50
+		if (pending != null) {
51
+			pending.getMessage().dispose();
52
+			Activator.getActive().remove(id);
53
+		}
51 54
 	}
52 55
 
53 56
 }