Browse code

BM-15302 Chore: don't pull HZ dependency when we just want the sessions map

Thomas Cataldo authored on 25/10/2019 09:52:58
Showing 15 changed files
... ...
@@ -155,6 +155,7 @@
155 155
       <plugin id="net.bluemind.core.sendmail"/>
156 156
       <plugin id="net.bluemind.core.serialization"/>
157 157
       <plugin id="net.bluemind.core.sessions"/>
158
+      <plugin id="net.bluemind.core.sessions.deletion.hz"/>
158 159
       <plugin id="net.bluemind.core.sqlschema"/>
159 160
       <plugin id="net.bluemind.core.task.api"/>
160 161
       <plugin id="net.bluemind.core.task.service"/>
161 162
new file mode 100644
... ...
@@ -0,0 +1,7 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<classpath>
3
+	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
4
+	<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
5
+	<classpathentry kind="src" path="src"/>
6
+	<classpathentry kind="output" path="bin"/>
7
+</classpath>
0 8
new file mode 100644
... ...
@@ -0,0 +1,28 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<projectDescription>
3
+	<name>net.bluemind.core.sessions.deletion.hz</name>
4
+	<comment></comment>
5
+	<projects>
6
+	</projects>
7
+	<buildSpec>
8
+		<buildCommand>
9
+			<name>org.eclipse.jdt.core.javabuilder</name>
10
+			<arguments>
11
+			</arguments>
12
+		</buildCommand>
13
+		<buildCommand>
14
+			<name>org.eclipse.pde.ManifestBuilder</name>
15
+			<arguments>
16
+			</arguments>
17
+		</buildCommand>
18
+		<buildCommand>
19
+			<name>org.eclipse.pde.SchemaBuilder</name>
20
+			<arguments>
21
+			</arguments>
22
+		</buildCommand>
23
+	</buildSpec>
24
+	<natures>
25
+		<nature>org.eclipse.pde.PluginNature</nature>
26
+		<nature>org.eclipse.jdt.core.javanature</nature>
27
+	</natures>
28
+</projectDescription>
0 29
new file mode 100644
... ...
@@ -0,0 +1,12 @@
1
+Manifest-Version: 1.0
2
+Bundle-ManifestVersion: 2
3
+Bundle-Name: net.bluemind.core.sessions.deletion.hz
4
+Bundle-SymbolicName: net.bluemind.core.sessions.deletion.hz;singleton:=true
5
+Bundle-Version: 4.1.0.qualifier
6
+Bundle-Vendor: bluemind.net
7
+Require-Bundle: org.eclipse.core.runtime,
8
+ net.bluemind.core.sessions,
9
+ net.bluemind.hornetq.client,
10
+ slf4j.api
11
+Bundle-RequiredExecutionEnvironment: JavaSE-1.8
12
+Automatic-Module-Name: net.bluemind.core.sessions.deletion.hz
0 13
new file mode 100644
... ...
@@ -0,0 +1,5 @@
1
+source.. = src/
2
+output.. = bin/
3
+bin.includes = META-INF/,\
4
+               .,\
5
+               plugin.xml
0 6
new file mode 100644
... ...
@@ -0,0 +1,11 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<?eclipse version="3.4"?>
3
+<plugin>
4
+   <extension
5
+         point="net.bluemind.core.sessions.deletion">
6
+      <listener
7
+            new_attribute="net.bluemind.core.sessions.deletion.hz.PropagateSessionDeletions">
8
+      </listener>
9
+   </extension>
10
+
11
+</plugin>
0 12
new file mode 100644
... ...
@@ -0,0 +1,10 @@
1
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
2
+  <modelVersion>4.0.0</modelVersion>
3
+  <parent>
4
+    <groupId>net.bluemind</groupId>
5
+    <artifactId>net.bluemind.core.plugins</artifactId>
6
+    <version>4.1.0-SNAPSHOT</version>
7
+  </parent>
8
+  <artifactId>net.bluemind.core.sessions.deletion.hz</artifactId>
9
+  <packaging>eclipse-plugin</packaging>
10
+</project>
0 11
new file mode 100644
... ...
@@ -0,0 +1,56 @@
1
+/* BEGIN LICENSE
2
+ * Copyright © Blue Mind SAS, 2012-2019
3
+ *
4
+ * This file is part of BlueMind. BlueMind is a messaging and collaborative
5
+ * solution.
6
+ *
7
+ * This program is free software; you can redistribute it and/or modify
8
+ * it under the terms of either the GNU Affero General Public License as
9
+ * published by the Free Software Foundation (version 3 of the License).
10
+ *
11
+ * This program is distributed in the hope that it will be useful,
12
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14
+ *
15
+ * See LICENSE.txt
16
+ * END LICENSE
17
+ */
18
+package net.bluemind.core.sessions.deletion.hz;
19
+
20
+import java.util.concurrent.CompletableFuture;
21
+
22
+import org.slf4j.Logger;
23
+import org.slf4j.LoggerFactory;
24
+
25
+import net.bluemind.core.sessions.ISessionDeletionListener;
26
+import net.bluemind.hornetq.client.MQ;
27
+import net.bluemind.hornetq.client.OOPMessage;
28
+import net.bluemind.hornetq.client.Producer;
29
+import net.bluemind.hornetq.client.Topic;
30
+
31
+public class PropagateSessionDeletions implements ISessionDeletionListener {
32
+
33
+	private static final Logger logger = LoggerFactory.getLogger(PropagateSessionDeletions.class);
34
+
35
+	private final CompletableFuture<Producer> producer;
36
+
37
+	public PropagateSessionDeletions() {
38
+		producer = MQ.init().thenApply(v -> MQ.getProducer(Topic.CORE_SESSIONS));
39
+	}
40
+
41
+	@Override
42
+	public void deleted(String identity, String sid) {
43
+		Producer prod = producer.getNow(null);
44
+		if (prod != null) {
45
+			OOPMessage cm = MQ.newMessage();
46
+			cm.putStringProperty("sender", identity);
47
+			cm.putStringProperty("operation", "logout");
48
+			cm.putStringProperty("sid", sid);
49
+			prod.send(cm);
50
+			logger.debug("MQ: logout {} sent.", sid);
51
+		} else {
52
+			logger.warn("MQ is missing, logout support will fail");
53
+		}
54
+	}
55
+
56
+}
... ...
@@ -9,7 +9,6 @@ Require-Bundle: org.eclipse.core.runtime,
9 9
  com.google.guava;bundle-version="19.0.0",
10 10
  net.bluemind.core.context,
11 11
  net.bluemind.slf4j;bundle-version="1.0.0",
12
- net.bluemind.hornetq.client,
13 12
  net.bluemind.config;bundle-version="1.0.0",
14 13
  net.bluemind.lib.vertx,
15 14
  net.bluemind.system.api;bundle-version="4.1.0",
... ...
@@ -2,5 +2,6 @@
2 2
 <?eclipse version="3.4"?>
3 3
 <plugin>
4 4
    <extension-point id="net.bluemind.core.sessions.provider" name="provider" schema="schema/net.bluemind.core.sessions.provider.exsd"/>
5
+   <extension-point id="net.bluemind.core.sessions.deletion" name="deletion" schema="schema/net.bluemind.core.sessions.deletion.exsd"/>
5 6
 
6 7
 </plugin>
7 8
new file mode 100644
... ...
@@ -0,0 +1,102 @@
1
+<?xml version='1.0' encoding='UTF-8'?>
2
+<!-- Schema file written by PDE -->
3
+<schema targetNamespace="net.bluemind.core.sessions" xmlns="http://www.w3.org/2001/XMLSchema">
4
+<annotation>
5
+      <appinfo>
6
+         <meta.schema plugin="net.bluemind.core.sessions" id="net.bluemind.core.sessions.deletion" name="deletion"/>
7
+      </appinfo>
8
+      <documentation>
9
+         [Enter description of this extension point.]
10
+      </documentation>
11
+   </annotation>
12
+
13
+   <element name="extension">
14
+      <annotation>
15
+         <appinfo>
16
+            <meta.element />
17
+         </appinfo>
18
+      </annotation>
19
+      <complexType>
20
+         <sequence>
21
+            <element ref="listener" minOccurs="1" maxOccurs="unbounded"/>
22
+         </sequence>
23
+         <attribute name="point" type="string" use="required">
24
+            <annotation>
25
+               <documentation>
26
+                  
27
+               </documentation>
28
+            </annotation>
29
+         </attribute>
30
+         <attribute name="id" type="string">
31
+            <annotation>
32
+               <documentation>
33
+                  
34
+               </documentation>
35
+            </annotation>
36
+         </attribute>
37
+         <attribute name="name" type="string">
38
+            <annotation>
39
+               <documentation>
40
+                  
41
+               </documentation>
42
+               <appinfo>
43
+                  <meta.attribute translatable="true"/>
44
+               </appinfo>
45
+            </annotation>
46
+         </attribute>
47
+      </complexType>
48
+   </element>
49
+
50
+   <element name="listener">
51
+      <complexType>
52
+         <attribute name="impl" type="string" use="required">
53
+            <annotation>
54
+               <documentation>
55
+                  
56
+               </documentation>
57
+               <appinfo>
58
+                  <meta.attribute kind="java" basedOn=":net.bluemind.core.sessions.ISessionDeletionListener"/>
59
+               </appinfo>
60
+            </annotation>
61
+         </attribute>
62
+      </complexType>
63
+   </element>
64
+
65
+   <annotation>
66
+      <appinfo>
67
+         <meta.section type="since"/>
68
+      </appinfo>
69
+      <documentation>
70
+         [Enter the first release in which this extension point appears.]
71
+      </documentation>
72
+   </annotation>
73
+
74
+   <annotation>
75
+      <appinfo>
76
+         <meta.section type="examples"/>
77
+      </appinfo>
78
+      <documentation>
79
+         [Enter extension point usage example here.]
80
+      </documentation>
81
+   </annotation>
82
+
83
+   <annotation>
84
+      <appinfo>
85
+         <meta.section type="apiinfo"/>
86
+      </appinfo>
87
+      <documentation>
88
+         [Enter API information here.]
89
+      </documentation>
90
+   </annotation>
91
+
92
+   <annotation>
93
+      <appinfo>
94
+         <meta.section type="implementation"/>
95
+      </appinfo>
96
+      <documentation>
97
+         [Enter information about supplied implementation of this extension point.]
98
+      </documentation>
99
+   </annotation>
100
+
101
+
102
+</schema>
0 103
new file mode 100644
... ...
@@ -0,0 +1,24 @@
1
+/* BEGIN LICENSE
2
+ * Copyright © Blue Mind SAS, 2012-2019
3
+ *
4
+ * This file is part of BlueMind. BlueMind is a messaging and collaborative
5
+ * solution.
6
+ *
7
+ * This program is free software; you can redistribute it and/or modify
8
+ * it under the terms of either the GNU Affero General Public License as
9
+ * published by the Free Software Foundation (version 3 of the License).
10
+ *
11
+ * This program is distributed in the hope that it will be useful,
12
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14
+ *
15
+ * See LICENSE.txt
16
+ * END LICENSE
17
+ */
18
+package net.bluemind.core.sessions;
19
+
20
+public interface ISessionDeletionListener {
21
+
22
+	void deleted(String identity, String sid);
23
+
24
+}
0 25
new file mode 100644
... ...
@@ -0,0 +1,41 @@
1
+/* BEGIN LICENSE
2
+ * Copyright © Blue Mind SAS, 2012-2019
3
+ *
4
+ * This file is part of BlueMind. BlueMind is a messaging and collaborative
5
+ * solution.
6
+ *
7
+ * This program is free software; you can redistribute it and/or modify
8
+ * it under the terms of either the GNU Affero General Public License as
9
+ * published by the Free Software Foundation (version 3 of the License).
10
+ *
11
+ *
12
+ * This program is distributed in the hope that it will be useful,
13
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15
+ *
16
+ * See LICENSE.txt
17
+ * END LICENSE
18
+ */
19
+package net.bluemind.core.sessions;
20
+
21
+import java.util.List;
22
+
23
+import net.bluemind.eclipse.common.RunnableExtensionLoader;
24
+
25
+public class SessionDeletionListeners {
26
+
27
+	private static final List<ISessionDeletionListener> listeners = load();
28
+
29
+	private SessionDeletionListeners() {
30
+
31
+	}
32
+
33
+	private static List<ISessionDeletionListener> load() {
34
+		RunnableExtensionLoader<ISessionDeletionListener> rel = new RunnableExtensionLoader<>();
35
+		return rel.loadExtensionsWithPriority("net.bluemind.core.sessions", "deletion", "listener", "impl");
36
+	}
37
+
38
+	public static List<ISessionDeletionListener> get() {
39
+		return listeners;
40
+	}
41
+}
... ...
@@ -8,7 +8,6 @@ import org.osgi.framework.BundleActivator;
8 8
 import org.osgi.framework.BundleContext;
9 9
 import org.slf4j.Logger;
10 10
 import org.slf4j.LoggerFactory;
11
-import org.vertx.java.core.Handler;
12 11
 import org.vertx.java.core.eventbus.Message;
13 12
 import org.vertx.java.core.json.JsonObject;
14 13
 
... ...
@@ -20,11 +19,6 @@ import com.google.common.cache.RemovalNotification;
20 19
 
21 20
 import net.bluemind.config.Token;
22 21
 import net.bluemind.core.context.SecurityContext;
23
-import net.bluemind.hornetq.client.MQ;
24
-import net.bluemind.hornetq.client.MQ.IMQConnectHandler;
25
-import net.bluemind.hornetq.client.OOPMessage;
26
-import net.bluemind.hornetq.client.Producer;
27
-import net.bluemind.hornetq.client.Topic;
28 22
 import net.bluemind.lib.vertx.VertxPlatform;
29 23
 import net.bluemind.system.api.SystemState;
30 24
 
... ...
@@ -56,16 +50,8 @@ public class Sessions implements BundleActivator {
56 50
 	}
57 51
 
58 52
 	private static void notifyDeletion(String sessionId) {
59
-		Producer prod = MQ.getProducer(Topic.CORE_SESSIONS);
60
-		if (prod != null) {
61
-			OOPMessage cm = MQ.newMessage();
62
-			cm.putStringProperty("sender", identity);
63
-			cm.putStringProperty("operation", "logout");
64
-			cm.putStringProperty("sid", sessionId);
65
-			prod.send(cm);
66
-			logger.debug("MQ: logout {} sent.", sessionId);
67
-		} else {
68
-			logger.warn("MQ is missing, logout support will fail");
53
+		for (ISessionDeletionListener listener : SessionDeletionListeners.get()) {
54
+			listener.deleted(identity, sessionId);
69 55
 		}
70 56
 	}
71 57
 
... ...
@@ -86,23 +72,11 @@ public class Sessions implements BundleActivator {
86 72
 	@Override
87 73
 	public void start(BundleContext bundleContext) throws Exception {
88 74
 		Sessions.context = bundleContext;
89
-		VertxPlatform.getVertx().eventBus().registerHandler(SystemState.BROADCAST, new Handler<Message<JsonObject>>() {
90
-
91
-			@Override
92
-			public void handle(Message<JsonObject> event) {
93
-				String op = event.body().getString("operation");
94
-				SystemState state = SystemState.fromOperation(op);
95
-				if (state == SystemState.CORE_STATE_MAINTENANCE) {
96
-					sessions.invalidateAll();
97
-				}
98
-			}
99
-		});
100
-		MQ.init(new IMQConnectHandler() {
101
-
102
-			@Override
103
-			public void connected() {
104
-				MQ.registerProducer(Topic.CORE_SESSIONS);
105
-				logger.info("**** SESSION NOTIFICATION REGISTERED ****");
75
+		VertxPlatform.getVertx().eventBus().registerHandler(SystemState.BROADCAST, (Message<JsonObject> event) -> {
76
+			String op = event.body().getString("operation");
77
+			SystemState state = SystemState.fromOperation(op);
78
+			if (state == SystemState.CORE_STATE_MAINTENANCE) {
79
+				sessions.invalidateAll();
106 80
 			}
107 81
 		});
108 82
 
... ...
@@ -12,6 +12,7 @@
12 12
 		<module>net.bluemind.core.commons</module>
13 13
 		<module>net.bluemind.core.commons.tests</module>
14 14
 		<module>net.bluemind.core.sessions</module>
15
+		<module>net.bluemind.core.sessions.deletion.hz</module>
15 16
 		<module>net.bluemind.core.context</module>
16 17
 		<module>net.bluemind.config</module>
17 18
 		<module>net.bluemind.i18n.labels</module>