Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorafinkbein2010-06-11 18:52:58 -0400
committerafinkbein2010-06-11 18:52:58 -0400
commit3968b0a395ceae2f3893f8d13f957890796c2339 (patch)
tree1a8c678930fe2ff6e3974a3b3d76c0b684d5170c /plugins/org.eclipse.osee.framework.messaging
parent94d56833a53aced4b8c7c5da94f7abe87a1a1493 (diff)
downloadorg.eclipse.osee-3968b0a395ceae2f3893f8d13f957890796c2339.tar.gz
org.eclipse.osee-3968b0a395ceae2f3893f8d13f957890796c2339.tar.xz
org.eclipse.osee-3968b0a395ceae2f3893f8d13f957890796c2339.zip
cleaned up some shutdown code
Diffstat (limited to 'plugins/org.eclipse.osee.framework.messaging')
-rw-r--r--plugins/org.eclipse.osee.framework.messaging/src/org/eclipse/osee/framework/messaging/internal/FailoverConnectionNode.java7
-rw-r--r--plugins/org.eclipse.osee.framework.messaging/src/org/eclipse/osee/framework/messaging/internal/activemq/ConnectionNodeActiveMq.java7
-rw-r--r--plugins/org.eclipse.osee.framework.messaging/src/org/eclipse/osee/framework/messaging/services/internal/RemoteServiceRegistrarImpl.java5
-rw-r--r--plugins/org.eclipse.osee.framework.messaging/src/org/eclipse/osee/framework/messaging/services/internal/ServiceLookupAndRegistrarLifeCycle.java31
4 files changed, 39 insertions, 11 deletions
diff --git a/plugins/org.eclipse.osee.framework.messaging/src/org/eclipse/osee/framework/messaging/internal/FailoverConnectionNode.java b/plugins/org.eclipse.osee.framework.messaging/src/org/eclipse/osee/framework/messaging/internal/FailoverConnectionNode.java
index b658e1312f..4b0206458c 100644
--- a/plugins/org.eclipse.osee.framework.messaging/src/org/eclipse/osee/framework/messaging/internal/FailoverConnectionNode.java
+++ b/plugins/org.eclipse.osee.framework.messaging/src/org/eclipse/osee/framework/messaging/internal/FailoverConnectionNode.java
@@ -9,9 +9,12 @@ import java.util.List;
import java.util.Properties;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
+
import javax.jms.JMSException;
+
import org.eclipse.osee.framework.core.exception.OseeCoreException;
import org.eclipse.osee.framework.logging.OseeLog;
import org.eclipse.osee.framework.messaging.ConnectionListener;
@@ -34,6 +37,7 @@ public class FailoverConnectionNode implements ConnectionNode, Runnable {
private ScheduledExecutorService scheduledExecutor;
private boolean lastConnectedState = false;
private OseeExceptionListener exceptionListener;
+private ScheduledFuture<?> itemToCancel;
public FailoverConnectionNode(ConnectionNodeFailoverSupport connectionNode, ScheduledExecutorService scheduledExecutor, OseeExceptionListener exceptionListener) {
this.connectionNode = connectionNode;
@@ -42,7 +46,7 @@ public class FailoverConnectionNode implements ConnectionNode, Runnable {
savedSubscribes = new CopyOnWriteArrayList<SavedSubscribe>();
connectionListeners = new CopyOnWriteArrayList<ConnectionListener>();
this.scheduledExecutor = scheduledExecutor;
- this.scheduledExecutor.scheduleAtFixedRate(this, 60, 15, TimeUnit.SECONDS);
+ itemToCancel = this.scheduledExecutor.scheduleAtFixedRate(this, 60, 15, TimeUnit.SECONDS);
}
@Override
@@ -73,6 +77,7 @@ public class FailoverConnectionNode implements ConnectionNode, Runnable {
@Override
public void stop() {
+ itemToCancel.cancel(false);
connectionNode.stop();
}
diff --git a/plugins/org.eclipse.osee.framework.messaging/src/org/eclipse/osee/framework/messaging/internal/activemq/ConnectionNodeActiveMq.java b/plugins/org.eclipse.osee.framework.messaging/src/org/eclipse/osee/framework/messaging/internal/activemq/ConnectionNodeActiveMq.java
index 08ce257998..398eef8b94 100644
--- a/plugins/org.eclipse.osee.framework.messaging/src/org/eclipse/osee/framework/messaging/internal/activemq/ConnectionNodeActiveMq.java
+++ b/plugins/org.eclipse.osee.framework.messaging/src/org/eclipse/osee/framework/messaging/internal/activemq/ConnectionNodeActiveMq.java
@@ -14,6 +14,7 @@ import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutorService;
import java.util.logging.Level;
+
import javax.jms.Connection;
import javax.jms.DeliveryMode;
import javax.jms.ExceptionListener;
@@ -25,6 +26,7 @@ import javax.jms.MessageProducer;
import javax.jms.Session;
import javax.jms.TemporaryTopic;
import javax.jms.Topic;
+
import org.apache.activemq.ActiveMQConnectionFactory;
import org.eclipse.osee.framework.core.exception.OseeCoreException;
import org.eclipse.osee.framework.core.exception.OseeWrappedException;
@@ -235,13 +237,12 @@ class ConnectionNodeActiveMq implements ConnectionNodeFailoverSupport, MessageLi
for(Entry<MessageConsumer, OseeMessagingListener> entry:listeners.entrySet()){
if(entry.getValue().equals(listener)){
entry.getKey().setMessageListener(null);
- entry.getKey().close();
consumersToRemove.add(entry.getKey());
}
}
for(MessageConsumer messageConsumer: consumersToRemove){
- messageConsumer.setMessageListener(null);
- messageConsumer.close();
+ messageConsumer.setMessageListener(null);
+ messageConsumer.close();
}
}catch (JMSException ex) {
statusCallback.fail(ex);
diff --git a/plugins/org.eclipse.osee.framework.messaging/src/org/eclipse/osee/framework/messaging/services/internal/RemoteServiceRegistrarImpl.java b/plugins/org.eclipse.osee.framework.messaging/src/org/eclipse/osee/framework/messaging/services/internal/RemoteServiceRegistrarImpl.java
index aba1b76edc..517ea0523c 100644
--- a/plugins/org.eclipse.osee.framework.messaging/src/org/eclipse/osee/framework/messaging/services/internal/RemoteServiceRegistrarImpl.java
+++ b/plugins/org.eclipse.osee.framework.messaging/src/org/eclipse/osee/framework/messaging/services/internal/RemoteServiceRegistrarImpl.java
@@ -12,12 +12,13 @@ import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
+
import org.eclipse.osee.framework.jdk.core.type.CompositeKeyHashMap;
import org.eclipse.osee.framework.messaging.ConnectionNode;
import org.eclipse.osee.framework.messaging.services.BaseMessages;
+import org.eclipse.osee.framework.messaging.services.RegisteredServiceReference;
import org.eclipse.osee.framework.messaging.services.RemoteServiceRegistrar;
import org.eclipse.osee.framework.messaging.services.ServiceInfoPopulator;
-import org.eclipse.osee.framework.messaging.services.RegisteredServiceReference;
/**
* @author Andrew M. Finkbeiner
@@ -45,7 +46,7 @@ public class RemoteServiceRegistrarImpl implements RemoteServiceRegistrar {
}
public void stop() {
- connectionNode.subscribe(BaseMessages.ServiceHealthRequest, healthRequestListener, new OseeMessagingStatusImpl("Failed to subscribe to " + BaseMessages.ServiceHealthRequest.getName(), RemoteServiceRegistrarImpl.class));
+ connectionNode.unsubscribe(BaseMessages.ServiceHealthRequest, healthRequestListener, new OseeMessagingStatusImpl("Failed to subscribe to " + BaseMessages.ServiceHealthRequest.getName(), RemoteServiceRegistrarImpl.class));
}
@Override
diff --git a/plugins/org.eclipse.osee.framework.messaging/src/org/eclipse/osee/framework/messaging/services/internal/ServiceLookupAndRegistrarLifeCycle.java b/plugins/org.eclipse.osee.framework.messaging/src/org/eclipse/osee/framework/messaging/services/internal/ServiceLookupAndRegistrarLifeCycle.java
index 61710f5823..9e255e380f 100644
--- a/plugins/org.eclipse.osee.framework.messaging/src/org/eclipse/osee/framework/messaging/services/internal/ServiceLookupAndRegistrarLifeCycle.java
+++ b/plugins/org.eclipse.osee.framework.messaging/src/org/eclipse/osee/framework/messaging/services/internal/ServiceLookupAndRegistrarLifeCycle.java
@@ -8,6 +8,7 @@ package org.eclipse.osee.framework.messaging.services.internal;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.logging.Level;
+
import org.eclipse.osee.framework.core.exception.OseeCoreException;
import org.eclipse.osee.framework.logging.OseeLog;
import org.eclipse.osee.framework.messaging.MessageService;
@@ -29,6 +30,7 @@ public class ServiceLookupAndRegistrarLifeCycle extends ServiceTracker {
private ServiceRegistration lookupRegistration;
private ServiceRegistration registrarRegistration;
private ClassLoader contextClassLoader;
+ private RemoteServiceLookupImpl lookup;
/**
* @param context
* @param filter
@@ -51,11 +53,11 @@ public class ServiceLookupAndRegistrarLifeCycle extends ServiceTracker {
OseeLog.log(Activator.class, Level.FINEST, String.format("set context classloader"));
Thread.currentThread().setContextClassLoader(contextClassLoader);
OseeLog.log(Activator.class, Level.FINEST, String.format("done set context classloader"));
- RemoteServiceRegistrar registrar = new RemoteServiceRegistrarImpl(messageService.getDefault(), executor);
+ registrar = new RemoteServiceRegistrarImpl(messageService.getDefault(), executor);
OseeLog.log(Activator.class, Level.FINEST, String.format("Getting ready to start %s.", RemoteServiceRegistrarImpl.class.getName()));
registrar.start();
OseeLog.log(Activator.class, Level.FINEST, String.format("started %s.", RemoteServiceRegistrarImpl.class.getName()));
- RemoteServiceLookup lookup = new RemoteServiceLookupImpl(messageService.getDefault(), executor);
+ lookup = new RemoteServiceLookupImpl(messageService.getDefault(), executor);
OseeLog.log(Activator.class, Level.FINEST, String.format("Getting ready to start %s.", RemoteServiceLookupImpl.class.getName()));
lookup.start();
OseeLog.log(Activator.class, Level.FINEST, String.format("started %s.", RemoteServiceLookupImpl.class.getName()));
@@ -72,10 +74,29 @@ public class ServiceLookupAndRegistrarLifeCycle extends ServiceTracker {
@Override
public void removedService(ServiceReference reference, Object service) {
- lookupRegistration.unregister();
- registrarRegistration.unregister();
- registrar.stop();
+ commonShutdown();
super.removedService(reference, service);
}
+ @Override
+ public void close() {
+ commonShutdown();
+ super.close();
+ }
+
+ private void commonShutdown(){
+ if(lookupRegistration != null){
+ lookupRegistration.unregister();
+ lookupRegistration = null;
+ lookup.stop();
+ }
+ if(registrarRegistration != null){
+ registrarRegistration.unregister();
+ registrarRegistration = null;
+ registrar.stop();
+ }
+
+ }
+
+
}

Back to the top