diff --git a/org.adempiere.base/OSGI-INF/broadcastutil.xml b/org.adempiere.base/OSGI-INF/broadcastutil.xml
new file mode 100644
index 0000000000..e45b0789e2
--- /dev/null
+++ b/org.adempiere.base/OSGI-INF/broadcastutil.xml
@@ -0,0 +1,5 @@
+
+
+
+
+
diff --git a/org.adempiere.base/build.properties b/org.adempiere.base/build.properties
index d544a7e725..13b7031c31 100644
--- a/org.adempiere.base/build.properties
+++ b/org.adempiere.base/build.properties
@@ -26,7 +26,8 @@ bin.includes = META-INF/,\
OSGI-INF/defaultmodelvalidatorfactory.xml,\
OSGI-INF/defaultprocessfactory.xml,\
OSGI-INF/defaultshipmentprocessorfactory.xml,\
- OSGI-INF/defaultpaymentprocessorfactory.xml
+ OSGI-INF/defaultpaymentprocessorfactory.xml,\
+ OSGI-INF/broadcastutil.xml
output.base.jar = build/
src.includes = schema/
source.base.jar = src/
diff --git a/org.adempiere.base/src/org/idempiere/broadcast/BroadCastUtil.java b/org.adempiere.base/src/org/idempiere/broadcast/BroadCastUtil.java
index 933074a2ed..ddf516198f 100644
--- a/org.adempiere.base/src/org/idempiere/broadcast/BroadCastUtil.java
+++ b/org.adempiere.base/src/org/idempiere/broadcast/BroadCastUtil.java
@@ -13,8 +13,9 @@
*****************************************************************************/
package org.idempiere.broadcast;
-import org.adempiere.base.IServiceHolder;
-import org.adempiere.base.Service;
+import java.util.ArrayList;
+import java.util.List;
+
import org.idempiere.distributed.IMessageService;
import org.idempiere.distributed.ITopic;
import org.idempiere.distributed.ITopicSubscriber;
@@ -29,30 +30,39 @@ public class BroadCastUtil {
public static final int EVENT_SESSION_TIMEOUT =3;
public static final int EVENT_SESSION_ONNODE_TIMEOUT=4;
- public static void subscribe(ITopicSubscriber subscriber){
-
- IServiceHolder holder = Service.locator().locate(IMessageService.class);
- IMessageService service = holder.getService();
+ private final static List> subscribers = new ArrayList>();
+ private static IMessageService service = null;
+
+ /**
+ *
+ * @param subscriber
+ */
+ public static synchronized void subscribe(ITopicSubscriber subscriber){
+ subscribers.add(subscriber);
if (service != null) {
ITopic topic= service.getTopic(TOPIC_BROADCAST_MESSAGE);
topic.subscribe(subscriber);
- }
+ }
}
- public static void unSubscribe(ITopicSubscriber subscriber){
-
- IServiceHolder holder = Service.locator().locate(IMessageService.class);
- IMessageService service = holder.getService();
+ /**
+ *
+ * @param subscriber
+ */
+ public static synchronized void unSubscribe(ITopicSubscriber subscriber){
+ subscribers.remove(subscriber);
if (service != null) {
ITopic topic= service.getTopic(TOPIC_BROADCAST_MESSAGE);
topic.unsubscribe(subscriber);
}
}
- public static boolean publish(BroadCastMsg msg){
-
- IServiceHolder holder = Service.locator().locate(IMessageService.class);
- IMessageService service = holder.getService();
+ /**
+ *
+ * @param msg
+ * @return true if publish successfully
+ */
+ public static synchronized boolean publish(BroadCastMsg msg){
if (service != null) {
ITopic topic= service.getTopic(TOPIC_BROADCAST_MESSAGE);
topic.publish(msg);
@@ -60,4 +70,28 @@ public class BroadCastUtil {
}
return false;
}
+
+ /**
+ *
+ * @param messageService
+ */
+ public void bindMessageService(IMessageService messageService) {
+ synchronized (BroadCastUtil.class) {
+ service = messageService;
+ for (ITopicSubscriber subscriber : subscribers) {
+ ITopic topic= service.getTopic(TOPIC_BROADCAST_MESSAGE);
+ topic.subscribe(subscriber);
+ }
+ }
+ }
+
+ /**
+ *
+ * @param messageService
+ */
+ public void unbindMessageService(IMessageService messageService) {
+ synchronized (BroadCastUtil.class) {
+ service = null;
+ }
+ }
}
diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/event/ZKBroadCastManager.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/event/ZKBroadCastManager.java
index 1a5b96d135..21cf5347c9 100644
--- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/event/ZKBroadCastManager.java
+++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/event/ZKBroadCastManager.java
@@ -26,15 +26,9 @@ import org.idempiere.distributed.ITopicSubscriber;
*/
public class ZKBroadCastManager implements ITopicSubscriber{
- private static ZKBroadCastManager broadCastMgr = null;
+ private final static ZKBroadCastManager broadCastMgr = new ZKBroadCastManager();
- public static ZKBroadCastManager getBroadCastMgr() {
-
- synchronized (ZKBroadCastManager.class) {
- if(broadCastMgr==null)
- broadCastMgr= new ZKBroadCastManager();
-
- }
+ public static ZKBroadCastManager getBroadCastMgr() {
return broadCastMgr;
}