Browse code

BM-12943 Fix: dispose message after delivery

Thomas Fricker authored on 09/03/2018 11:39:01
Showing 5 changed files
... ...
@@ -52,7 +52,7 @@ public class Activator implements BundleActivator {
52 52
 		mailIndex = null;
53 53
 	}
54 54
 
55
-	static ActiveDeliveries getActive() {
55
+	public static ActiveDeliveries getActive() {
56 56
 		return active;
57 57
 	}
58 58
 
... ...
@@ -44,7 +44,7 @@ import net.bluemind.lib.jutf7.UTF7Converter;
44 44
 import net.bluemind.lmtp.backend.DeliveredVersion;
45 45
 import net.bluemind.lmtp.backend.IDeliveryDoneAction;
46 46
 import net.bluemind.lmtp.backend.LmtpEnvelope;
47
-import net.bluemind.lmtp.filter.indexing.impl.ActiveDeliveries;
47
+import net.bluemind.lmtp.filter.indexing.impl.IndexingFilter;
48 48
 import net.bluemind.lmtp.filter.indexing.impl.PendingInsert;
49 49
 import net.bluemind.locator.client.LocatorClient;
50 50
 import net.bluemind.mailbox.api.IMailboxFolderHierarchy;
... ...
@@ -55,19 +55,17 @@ public class IndexOnDeliveryAction implements IDeliveryDoneAction {
55 55
 
56 56
 	private static final Logger logger = LoggerFactory.getLogger(IndexOnDeliveryAction.class);
57 57
 
58
-	private final ActiveDeliveries active;
59 58
 	private Cache<String, ItemValue<Mailbox>> boxToUid;
60 59
 	private String core;
61 60
 
62 61
 	public IndexOnDeliveryAction() {
63
-		active = Activator.getActive();
64 62
 		boxToUid = CacheBuilder.newBuilder().expireAfterAccess(30, TimeUnit.MINUTES).concurrencyLevel(4)
65 63
 				.initialCapacity(1024).build();
66 64
 	}
67 65
 
68 66
 	@Override
69 67
 	public void newMessageDelivered(LmtpEnvelope env, DeliveredVersion dv, String email) {
70
-		PendingInsert pending = active.get(env.getId());
68
+		PendingInsert pending = Activator.getActive().get(env.getId());
71 69
 		if (pending == null) {
72 70
 			logger.warn("newMessageDelivered: Delivery {} unknown or took too long.", env.getId());
73 71
 			return;
... ...
@@ -81,14 +79,14 @@ public class IndexOnDeliveryAction implements IDeliveryDoneAction {
81 81
 
82 82
 	@Override
83 83
 	public void deliveryFinished(LmtpEnvelope env) {
84
-		PendingInsert pending = active.get(env.getId());
84
+		PendingInsert pending = Activator.getActive().get(env.getId());
85 85
 		if (pending == null) {
86 86
 			logger.warn("deliveryFinished: Delivery {} unknown or took too long.", env.getId());
87 87
 			return;
88 88
 		}
89 89
 		if (pending.getVersions().isEmpty()) {
90 90
 			logger.warn("[{}] No pending versions", env.getId());
91
-			active.remove(env.getId());
91
+			Activator.getActive().remove(env.getId());
92 92
 			return;
93 93
 		}
94 94
 
... ...
@@ -111,7 +109,7 @@ public class IndexOnDeliveryAction implements IDeliveryDoneAction {
111 111
 		}
112 112
 
113 113
 		MailIndexActivator.getService().append(mailDocs, true);
114
-		active.remove(env.getId());
114
+		IndexingFilter.deliveryFinished(env.getId());
115 115
 	}
116 116
 
117 117
 	private Set<String> expandFlags(Set<String> flags) {
... ...
@@ -34,7 +34,7 @@ public class IndexingFilterFactory implements ILmtpFilterFactory {
34 34
 
35 35
 	@Override
36 36
 	public IMessageFilter getEngine() {
37
-		return new IndexingFilter(Activator.getActive());
37
+		return new IndexingFilter();
38 38
 	}
39 39
 
40 40
 }
... ...
@@ -25,25 +25,29 @@ import org.slf4j.LoggerFactory;
25 25
 import net.bluemind.lmtp.backend.FilterException;
26 26
 import net.bluemind.lmtp.backend.IMessageFilter;
27 27
 import net.bluemind.lmtp.backend.LmtpEnvelope;
28
+import net.bluemind.lmtp.filter.indexing.Activator;
28 29
 
29 30
 public class IndexingFilter implements IMessageFilter {
30 31
 
31 32
 	private static final Logger logger = LoggerFactory.getLogger(IndexingFilter.class);
32
-	private final ActiveDeliveries active;
33 33
 
34
-	public IndexingFilter(ActiveDeliveries active) {
35
-		this.active = active;
34
+	public IndexingFilter() {
36 35
 	}
37 36
 
38 37
 	@Override
39 38
 	public Message filter(LmtpEnvelope env, Message message, long messageSize) throws FilterException {
40 39
 
41 40
 		PendingInsert pi = new PendingInsert(message, (int) messageSize);
42
-		active.put(env.getId(), pi);
41
+		Activator.getActive().put(env.getId(), pi);
43 42
 
44 43
 		logger.info("[{}] Pending insert created", env.getId());
45 44
 
46 45
 		return null;
47 46
 	}
48 47
 
48
+	public static void deliveryFinished(String id) {
49
+		Activator.getActive().get(id).getMessage().dispose();
50
+		Activator.getActive().remove(id);
51
+	}
52
+
49 53
 }
... ...
@@ -131,12 +131,10 @@ public class LmtpFiltersVerticle extends Verticle {
131 131
 		// no body modification
132 132
 		if (!modified) {
133 133
 			// return original body
134
-			msg.dispose();
135 134
 			return body;
136 135
 		} else {
137 136
 			logger.debug("mail body has been modified");
138 137
 			ByteBuf data = parseFilteredMessage(filtered);
139
-			msg.dispose();
140 138
 			return new MailMessage(body.getEnvelope(), data);
141 139
 		}
142 140