From 3968b0a395ceae2f3893f8d13f957890796c2339 Mon Sep 17 00:00:00 2001 From: afinkbein Date: Fri, 11 Jun 2010 22:52:58 +0000 Subject: cleaned up some shutdown code --- .../messaging/internal/FailoverConnectionNode.java | 7 ++++- .../internal/activemq/ConnectionNodeActiveMq.java | 7 ++--- .../internal/RemoteServiceRegistrarImpl.java | 5 ++-- .../ServiceLookupAndRegistrarLifeCycle.java | 31 ++++++++++++++++++---- 4 files changed, 39 insertions(+), 11 deletions(-) (limited to 'plugins/org.eclipse.osee.framework.messaging') 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 b658e1312fa..4b0206458c6 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(); connectionListeners = new CopyOnWriteArrayList(); 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 08ce2579981..398eef8b949 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 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 aba1b76edce..517ea0523c9 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 61710f58232..9e255e380f1 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(); + } + + } + + } -- cgit v1.2.3