diff options
author | Roberto E. Escobar | 2012-04-13 21:20:56 +0000 |
---|---|---|
committer | Roberto E. Escobar | 2012-04-13 21:20:56 +0000 |
commit | c3d840e4703cb62d9db92362b737a7f1c7f8ed46 (patch) | |
tree | a921c49358c34e9e2ce68ee8ac9a40c01888c41a | |
parent | 15696dd01fe687c5792fb10c0476fa19f28ceda1 (diff) | |
download | org.eclipse.osee-c3d840e4703cb62d9db92362b737a7f1c7f8ed46.tar.gz org.eclipse.osee-c3d840e4703cb62d9db92362b737a7f1c7f8ed46.tar.xz org.eclipse.osee-c3d840e4703cb62d9db92362b737a7f1c7f8ed46.zip |
feature[ats_VGR8B]: Convert framework messaging to DS
20 files changed, 242 insertions, 227 deletions
diff --git a/plugins/org.eclipse.osee.framework.messaging.test/src/org/eclipse/osee/framework/messaging/internal/BaseBrokerTesting.java b/plugins/org.eclipse.osee.framework.messaging.test/src/org/eclipse/osee/framework/messaging/internal/BaseBrokerTesting.java index 04475ecc9bb..81b36678283 100644 --- a/plugins/org.eclipse.osee.framework.messaging.test/src/org/eclipse/osee/framework/messaging/internal/BaseBrokerTesting.java +++ b/plugins/org.eclipse.osee.framework.messaging.test/src/org/eclipse/osee/framework/messaging/internal/BaseBrokerTesting.java @@ -37,13 +37,13 @@ import org.eclipse.osee.framework.messaging.test.msg.TestMessage; */ public class BaseBrokerTesting { - private MessageServiceProviderImpl messageServiceProviderImpl = null; + private MessageServiceProxy messageServiceProviderImpl = null; private ConcurrentHashMap<String, BrokerService> brokers; private Thread[] threads; @org.junit.Before public void beforeTest() { - messageServiceProviderImpl = new MessageServiceProviderImpl(Thread.currentThread().getContextClassLoader()); + messageServiceProviderImpl = new MessageServiceProxy(); brokers = new ConcurrentHashMap<String, BrokerService>(); try { messageServiceProviderImpl.start(); @@ -169,7 +169,7 @@ public class BaseBrokerTesting { protected final MessageService getMessaging() { MessageService messaging = null; - messaging = messageServiceProviderImpl.getMessageService(); + messaging = messageServiceProviderImpl.getProxiedService(); assertTrue(messaging != null); return messaging; } diff --git a/plugins/org.eclipse.osee.framework.messaging.test/src/org/eclipse/osee/framework/messaging/internal/IntegrationSuite.java b/plugins/org.eclipse.osee.framework.messaging.test/src/org/eclipse/osee/framework/messaging/internal/IntegrationSuite.java index 2da15d07ab9..9a014e20a41 100644 --- a/plugins/org.eclipse.osee.framework.messaging.test/src/org/eclipse/osee/framework/messaging/internal/IntegrationSuite.java +++ b/plugins/org.eclipse.osee.framework.messaging.test/src/org/eclipse/osee/framework/messaging/internal/IntegrationSuite.java @@ -17,4 +17,5 @@ import org.junit.runners.Suite; @RunWith(Suite.class) @Suite.SuiteClasses({TestSendingAndRecieving.class, TestBrokerServiceInterruptions.class, TestMessageServices.class}) public class IntegrationSuite { + // } diff --git a/plugins/org.eclipse.osee.framework.messaging.test/src/org/eclipse/osee/framework/messaging/services/internal/TestMessageServices.java b/plugins/org.eclipse.osee.framework.messaging.test/src/org/eclipse/osee/framework/messaging/services/internal/TestMessageServices.java index 9ae5f9a3b27..455422c9df6 100644 --- a/plugins/org.eclipse.osee.framework.messaging.test/src/org/eclipse/osee/framework/messaging/services/internal/TestMessageServices.java +++ b/plugins/org.eclipse.osee.framework.messaging.test/src/org/eclipse/osee/framework/messaging/services/internal/TestMessageServices.java @@ -16,7 +16,6 @@ import java.util.Map; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; import java.util.logging.Level; -import org.junit.Assert; import org.eclipse.osee.framework.core.exception.OseeCoreException; import org.eclipse.osee.framework.logging.OseeLog; import org.eclipse.osee.framework.messaging.ConnectionNode; @@ -26,12 +25,11 @@ import org.eclipse.osee.framework.messaging.OseeMessagingStatusCallback; import org.eclipse.osee.framework.messaging.ReplyConnection; import org.eclipse.osee.framework.messaging.internal.BaseBrokerTesting; import org.eclipse.osee.framework.messaging.internal.TestMessages; -import org.eclipse.osee.framework.messaging.services.RemoteServiceLookup; -import org.eclipse.osee.framework.messaging.services.RemoteServiceRegistrar; import org.eclipse.osee.framework.messaging.services.ServiceInfoPopulator; import org.eclipse.osee.framework.messaging.services.ServiceNotification; import org.eclipse.osee.framework.messaging.services.messages.ServiceDescriptionPair; import org.eclipse.osee.framework.messaging.services.messages.ServiceHealth; +import org.junit.Assert; /** * @author Andrew M. Finkbeiner @@ -68,8 +66,8 @@ public class TestMessageServices extends BaseBrokerTesting { Assert.assertNotNull(connection); ScheduledExecutorService executor = Executors.newScheduledThreadPool(3); - RemoteServiceRegistrar registrar = new RemoteServiceRegistrarImpl(connection, executor); - RemoteServiceLookup lookup = new RemoteServiceLookupImpl(connection, executor); + RemoteServiceRegistrarImpl registrar = new RemoteServiceRegistrarImpl(connection, executor); + RemoteServiceLookupImpl lookup = new RemoteServiceLookupImpl(connection, executor); registrar.start(); lookup.start(); @@ -108,10 +106,10 @@ public class TestMessageServices extends BaseBrokerTesting { ConnectionNode connection = getMessaging().get(new NodeInfo("osee-jms", new URI(BROKER_URI))); Assert.assertNotNull(connection); ScheduledExecutorService executor = Executors.newScheduledThreadPool(3); - RemoteServiceRegistrar registrar = new RemoteServiceRegistrarImpl(connection, executor); + RemoteServiceRegistrarImpl registrar = new RemoteServiceRegistrarImpl(connection, executor); registrar.start(); - RemoteServiceLookup lookup = new RemoteServiceLookupImpl(connection, executor); + RemoteServiceLookupImpl lookup = new RemoteServiceLookupImpl(connection, executor); lookup.start(); TestNotification testNotification = new TestNotification(); @@ -152,13 +150,13 @@ public class TestMessageServices extends BaseBrokerTesting { Assert.assertNotNull(connection); ScheduledExecutorService executor = Executors.newScheduledThreadPool(3); - RemoteServiceRegistrar registrar = new RemoteServiceRegistrarImpl(connection, executor); + RemoteServiceRegistrarImpl registrar = new RemoteServiceRegistrarImpl(connection, executor); registrar.start(); registrar.registerService("testService", "1002", "some.service.id", new URI("tcp://localhost:666"), new TestPopulator(), 50000); testWait(2000); - RemoteServiceLookup lookup = new RemoteServiceLookupImpl(connection, executor); + RemoteServiceLookupImpl lookup = new RemoteServiceLookupImpl(connection, executor); lookup.start(); TestNotification testNotification = new TestNotification(); lookup.register("testService", "1002", testNotification); diff --git a/plugins/org.eclipse.osee.framework.messaging/.project b/plugins/org.eclipse.osee.framework.messaging/.project index 35f666cb6e6..19e528cc21c 100644 --- a/plugins/org.eclipse.osee.framework.messaging/.project +++ b/plugins/org.eclipse.osee.framework.messaging/.project @@ -20,6 +20,11 @@ <arguments> </arguments> </buildCommand> + <buildCommand> + <name>org.eclipse.pde.ds.core.builder</name> + <arguments> + </arguments> + </buildCommand> </buildSpec> <natures> <nature>org.eclipse.pde.PluginNature</nature> diff --git a/plugins/org.eclipse.osee.framework.messaging/META-INF/MANIFEST.MF b/plugins/org.eclipse.osee.framework.messaging/META-INF/MANIFEST.MF index 07e2c76e003..57669f800fc 100644 --- a/plugins/org.eclipse.osee.framework.messaging/META-INF/MANIFEST.MF +++ b/plugins/org.eclipse.osee.framework.messaging/META-INF/MANIFEST.MF @@ -133,3 +133,4 @@ Export-Package: org.eclipse.osee.framework.messaging, org.eclipse.osee.framework.messaging.id, org.eclipse.osee.framework.messaging.services, org.eclipse.osee.framework.messaging.services.messages +Service-Component: OSGI-INF/*.xml diff --git a/plugins/org.eclipse.osee.framework.messaging/OSGI-INF/legacy.messaging.gateway.xml b/plugins/org.eclipse.osee.framework.messaging/OSGI-INF/legacy.messaging.gateway.xml new file mode 100644 index 00000000000..9464e18de78 --- /dev/null +++ b/plugins/org.eclipse.osee.framework.messaging/OSGI-INF/legacy.messaging.gateway.xml @@ -0,0 +1,7 @@ +<?xml version="1.0" encoding="UTF-8"?> +<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" immediate="true" name="org.eclipse.osee.framework.messaging.internal.old.MessagingGatewayImpl"> + <implementation class="org.eclipse.osee.framework.messaging.internal.old.MessagingGatewayImpl"/> + <service> + <provide interface="org.eclipse.osee.framework.messaging.MessagingGateway"/> + </service> +</scr:component> diff --git a/plugins/org.eclipse.osee.framework.messaging/OSGI-INF/message.service.command.xml b/plugins/org.eclipse.osee.framework.messaging/OSGI-INF/message.service.command.xml new file mode 100644 index 00000000000..1b637fc90a8 --- /dev/null +++ b/plugins/org.eclipse.osee.framework.messaging/OSGI-INF/message.service.command.xml @@ -0,0 +1,8 @@ +<?xml version="1.0" encoding="UTF-8"?> +<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" name="org.eclipse.osee.framework.messaging.internal.MessageServiceConsole"> + <implementation class="org.eclipse.osee.framework.messaging.internal.MessageServiceConsole"/> + <reference bind="setMessageService" cardinality="1..1" interface="org.eclipse.osee.framework.messaging.MessageService" name="MessageService" policy="static"/> + <service> + <provide interface="org.eclipse.osgi.framework.console.CommandProvider"/> + </service> +</scr:component> diff --git a/plugins/org.eclipse.osee.framework.messaging/OSGI-INF/message.service.xml b/plugins/org.eclipse.osee.framework.messaging/OSGI-INF/message.service.xml new file mode 100644 index 00000000000..2cc0dd9be41 --- /dev/null +++ b/plugins/org.eclipse.osee.framework.messaging/OSGI-INF/message.service.xml @@ -0,0 +1,7 @@ +<?xml version="1.0" encoding="UTF-8"?> +<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" activate="start" deactivate="stop" immediate="true" name="org.eclipse.osee.framework.messaging"> + <implementation class="org.eclipse.osee.framework.messaging.internal.MessageServiceProxy"/> + <service> + <provide interface="org.eclipse.osee.framework.messaging.MessageService"/> + </service> +</scr:component> diff --git a/plugins/org.eclipse.osee.framework.messaging/OSGI-INF/remove.message.service.lookup.xml b/plugins/org.eclipse.osee.framework.messaging/OSGI-INF/remove.message.service.lookup.xml new file mode 100644 index 00000000000..70aaf39b4a8 --- /dev/null +++ b/plugins/org.eclipse.osee.framework.messaging/OSGI-INF/remove.message.service.lookup.xml @@ -0,0 +1,9 @@ +<?xml version="1.0" encoding="UTF-8"?> +<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" activate="start" deactivate="stop" name="org.eclipse.osee.framework.messaging.internal.RemoteServiceLookupProxy"> + <implementation class="org.eclipse.osee.framework.messaging.internal.RemoteServiceLookupProxy"/> + <reference bind="setMessageService" cardinality="1..1" interface="org.eclipse.osee.framework.messaging.MessageService" name="MessageService" policy="static"/> + <service> + <provide interface="org.eclipse.osee.framework.messaging.services.RemoteServiceLookup"/> + <provide interface="org.eclipse.osee.framework.messaging.services.RemoteServiceRegistrar"/> + </service> +</scr:component> diff --git a/plugins/org.eclipse.osee.framework.messaging/build.properties b/plugins/org.eclipse.osee.framework.messaging/build.properties index b3415af20a4..8b4e901e2d4 100644 --- a/plugins/org.eclipse.osee.framework.messaging/build.properties +++ b/plugins/org.eclipse.osee.framework.messaging/build.properties @@ -1,12 +1,16 @@ -source.. = src/,\ - src-gen/ output.. = bin/ bin.includes = META-INF/,\ .,\ customBuildCallbacks.xml,\ msgSchemas/,\ - build.properties -customBuildCallbacks = customBuildCallbacks.xml -customBuildCallbacks.failonerror = true + build.properties,\ + OSGI-INF/message.service.xml,\ + OSGI-INF/message.service.command.xml,\ + OSGI-INF/remove.message.service.lookup.xml,\ + OSGI-INF/legacy.messaging.gateway.xml +customBuildCallbacks.failonerror = true customBuildCallbacks.inheritall = true -custom = true +source.. = src/,\ + src-gen/ +custom = true +customBuildCallbacks = customBuildCallbacks.xml diff --git a/plugins/org.eclipse.osee.framework.messaging/src/org/eclipse/osee/framework/messaging/internal/Activator.java b/plugins/org.eclipse.osee.framework.messaging/src/org/eclipse/osee/framework/messaging/internal/Activator.java index b51d5f13aed..6e10ae156e3 100644 --- a/plugins/org.eclipse.osee.framework.messaging/src/org/eclipse/osee/framework/messaging/internal/Activator.java +++ b/plugins/org.eclipse.osee.framework.messaging/src/org/eclipse/osee/framework/messaging/internal/Activator.java @@ -10,15 +10,8 @@ *******************************************************************************/ package org.eclipse.osee.framework.messaging.internal; -import org.eclipse.osee.framework.messaging.MessageService; -import org.eclipse.osee.framework.messaging.MessagingGateway; -import org.eclipse.osee.framework.messaging.internal.old.MessagingGatewayImpl; -import org.eclipse.osee.framework.messaging.services.internal.ServiceLookupAndRegistrarLifeCycle; -import org.eclipse.osee.framework.plugin.core.util.ExportClassLoader; -import org.eclipse.osgi.framework.console.CommandProvider; import org.osgi.framework.BundleActivator; import org.osgi.framework.BundleContext; -import org.osgi.framework.ServiceRegistration; /** * @author Andrew M. Finkbeiner @@ -27,53 +20,16 @@ public class Activator implements BundleActivator { private static Activator me; private BundleContext context; - private ServiceRegistration msgServiceRegistration; - private MessageServiceProviderImpl messageServiceProviderImpl; - private ServiceLookupAndRegistrarLifeCycle serviceLookupAndRegistrarLifeCycle; - // old - private ServiceRegistration registration; - private MessagingGatewayImpl messaging; - private ServiceRegistration msgCommandProvider; - @Override public void start(BundleContext context) throws Exception { this.context = context; me = this; - serviceLookupAndRegistrarLifeCycle = - new ServiceLookupAndRegistrarLifeCycle(context, ExportClassLoader.getInstance()); - serviceLookupAndRegistrarLifeCycle.open(true); - - messageServiceProviderImpl = new MessageServiceProviderImpl(ExportClassLoader.getInstance()); - messageServiceProviderImpl.start(); - msgServiceRegistration = - context.registerService(MessageService.class.getName(), messageServiceProviderImpl.getMessageService(), null); - - msgCommandProvider = - context.registerService(CommandProvider.class.getName(), - new MessageServiceConsole(messageServiceProviderImpl.getMessageService()), null); - //old - messaging = new MessagingGatewayImpl(); - registration = context.registerService(MessagingGateway.class.getName(), messaging, null); } @Override public void stop(BundleContext context) throws Exception { me = null; this.context = null; - - if (msgServiceRegistration != null) { - msgServiceRegistration.unregister(); - } - messageServiceProviderImpl.stop(); - msgCommandProvider.unregister(); - //old - if (registration != null) { - registration.unregister(); - } - - if (messaging != null) { - messaging.dispose(); - } } public static Activator getInstance() { diff --git a/plugins/org.eclipse.osee.framework.messaging/src/org/eclipse/osee/framework/messaging/internal/MessageServiceConsole.java b/plugins/org.eclipse.osee.framework.messaging/src/org/eclipse/osee/framework/messaging/internal/MessageServiceConsole.java index 540891c5bd4..ddbc61f4c5b 100644 --- a/plugins/org.eclipse.osee.framework.messaging/src/org/eclipse/osee/framework/messaging/internal/MessageServiceConsole.java +++ b/plugins/org.eclipse.osee.framework.messaging/src/org/eclipse/osee/framework/messaging/internal/MessageServiceConsole.java @@ -21,9 +21,9 @@ import org.eclipse.osgi.framework.console.CommandProvider; */ public class MessageServiceConsole implements CommandProvider { - private final MessageService messageService; + private MessageService messageService; - MessageServiceConsole(MessageService messageService) { + public void setMessageService(MessageService messageService) { this.messageService = messageService; } diff --git a/plugins/org.eclipse.osee.framework.messaging/src/org/eclipse/osee/framework/messaging/internal/MessageServiceProviderImpl.java b/plugins/org.eclipse.osee.framework.messaging/src/org/eclipse/osee/framework/messaging/internal/MessageServiceProviderImpl.java deleted file mode 100644 index 8c14f4122af..00000000000 --- a/plugins/org.eclipse.osee.framework.messaging/src/org/eclipse/osee/framework/messaging/internal/MessageServiceProviderImpl.java +++ /dev/null @@ -1,48 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010 Boeing. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Boeing - initial API and implementation - *******************************************************************************/ -package org.eclipse.osee.framework.messaging.internal; - -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import org.eclipse.osee.framework.messaging.MessageService; -import org.eclipse.osee.framework.messaging.MessageServiceProvider; -import org.eclipse.osee.framework.messaging.internal.activemq.ConnectionNodeFactoryImpl; - -/** - * @author Andrew M. Finkbeiner - */ -public class MessageServiceProviderImpl implements MessageServiceProvider { - - private MessageServiceImpl messageService; - private ExecutorService executor; - private final ClassLoader contextClassLoader; - - MessageServiceProviderImpl(ClassLoader contextClassLoader) { - this.contextClassLoader = contextClassLoader; - } - - public void start() throws Exception { - // Thread.currentThread().setContextClassLoader(contextClassLoader); - executor = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors()); - messageService = - new MessageServiceImpl(new ConnectionNodeFactoryImpl("1.0", Integer.toString(hashCode()), executor)); - } - - public void stop() throws Exception { - messageService.stop(); - executor.shutdown(); - } - - @Override - public MessageService getMessageService() { - return messageService; - } -} diff --git a/plugins/org.eclipse.osee.framework.messaging/src/org/eclipse/osee/framework/messaging/internal/MessageServiceProxy.java b/plugins/org.eclipse.osee.framework.messaging/src/org/eclipse/osee/framework/messaging/internal/MessageServiceProxy.java new file mode 100644 index 00000000000..43fa8a6fee3 --- /dev/null +++ b/plugins/org.eclipse.osee.framework.messaging/src/org/eclipse/osee/framework/messaging/internal/MessageServiceProxy.java @@ -0,0 +1,77 @@ +/******************************************************************************* + * Copyright (c) 2012 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.messaging.internal; + +import java.util.Collection; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import org.eclipse.osee.framework.core.exception.OseeCoreException; +import org.eclipse.osee.framework.messaging.ConnectionNode; +import org.eclipse.osee.framework.messaging.ConnectionNodeFactory; +import org.eclipse.osee.framework.messaging.MessageService; +import org.eclipse.osee.framework.messaging.NodeInfo; +import org.eclipse.osee.framework.messaging.internal.activemq.ConnectionNodeFactoryImpl; + +/** + * @author Roberto E. Escobar + */ +public class MessageServiceProxy implements MessageService { + + private MessageServiceImpl messageService; + private ExecutorService executor; + + public void start() { + executor = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors()); + + String sourceId = Integer.toString(hashCode()); + ConnectionNodeFactory factory = new ConnectionNodeFactoryImpl("1.0", sourceId, executor); + + messageService = new MessageServiceImpl(factory); + } + + public void stop() { + executor.shutdown(); + executor = null; + + messageService.stop(); + messageService = null; + } + + MessageService getProxiedService() { + return messageService; + } + + @Override + public ConnectionNode getDefault() throws OseeCoreException { + return getProxiedService().getDefault(); + } + + @Override + public ConnectionNode get(NodeInfo nodeInfo) throws OseeCoreException { + return getProxiedService().get(nodeInfo); + } + + @Override + public Collection<NodeInfo> getAvailableConnections() { + return getProxiedService().getAvailableConnections(); + } + + @Override + public int size() { + return getProxiedService().size(); + } + + @Override + public boolean isEmpty() { + return getProxiedService().isEmpty(); + } + +} diff --git a/plugins/org.eclipse.osee.framework.messaging/src/org/eclipse/osee/framework/messaging/internal/RemoteServiceLookupProxy.java b/plugins/org.eclipse.osee.framework.messaging/src/org/eclipse/osee/framework/messaging/internal/RemoteServiceLookupProxy.java new file mode 100644 index 00000000000..a2a2f3a6232 --- /dev/null +++ b/plugins/org.eclipse.osee.framework.messaging/src/org/eclipse/osee/framework/messaging/internal/RemoteServiceLookupProxy.java @@ -0,0 +1,105 @@ +/******************************************************************************* + * Copyright (c) 2012 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.messaging.internal; + +import java.net.URI; +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; +import org.eclipse.osee.framework.messaging.services.RegisteredServiceReference; +import org.eclipse.osee.framework.messaging.services.RemoteServiceLookup; +import org.eclipse.osee.framework.messaging.services.RemoteServiceRegistrar; +import org.eclipse.osee.framework.messaging.services.ServiceInfoPopulator; +import org.eclipse.osee.framework.messaging.services.ServiceNotification; +import org.eclipse.osee.framework.messaging.services.internal.RemoteServiceLookupImpl; +import org.eclipse.osee.framework.messaging.services.internal.RemoteServiceRegistrarImpl; +import org.eclipse.osee.framework.plugin.core.util.ExportClassLoader; + +/** + * @author Roberto E. Escobar + */ +public class RemoteServiceLookupProxy implements RemoteServiceLookup, RemoteServiceRegistrar { + + private ClassLoader contextClassLoader; + private RemoteServiceRegistrarImpl registrar; + private RemoteServiceLookupImpl lookup; + private ScheduledExecutorService executor; + + private MessageService messageService; + + public void setMessageService(MessageService messageService) { + this.messageService = messageService; + } + + public void start() throws OseeCoreException { + OseeLog.log(Activator.class, Level.INFO, "Remote Service Lookup - Starting"); + executor = Executors.newScheduledThreadPool(2); + + contextClassLoader = ExportClassLoader.getInstance(); + Thread.currentThread().setContextClassLoader(contextClassLoader); + + registrar = new RemoteServiceRegistrarImpl(messageService.getDefault(), executor); + registrar.start(); + + lookup = new RemoteServiceLookupImpl(messageService.getDefault(), executor); + lookup.start(); + OseeLog.log(Activator.class, Level.INFO, "Remote Service Lookup - Started"); + } + + public void stop() { + OseeLog.log(Activator.class, Level.INFO, "Remote Service Lookup - Stopping"); + if (lookup != null) { + lookup.stop(); + lookup = null; + } + if (registrar != null) { + registrar.stop(); + registrar = null; + } + + if (executor != null) { + executor.shutdown(); + executor = null; + } + contextClassLoader = null; + OseeLog.log(Activator.class, Level.INFO, "Remote Service Lookup - Stopped"); + } + + @Override + public void sendOutRequestsForServiceHealth() { + lookup.sendOutRequestsForServiceHealth(); + } + + @Override + public void register(String serviceId, String serviceVersion, ServiceNotification notification) { + lookup.register(serviceId, serviceVersion, notification); + } + + @Override + public boolean unregister(String serviceId, String serviceVersion, ServiceNotification notification) { + return lookup.unregister(serviceId, serviceVersion, notification); + } + + @Override + public RegisteredServiceReference registerService(String serviceName, String serviceVersion, String serviceUniqueId, URI broker, ServiceInfoPopulator infoPopulator, int refreshRateInSeconds) { + return registrar.registerService(serviceName, serviceVersion, serviceUniqueId, broker, infoPopulator, + refreshRateInSeconds); + } + + @Override + public boolean unregisterService(String serviceName, String serviceVersion, String serviceUniqueId) { + return registrar.unregisterService(serviceName, serviceVersion, serviceUniqueId); + } + +} diff --git a/plugins/org.eclipse.osee.framework.messaging/src/org/eclipse/osee/framework/messaging/services/RemoteServiceLookup.java b/plugins/org.eclipse.osee.framework.messaging/src/org/eclipse/osee/framework/messaging/services/RemoteServiceLookup.java index e063669211d..dead81c9cce 100644 --- a/plugins/org.eclipse.osee.framework.messaging/src/org/eclipse/osee/framework/messaging/services/RemoteServiceLookup.java +++ b/plugins/org.eclipse.osee.framework.messaging/src/org/eclipse/osee/framework/messaging/services/RemoteServiceLookup.java @@ -14,9 +14,6 @@ package org.eclipse.osee.framework.messaging.services; * @author Andrew M. Finkbeiner */ public interface RemoteServiceLookup { - void start(); - - void stop(); void sendOutRequestsForServiceHealth(); diff --git a/plugins/org.eclipse.osee.framework.messaging/src/org/eclipse/osee/framework/messaging/services/RemoteServiceRegistrar.java b/plugins/org.eclipse.osee.framework.messaging/src/org/eclipse/osee/framework/messaging/services/RemoteServiceRegistrar.java index 53c6b702726..33fbed041fe 100644 --- a/plugins/org.eclipse.osee.framework.messaging/src/org/eclipse/osee/framework/messaging/services/RemoteServiceRegistrar.java +++ b/plugins/org.eclipse.osee.framework.messaging/src/org/eclipse/osee/framework/messaging/services/RemoteServiceRegistrar.java @@ -16,9 +16,6 @@ import java.net.URI; * @author Andrew M. Finkbeiner */ public interface RemoteServiceRegistrar { - void start(); - - void stop(); RegisteredServiceReference registerService(String serviceName, String serviceVersion, String serviceUniqueId, URI broker, ServiceInfoPopulator infoPopulator, int refreshRateInSeconds); diff --git a/plugins/org.eclipse.osee.framework.messaging/src/org/eclipse/osee/framework/messaging/services/internal/RemoteServiceLookupImpl.java b/plugins/org.eclipse.osee.framework.messaging/src/org/eclipse/osee/framework/messaging/services/internal/RemoteServiceLookupImpl.java index e6d8c0ac62c..beff750af74 100644 --- a/plugins/org.eclipse.osee.framework.messaging/src/org/eclipse/osee/framework/messaging/services/internal/RemoteServiceLookupImpl.java +++ b/plugins/org.eclipse.osee.framework.messaging/src/org/eclipse/osee/framework/messaging/services/internal/RemoteServiceLookupImpl.java @@ -47,14 +47,12 @@ public class RemoteServiceLookupImpl implements RemoteServiceLookup { executor.scheduleAtFixedRate(new MonitorTimedOutServices(map, callbacks), 30, 30, TimeUnit.SECONDS); } - @Override public void start() { connectionNode.subscribe(BaseMessages.ServiceHealth, healthServiceListener, new OseeMessagingStatusImpl( "Failed to subscribe to " + BaseMessages.ServiceHealth.getName(), RemoteServiceLookupImpl.class)); } - @Override public void stop() { connectionNode.unsubscribe(BaseMessages.ServiceHealth, healthServiceListener, new OseeMessagingStatusImpl( "Failed to subscribe to " + BaseMessages.ServiceHealth.getName(), RemoteServiceLookupImpl.class)); 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 5e0ad1d40a7..61c23d1ef9b 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 @@ -45,13 +45,11 @@ public class RemoteServiceRegistrarImpl implements RemoteServiceRegistrar { healthRequestListener = new HealthRequestListener(mapForReplys); } - @Override public void start() { connectionNode.subscribe(BaseMessages.ServiceHealthRequest, healthRequestListener, new OseeMessagingStatusImpl( "Failed to subscribe to " + BaseMessages.ServiceHealthRequest.getName(), RemoteServiceRegistrarImpl.class)); } - @Override public void stop() { connectionNode.unsubscribe(BaseMessages.ServiceHealthRequest, healthRequestListener, new OseeMessagingStatusImpl( "Failed to subscribe to " + BaseMessages.ServiceHealthRequest.getName(), RemoteServiceRegistrarImpl.class)); 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 deleted file mode 100644 index 417873d1486..00000000000 --- a/plugins/org.eclipse.osee.framework.messaging/src/org/eclipse/osee/framework/messaging/services/internal/ServiceLookupAndRegistrarLifeCycle.java +++ /dev/null @@ -1,105 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010 Boeing. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Boeing - initial API and implementation - *******************************************************************************/ -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; -import org.eclipse.osee.framework.messaging.internal.Activator; -import org.eclipse.osee.framework.messaging.services.RemoteServiceLookup; -import org.eclipse.osee.framework.messaging.services.RemoteServiceRegistrar; -import org.osgi.framework.BundleContext; -import org.osgi.framework.ServiceReference; -import org.osgi.framework.ServiceRegistration; -import org.osgi.util.tracker.ServiceTracker; - -/** - * @author Andrew M. Finkbeiner - */ -public class ServiceLookupAndRegistrarLifeCycle extends ServiceTracker { - - private RemoteServiceRegistrar registrar; - private ServiceRegistration lookupRegistration; - private ServiceRegistration registrarRegistration; - private final ClassLoader contextClassLoader; - private RemoteServiceLookupImpl lookup; - - public ServiceLookupAndRegistrarLifeCycle(BundleContext context, ClassLoader contextClassLoader) { - super(context, MessageService.class.getName(), null); - this.contextClassLoader = contextClassLoader; - } - - @Override - public Object addingService(ServiceReference reference) { - OseeLog.logf(Activator.class, Level.INFO, "Found %s service.", MessageService.class.getName()); - OseeLog.logf(Activator.class, Level.FINEST, "GOING TO GET THE REF"); - MessageService messageService = (MessageService) context.getService(reference); - OseeLog.logf(Activator.class, Level.FINEST, "got the service ref"); - ScheduledExecutorService executor = Executors.newScheduledThreadPool(2); - OseeLog.logf(Activator.class, Level.FINEST, "got exec"); - try { - OseeLog.logf(Activator.class, Level.FINEST, "set context classloader"); - Thread.currentThread().setContextClassLoader(contextClassLoader); - OseeLog.logf(Activator.class, Level.FINEST, "done set context classloader"); - registrar = new RemoteServiceRegistrarImpl(messageService.getDefault(), executor); - OseeLog.logf(Activator.class, Level.FINEST, - "Getting ready to start %s.", RemoteServiceRegistrarImpl.class.getName()); - registrar.start(); - OseeLog.logf(Activator.class, Level.FINEST, - "started %s.", RemoteServiceRegistrarImpl.class.getName()); - lookup = new RemoteServiceLookupImpl(messageService.getDefault(), executor); - OseeLog.logf(Activator.class, Level.FINEST, - "Getting ready to start %s.", RemoteServiceLookupImpl.class.getName()); - lookup.start(); - OseeLog.logf(Activator.class, Level.FINEST, - "started %s.", RemoteServiceLookupImpl.class.getName()); - - lookupRegistration = context.registerService(RemoteServiceLookup.class.getName(), lookup, null); - OseeLog.logf(Activator.class, Level.INFO, "Registered %s.", RemoteServiceLookup.class.getName()); - registrarRegistration = context.registerService(RemoteServiceRegistrar.class.getName(), registrar, null); - OseeLog.logf(Activator.class, Level.INFO, - "Registered %s.", RemoteServiceRegistrar.class.getName()); - } catch (OseeCoreException ex) { - OseeLog.log(ServiceLookupAndRegistrarLifeCycle.class, Level.SEVERE, ex); - } - return super.addingService(reference); - } - - @Override - public void removedService(ServiceReference reference, Object service) { - 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(); - } - - } - -} |