diff options
author | Andrew M. Finkbeiner | 2014-03-05 19:21:51 +0000 |
---|---|---|
committer | Ryan T. Baldwin | 2014-03-05 19:21:51 +0000 |
commit | 3ea0608b258f867b45edf861641816050eea43e7 (patch) | |
tree | 017d6b91faec1f7b953829979cbe569b77d1f448 /plugins/org.eclipse.osee.framework.messaging/src/org/eclipse | |
parent | 629b51f04daf7a15ffb97671713e38c30659d937 (diff) | |
download | org.eclipse.osee-3ea0608b258f867b45edf861641816050eea43e7.tar.gz org.eclipse.osee-3ea0608b258f867b45edf861641816050eea43e7.tar.xz org.eclipse.osee-3ea0608b258f867b45edf861641816050eea43e7.zip |
feature[ats_ATS27250]: Remove unnecessary JMS code
Diffstat (limited to 'plugins/org.eclipse.osee.framework.messaging/src/org/eclipse')
8 files changed, 0 insertions, 565 deletions
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 deleted file mode 100644 index 759f950ea76..00000000000 --- a/plugins/org.eclipse.osee.framework.messaging/src/org/eclipse/osee/framework/messaging/internal/RemoteServiceLookupProxy.java +++ /dev/null @@ -1,109 +0,0 @@ -/******************************************************************************* - * 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.concurrent.TimeUnit; -import java.util.logging.Level; -import org.eclipse.osee.framework.jdk.core.type.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 static final long SERVICE_LOOKUP_TIMEOUT = 30; - - 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, SERVICE_LOOKUP_TIMEOUT, TimeUnit.SECONDS); - 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 deleted file mode 100644 index dead81c9cce..00000000000 --- a/plugins/org.eclipse.osee.framework.messaging/src/org/eclipse/osee/framework/messaging/services/RemoteServiceLookup.java +++ /dev/null @@ -1,23 +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; - -/** - * @author Andrew M. Finkbeiner - */ -public interface RemoteServiceLookup { - - void sendOutRequestsForServiceHealth(); - - void register(String serviceId, String serviceVersion, ServiceNotification notification); - - boolean unregister(String serviceId, String serviceVersion, ServiceNotification notification); -} 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 deleted file mode 100644 index 33fbed041fe..00000000000 --- a/plugins/org.eclipse.osee.framework.messaging/src/org/eclipse/osee/framework/messaging/services/RemoteServiceRegistrar.java +++ /dev/null @@ -1,23 +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; - -import java.net.URI; - -/** - * @author Andrew M. Finkbeiner - */ -public interface RemoteServiceRegistrar { - - RegisteredServiceReference registerService(String serviceName, String serviceVersion, String serviceUniqueId, URI broker, ServiceInfoPopulator infoPopulator, int refreshRateInSeconds); - - boolean unregisterService(String serviceName, String serviceVersion, String serviceUniqueId); -} diff --git a/plugins/org.eclipse.osee.framework.messaging/src/org/eclipse/osee/framework/messaging/services/ServiceNotification.java b/plugins/org.eclipse.osee.framework.messaging/src/org/eclipse/osee/framework/messaging/services/ServiceNotification.java deleted file mode 100644 index bbfda964bd0..00000000000 --- a/plugins/org.eclipse.osee.framework.messaging/src/org/eclipse/osee/framework/messaging/services/ServiceNotification.java +++ /dev/null @@ -1,24 +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; - -import org.eclipse.osee.framework.messaging.services.messages.ServiceHealth; - -/** - * @author Andrew M. Finkbeiner - */ -public interface ServiceNotification { - void onServiceUpdate(ServiceHealth serviceHealth); - - void onServiceGone(ServiceHealth serviceHealth); - - boolean isServiceGone(ServiceHealth serviceHealth); -} diff --git a/plugins/org.eclipse.osee.framework.messaging/src/org/eclipse/osee/framework/messaging/services/internal/HealthServiceListener.java b/plugins/org.eclipse.osee.framework.messaging/src/org/eclipse/osee/framework/messaging/services/internal/HealthServiceListener.java deleted file mode 100644 index de7a9c8449d..00000000000 --- a/plugins/org.eclipse.osee.framework.messaging/src/org/eclipse/osee/framework/messaging/services/internal/HealthServiceListener.java +++ /dev/null @@ -1,68 +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.List; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; -import org.eclipse.osee.framework.jdk.core.type.CompositeKeyHashMap; -import org.eclipse.osee.framework.messaging.OseeMessagingListener; -import org.eclipse.osee.framework.messaging.ReplyConnection; -import org.eclipse.osee.framework.messaging.services.ServiceNotification; -import org.eclipse.osee.framework.messaging.services.messages.ServiceHealth; - -/** - * @author Andrew M. Finkbeiner - */ -class HealthServiceListener extends OseeMessagingListener { - - private static final int WIGGLE_ROOM = 20000; - - private final CompositeKeyHashMap<String/* serviceName */, String /* serviceVersion */, Map<String /* serviceUniqueId */, ServiceHealthPlusTimeout>> map; - private final CompositeKeyHashMap<String/* serviceName */, String /* serviceVersion */, List<ServiceNotification>> callbacks; - - HealthServiceListener(CompositeKeyHashMap<String, String, Map<String, ServiceHealthPlusTimeout>> map, CompositeKeyHashMap<String, String, List<ServiceNotification>> callbacks) { - super(ServiceHealth.class); - this.map = map; - this.callbacks = callbacks; - } - - @Override - public void process(Object message, Map<String, Object> headers, ReplyConnection replyConnection) { - ServiceHealth health = (ServiceHealth) message; - - if (health.isStopping()) { - List<ServiceNotification> itemsToNotify = callbacks.get(health.getServiceName(), health.getServiceVersion()); - if (itemsToNotify != null) { - for (ServiceNotification notification : itemsToNotify) { - notification.onServiceGone(health); - } - } - } else { - Map<String, ServiceHealthPlusTimeout> idMap = map.get(health.getServiceName(), health.getServiceVersion()); - if (idMap == null) { - idMap = new ConcurrentHashMap<String, ServiceHealthPlusTimeout>(); - map.put(health.getServiceName(), health.getServiceVersion(), idMap); - } - long shouldHaveRenewedTime = - System.currentTimeMillis() + health.getRefreshRateInSeconds() * 1000 + WIGGLE_ROOM; - idMap.put(health.getServiceUniqueId(), new ServiceHealthPlusTimeout(health, shouldHaveRenewedTime)); - - List<ServiceNotification> itemsToNotify = callbacks.get(health.getServiceName(), health.getServiceVersion()); - if (itemsToNotify != null) { - for (ServiceNotification notification : itemsToNotify) { - notification.onServiceUpdate(health); - } - } - } - } - -} diff --git a/plugins/org.eclipse.osee.framework.messaging/src/org/eclipse/osee/framework/messaging/services/internal/MonitorTimedOutServices.java b/plugins/org.eclipse.osee.framework.messaging/src/org/eclipse/osee/framework/messaging/services/internal/MonitorTimedOutServices.java deleted file mode 100644 index f7e4257a73a..00000000000 --- a/plugins/org.eclipse.osee.framework.messaging/src/org/eclipse/osee/framework/messaging/services/internal/MonitorTimedOutServices.java +++ /dev/null @@ -1,86 +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.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Set; -import org.eclipse.osee.framework.jdk.core.type.CompositeKeyHashMap; -import org.eclipse.osee.framework.jdk.core.type.Pair; -import org.eclipse.osee.framework.messaging.services.ServiceNotification; -import org.eclipse.osee.framework.messaging.services.messages.ServiceHealth; - -/** - * @author Andrew M. Finkbeiner - */ -class MonitorTimedOutServices implements Runnable { - - private final CompositeKeyHashMap<String, String, Map<String, ServiceHealthPlusTimeout>> map; - private final CompositeKeyHashMap<String, String, List<ServiceNotification>> callbacks; - - public MonitorTimedOutServices(CompositeKeyHashMap<String, String, Map<String, ServiceHealthPlusTimeout>> map, CompositeKeyHashMap<String, String, List<ServiceNotification>> callbacks) { - this.map = map; - this.callbacks = callbacks; - } - - @Override - public void run() { - List<ThreeItems> toRemove = new ArrayList<ThreeItems>(); - long currentSystemTime = System.currentTimeMillis(); - Set<Pair<String, String>> keySet = map.keySet(); - for (Pair<String, String> pair : keySet) { - Map<String, ServiceHealthPlusTimeout> items = map.get(pair.getFirst(), pair.getSecond()); - for (Entry<String, ServiceHealthPlusTimeout> key : items.entrySet()) { - if (key.getValue().isTimedOut(currentSystemTime)) { - List<ServiceNotification> list = callbacks.get(pair.getFirst(), pair.getSecond()); - if (isServiceReallyGone(list, key.getValue().getServiceHealth())) { - toRemove.add(new ThreeItems(pair.getFirst(), pair.getSecond(), key.getKey())); - for (ServiceNotification notify : list) { - notify.onServiceGone(key.getValue().getServiceHealth()); - } - } - } - } - } - for (ThreeItems item : toRemove) { - Map<String, ServiceHealthPlusTimeout> innerMap = map.get(item.first, item.second); - innerMap.remove(item.key); - if (innerMap.isEmpty()) { - map.remove(item.first, item.second); - } - } - } - - private boolean isServiceReallyGone(List<ServiceNotification> list, ServiceHealth serviceHealth) { - for (ServiceNotification notify : list) { - if (!notify.isServiceGone(serviceHealth)) { - return false; - } - } - return true; - } - - private static class ThreeItems { - - String first; - String second; - String key; - - ThreeItems(String first, String second, String key) { - this.first = first; - this.second = second; - this.key = key; - } - } - -} 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 deleted file mode 100644 index 9198c5c308b..00000000000 --- a/plugins/org.eclipse.osee.framework.messaging/src/org/eclipse/osee/framework/messaging/services/internal/RemoteServiceLookupImpl.java +++ /dev/null @@ -1,113 +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.List; -import java.util.Map; -import java.util.Set; -import java.util.concurrent.CopyOnWriteArrayList; -import java.util.concurrent.ScheduledExecutorService; -import java.util.concurrent.TimeUnit; -import java.util.logging.Level; -import org.eclipse.osee.framework.jdk.core.type.CompositeKeyHashMap; -import org.eclipse.osee.framework.jdk.core.type.OseeCoreException; -import org.eclipse.osee.framework.jdk.core.type.Pair; -import org.eclipse.osee.framework.logging.OseeLog; -import org.eclipse.osee.framework.messaging.ConnectionNode; -import org.eclipse.osee.framework.messaging.services.BaseMessages; -import org.eclipse.osee.framework.messaging.services.RemoteServiceLookup; -import org.eclipse.osee.framework.messaging.services.ServiceNotification; -import org.eclipse.osee.framework.messaging.services.messages.ServiceHealthRequest; - -/** - * @author Andrew M. Finkbeiner - */ -public class RemoteServiceLookupImpl implements RemoteServiceLookup { - - private final ConnectionNode connectionNode; - private final CompositeKeyHashMap<String, String, Map<String, ServiceHealthPlusTimeout>> map; - private final CompositeKeyHashMap<String, String, List<ServiceNotification>> callbacks; - private final HealthServiceListener healthServiceListener; - - public RemoteServiceLookupImpl(ConnectionNode node, ScheduledExecutorService executor, long serviceTimeout, TimeUnit unit) { - this.connectionNode = node; - map = new CompositeKeyHashMap<String, String, Map<String, ServiceHealthPlusTimeout>>(25, true); - callbacks = new CompositeKeyHashMap<String, String, List<ServiceNotification>>(25, true); - healthServiceListener = new HealthServiceListener(map, callbacks); - connectionNode.subscribeToReply(BaseMessages.ServiceHealthRequest, healthServiceListener); - executor.scheduleAtFixedRate(new MonitorTimedOutServices(map, callbacks), serviceTimeout, serviceTimeout, unit); - } - - public void start() { - connectionNode.subscribe(BaseMessages.ServiceHealth, healthServiceListener, new OseeMessagingStatusImpl( - "Failed to subscribe to " + BaseMessages.ServiceHealth.getName(), RemoteServiceLookupImpl.class)); - - } - - public void stop() { - connectionNode.unsubscribe(BaseMessages.ServiceHealth, healthServiceListener, new OseeMessagingStatusImpl( - "Failed to subscribe to " + BaseMessages.ServiceHealth.getName(), RemoteServiceLookupImpl.class)); - } - - @Override - public void register(String serviceName, String serviceVersion, ServiceNotification notification) { - - addListener(serviceName, serviceVersion, notification); - sendOutRequest(serviceName, serviceVersion); - } - - @Override - public void sendOutRequestsForServiceHealth() { - Set<Pair<String, String>> pairs = callbacks.keySet(); - for (Pair<String, String> pair : pairs) { - sendOutRequest(pair.getFirst(), pair.getSecond()); - } - } - - private void sendOutRequest(String serviceName, String serviceVersion) { - ServiceHealthRequest request = new ServiceHealthRequest(); - request.setServiceName(serviceName); - request.setServiceVersion(serviceVersion); - try { - connectionNode.send( - BaseMessages.ServiceHealthRequest, - request, - new OseeMessagingStatusImpl(String.format("Failed to send Health Request for %s [%s]", serviceName, - serviceVersion), RemoteServiceLookup.class)); - } catch (OseeCoreException ex) { - OseeLog.log(RemoteServiceLookupImpl.class, Level.SEVERE, ex); - } - } - - private void addListener(String serviceName, String serviceVersion, ServiceNotification notification) { - List<ServiceNotification> itemsToNotify = callbacks.get(serviceName, serviceVersion); - if (itemsToNotify == null) { - itemsToNotify = new CopyOnWriteArrayList<ServiceNotification>(); - callbacks.put(serviceName, serviceVersion, itemsToNotify); - } - itemsToNotify.add(notification); - } - - @Override - public boolean unregister(String serviceName, String serviceVersion, ServiceNotification notification) { - return removeListener(serviceName, serviceVersion, notification); - } - - private boolean removeListener(String serviceName, String serviceVersion, ServiceNotification notification) { - List<ServiceNotification> itemsToNotify = callbacks.get(serviceName, serviceVersion); - boolean removed = false; - if (itemsToNotify != null) { - removed = itemsToNotify.remove(notification); - } - return removed; - } - -} 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 deleted file mode 100644 index 61c23d1ef9b..00000000000 --- a/plugins/org.eclipse.osee.framework.messaging/src/org/eclipse/osee/framework/messaging/services/internal/RemoteServiceRegistrarImpl.java +++ /dev/null @@ -1,119 +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.net.URI; -import java.util.List; -import java.util.concurrent.ConcurrentHashMap; -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; - -/** - * @author Andrew M. Finkbeiner - */ -public class RemoteServiceRegistrarImpl implements RemoteServiceRegistrar { - - private final ConnectionNode connectionNode; - private final ConcurrentHashMap<String, ScheduledFuture<?>> map; - private final ConcurrentHashMap<String, UpdateStatus> mapOfUpdateStatus; - private final CompositeKeyHashMap<String, String, List<UpdateStatus>> mapForReplys; - private final ScheduledExecutorService executor; - private final HealthRequestListener healthRequestListener; - - public RemoteServiceRegistrarImpl(ConnectionNode node, ScheduledExecutorService executor) { - this.connectionNode = node; - this.executor = executor; - mapOfUpdateStatus = new ConcurrentHashMap<String, UpdateStatus>(); - map = new ConcurrentHashMap<String, ScheduledFuture<?>>(); - mapForReplys = new CompositeKeyHashMap<String, String, List<UpdateStatus>>(8, true); - healthRequestListener = new HealthRequestListener(mapForReplys); - } - - public void start() { - connectionNode.subscribe(BaseMessages.ServiceHealthRequest, healthRequestListener, new OseeMessagingStatusImpl( - "Failed to subscribe to " + BaseMessages.ServiceHealthRequest.getName(), RemoteServiceRegistrarImpl.class)); - } - - public void stop() { - connectionNode.unsubscribe(BaseMessages.ServiceHealthRequest, healthRequestListener, new OseeMessagingStatusImpl( - "Failed to subscribe to " + BaseMessages.ServiceHealthRequest.getName(), RemoteServiceRegistrarImpl.class)); - } - - @Override - public RegisteredServiceReference registerService(String serviceName, String serviceVersion, String serviceUniqueId, URI broker, ServiceInfoPopulator infoPopulator, int refreshRateInSeconds) { - String key = getKey(serviceName, serviceVersion, serviceUniqueId); - if (!mapOfUpdateStatus.containsKey(key)) { - UpdateStatus updateStatus = - new UpdateStatus(this.connectionNode, serviceName, serviceVersion, serviceUniqueId, broker, - refreshRateInSeconds, infoPopulator); - ScheduledFuture<?> scheduled = - executor.scheduleAtFixedRate(updateStatus, 0, refreshRateInSeconds, TimeUnit.SECONDS); - map.put(key, scheduled); - mapOfUpdateStatus.put(key, updateStatus); - addToReplyMap(serviceName, serviceVersion, updateStatus); - } - return new ServiceReferenceImp(mapOfUpdateStatus.get(key)); - } - - private String getKey(String serviceName, String serviceVersion, String serviceUniqueId) { - return serviceName + serviceVersion + serviceUniqueId; - } - - @Override - public boolean unregisterService(String serviceName, String serviceVersion, String serviceUniqueId) { - String key = getKey(serviceName, serviceVersion, serviceUniqueId); - - UpdateStatus updateStatus = mapOfUpdateStatus.remove(key); - if (updateStatus != null) { - updateStatus.close(); - removeFromReplyMap(serviceName, serviceVersion, updateStatus); - } - - ScheduledFuture<?> scheduled = map.remove(key); - if (scheduled == null) { - return false; - } else { - return scheduled.cancel(false); - } - } - - public void addToReplyMap(String serviceName, String serviceVersion, UpdateStatus updateForReply) { - List<UpdateStatus> list = mapForReplys.get(serviceName, serviceVersion); - if (list == null) { - list = new CopyOnWriteArrayList<UpdateStatus>(); - mapForReplys.put(serviceName, serviceVersion, list); - } - list.add(updateForReply); - } - - public boolean removeFromReplyMap(String serviceName, String serviceVersion, UpdateStatus updateForReply) { - List<UpdateStatus> list = mapForReplys.get(serviceName, serviceVersion); - if (list != null) { - return list.remove(updateForReply); - } - return false; - } - - void updateService(String key) { - UpdateStatus update = mapOfUpdateStatus.get(key); - if (update != null) { - update.run(); - } - } -} |