Browse code

Feat: might help with our topic listeners getting dropped when the cluster state is unstable

Thomas Cataldo authored on 09/03/2018 17:50:17
Showing 2 changed files
... ...
@@ -46,6 +46,7 @@ import com.hazelcast.core.MemberAttributeEvent;
46 46
 import com.hazelcast.core.MembershipEvent;
47 47
 import com.hazelcast.core.MembershipListener;
48 48
 import com.hazelcast.core.Message;
49
+import com.hazelcast.core.MessageListener;
49 50
 
50 51
 import net.bluemind.config.BmIni;
51 52
 import net.bluemind.hornetq.client.Consumer;
... ...
@@ -250,7 +251,7 @@ public abstract class ClusterNode {
250 250
 		hzStart.thenAccept(hz -> {
251 251
 			try {
252 252
 				ITopic<String> hzTopic = hz.getReliableTopic(topic);
253
-				String regId = hzTopic.addMessageListener((Message<String> message) -> {
253
+				MessageListener<String> basicListener = (Message<String> message) -> {
254 254
 					JsonObject payload = new JsonObject(message.getMessageObject());
255 255
 					if (filter != null) {
256 256
 						if (filter.test(payload)) {
... ...
@@ -261,7 +262,8 @@ public abstract class ClusterNode {
261 261
 					} else {
262 262
 						handler.handle(new OOPMessage(payload));
263 263
 					}
264
-				});
264
+				};
265
+				String regId = hzTopic.addMessageListener(new TopicListener(basicListener));
265 266
 				consumerRegistrations.put(regId, rc);
266 267
 				cons.complete(new Consumer(() -> {
267 268
 					hz.removeDistributedObjectListener(regId);
268 269
new file mode 100644
... ...
@@ -0,0 +1,34 @@
0
+/* BEGIN LICENSE
1
+  * Copyright © Blue Mind SAS, 2012-2018
2
+  *
3
+  * This file is part of BlueMind. BlueMind is a messaging and collaborative
4
+  * solution.
5
+  *
6
+  * This program is free software; you can redistribute it and/or modify
7
+  * it under the terms of either the GNU Affero General Public License as
8
+  * published by the Free Software Foundation (version 3 of the License).
9
+  *
10
+  * This program is distributed in the hope that it will be useful,
11
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13
+  *
14
+  * See LICENSE.txt
15
+  * END LICENSE
16
+  */
17
+package net.bluemind.hornetq.client.impl;
18
+
19
+import com.hazelcast.core.MessageListener;
20
+import com.hazelcast.topic.impl.reliable.ReliableMessageListenerAdapter;
21
+
22
+public class TopicListener extends ReliableMessageListenerAdapter<String> {
23
+
24
+	public TopicListener(MessageListener<String> ml) {
25
+		super(ml);
26
+	}
27
+
28
+	@Override
29
+	public boolean isLossTolerant() {
30
+		return true;
31
+	}
32
+
33
+}