diff options
author | Andrew M. Finkbeiner | 2014-05-15 14:49:19 +0000 |
---|---|---|
committer | Ryan T. Baldwin | 2014-05-15 14:49:19 +0000 |
commit | f66530b3a7878f33465bd9109accfbd255e45642 (patch) | |
tree | 9c9902c9490d70cd7e9c2dfd6a802d8bae5dac71 /plugins/org.eclipse.osee.ote.client.msg/src/org/eclipse | |
parent | 853e52262f35d765e29fcc1916b8342c29e62942 (diff) | |
download | org.eclipse.osee-f66530b3a7878f33465bd9109accfbd255e45642.tar.gz org.eclipse.osee-f66530b3a7878f33465bd9109accfbd255e45642.tar.xz org.eclipse.osee-f66530b3a7878f33465bd9109accfbd255e45642.zip |
feature[ats_ATS46147]: Remove message system rmi
Diffstat (limited to 'plugins/org.eclipse.osee.ote.client.msg/src/org/eclipse')
7 files changed, 257 insertions, 131 deletions
diff --git a/plugins/org.eclipse.osee.ote.client.msg/src/org/eclipse/osee/ote/client/msg/core/db/AbstractMessageDataBase.java b/plugins/org.eclipse.osee.ote.client.msg/src/org/eclipse/osee/ote/client/msg/core/db/AbstractMessageDataBase.java index 0345b45bd05..44df86c62ed 100644 --- a/plugins/org.eclipse.osee.ote.client.msg/src/org/eclipse/osee/ote/client/msg/core/db/AbstractMessageDataBase.java +++ b/plugins/org.eclipse.osee.ote.client.msg/src/org/eclipse/osee/ote/client/msg/core/db/AbstractMessageDataBase.java @@ -24,7 +24,6 @@ import org.eclipse.osee.ote.message.Message; import org.eclipse.osee.ote.message.data.MessageData; import org.eclipse.osee.ote.message.enums.DataType; import org.eclipse.osee.ote.message.interfaces.IMsgToolServiceClient; -import org.eclipse.osee.ote.message.interfaces.IRemoteMessageService; import org.eclipse.osee.ote.message.tool.MessageMode; import org.eclipse.osee.ote.messaging.dds.entity.DataReader; import org.eclipse.osee.ote.messaging.dds.entity.EntityFactory; @@ -40,7 +39,7 @@ public abstract class AbstractMessageDataBase { new ConcurrentHashMap<Integer, MessageInstance>(); private IMsgToolServiceClient client; - private IRemoteMessageService service; + private volatile boolean connected = false; private final DataReader reader = new DataReader(null, null, true, null, new EntityFactory() { @Override @@ -50,8 +49,8 @@ public abstract class AbstractMessageDataBase { }); - protected AbstractMessageDataBase() { - + protected AbstractMessageDataBase(IMsgToolServiceClient service) { + client = service; } public MessageInstance findInstance(String name, MessageMode mode, DataType type) { @@ -84,8 +83,8 @@ public abstract class AbstractMessageDataBase { referenceToMsgMap.put(reference, instance); } instance.incrementReferenceCount(); - if (service != null && !instance.isAttached()) { - doInstanceAttach(instance, service); + if (connected && !instance.isAttached()) { + doInstanceAttach(instance); } return instance; } @@ -118,8 +117,8 @@ public abstract class AbstractMessageDataBase { referenceToMsgMap.put(reference, instance); } instance.incrementReferenceCount(); - if (service != null && !instance.isAttached()) { - doInstanceAttach(instance, service); + if (connected && !instance.isAttached()) { + doInstanceAttach(instance); } return instance; } @@ -129,7 +128,7 @@ public abstract class AbstractMessageDataBase { instance.decrementReferenceCount(); if (!instance.hasReferences()) { if (instance.isAttached()) { - doInstanceDetach(instance, service); + doInstanceDetach(instance); } MessageReference reference = new MessageReference(instance.getType(), instance.getMode(), instance.getMessage().getClass().getName()); @@ -143,12 +142,12 @@ public abstract class AbstractMessageDataBase { protected abstract void destroyMessage(Message message) throws Exception; - public void attachToService(IRemoteMessageService service, IMsgToolServiceClient client) { - this.service = service; + public void attachToService(IMsgToolServiceClient client) { + connected = true; this.client = client; for (MessageInstance instance : referenceToMsgMap.values()) { try { - doInstanceAttach(instance, service); + doInstanceAttach(instance); } catch (Exception e) { OseeLog.log(AbstractMessageDataBase.class, Level.SEVERE, "could not attach instance for " + instance.toString(), e); @@ -156,11 +155,11 @@ public abstract class AbstractMessageDataBase { } } - public void detachService(IRemoteMessageService service) { + public void detachService() { for (MessageInstance instance : referenceToMsgMap.values()) { - doInstanceDetach(instance, service); + doInstanceDetach(instance); } - this.service = null; + connected = false; this.client = null; } @@ -168,8 +167,8 @@ public abstract class AbstractMessageDataBase { return idToMsgMap.get(id); } - private boolean doInstanceAttach(MessageInstance instance, IRemoteMessageService service) throws Exception { - Integer id = instance.attachToService(service, client); + private boolean doInstanceAttach(MessageInstance instance) throws Exception { + Integer id = instance.attachToService(client); if (id == null) { // can't subscribe because environment does not support this type return false; @@ -178,13 +177,13 @@ public abstract class AbstractMessageDataBase { return true; } - private void doInstanceDetach(MessageInstance instance, IRemoteMessageService service) { + private void doInstanceDetach(MessageInstance instance) { try { Integer id = instance.getId(); if (id != null) { idToMsgMap.remove(id); } - instance.detachService(service, client); + instance.detachService(client); } catch (Exception e) { e.printStackTrace(); } diff --git a/plugins/org.eclipse.osee.ote.client.msg/src/org/eclipse/osee/ote/client/msg/core/db/MessageInstance.java b/plugins/org.eclipse.osee.ote.client.msg/src/org/eclipse/osee/ote/client/msg/core/db/MessageInstance.java index f71576d9be4..70de39a7a69 100644 --- a/plugins/org.eclipse.osee.ote.client.msg/src/org/eclipse/osee/ote/client/msg/core/db/MessageInstance.java +++ b/plugins/org.eclipse.osee.ote.client.msg/src/org/eclipse/osee/ote/client/msg/core/db/MessageInstance.java @@ -10,16 +10,16 @@ *******************************************************************************/ package org.eclipse.osee.ote.client.msg.core.db; -import java.rmi.RemoteException; +import java.net.InetSocketAddress; import java.util.HashSet; import java.util.Set; +import org.eclipse.osee.ote.client.msg.core.internal.MessageServiceSupport; import org.eclipse.osee.ote.message.Message; import org.eclipse.osee.ote.message.commands.SubscribeToMessage; import org.eclipse.osee.ote.message.commands.UnSubscribeToMessage; import org.eclipse.osee.ote.message.enums.DataType; import org.eclipse.osee.ote.message.interfaces.IMsgToolServiceClient; -import org.eclipse.osee.ote.message.interfaces.IRemoteMessageService; import org.eclipse.osee.ote.message.tool.MessageMode; import org.eclipse.osee.ote.message.tool.SubscriptionDetails; import org.eclipse.osee.ote.message.tool.SubscriptionKey; @@ -35,8 +35,8 @@ public class MessageInstance { private SubscriptionKey serverSubscriptionKey = null; private int refcount = 0; private boolean supported = true; - private volatile IRemoteMessageService service; - + private volatile boolean connected = false; + public MessageInstance(Message msg, MessageMode mode, DataType type) { this.msg = msg; this.mode = mode; @@ -59,26 +59,32 @@ public class MessageInstance { return serverSubscriptionKey != null; } - public Integer attachToService(IRemoteMessageService service, IMsgToolServiceClient client) throws Exception { - SubscriptionDetails details = - service.subscribeToMessage(new SubscribeToMessage(msg.getClass().getName(), type, mode, client)); + public Integer attachToService(IMsgToolServiceClient client) throws Exception { + InetSocketAddress address = client.getAddressByType(msg.getClass().getName(), type); + SubscriptionDetails details; + if(address == null){ + details = null; + } else { + details = MessageServiceSupport.subscribeToMessage(new SubscribeToMessage(msg.getClass().getName(), type, mode, + client.getAddressByType(msg.getClass().getName(), type), client.getTestSessionKey())); + } if (details == null) { supported = false; return null; } supported = true; msg.setData(details.getCurrentData()); - this.service = service; + connected = true; serverSubscriptionKey = details.getKey(); return serverSubscriptionKey.getId(); } - public void detachService(IRemoteMessageService service, IMsgToolServiceClient client) throws Exception { - if (service != null && supported) { - service.unsubscribeToMessage(new UnSubscribeToMessage(msg.getClass().getName(), mode, type, + public void detachService(IMsgToolServiceClient client) throws Exception { + if (supported) { + MessageServiceSupport.unsubscribeToMessage(new UnSubscribeToMessage(msg.getClass().getName(), mode, type, client.getAddressByType(msg.getClass().getName(), type))); } - this.service = null; + connected = false; serverSubscriptionKey = null; } @@ -108,19 +114,16 @@ public class MessageInstance { public Set<DataType> getAvailableTypes() { HashSet<DataType> set = new HashSet<DataType>(); - if(service != null){ - try { - Set<? extends DataType> envSet = service.getAvailablePhysicalTypes(); - Set<DataType> available = msg.getAssociatedMessages().keySet(); - for(DataType type : available.toArray(new DataType[available.size()])){ - if(envSet.contains(type)){ - set.add(type); - } - } - } catch (RemoteException e) { - } - } - return set; + if(connected){ + Set<? extends DataType> envSet = MessageServiceSupport.getAvailablePhysicalTypes(); + Set<DataType> available = msg.getAssociatedMessages().keySet(); + for(DataType type : available.toArray(new DataType[available.size()])){ + if(envSet.contains(type)){ + set.add(type); + } + } + } + return set; } public boolean isSupported() { diff --git a/plugins/org.eclipse.osee.ote.client.msg/src/org/eclipse/osee/ote/client/msg/core/internal/MessageDatabase.java b/plugins/org.eclipse.osee.ote.client.msg/src/org/eclipse/osee/ote/client/msg/core/internal/MessageDatabase.java index ccf93f3bece..54aacc4fb49 100644 --- a/plugins/org.eclipse.osee.ote.client.msg/src/org/eclipse/osee/ote/client/msg/core/internal/MessageDatabase.java +++ b/plugins/org.eclipse.osee.ote.client.msg/src/org/eclipse/osee/ote/client/msg/core/internal/MessageDatabase.java @@ -20,6 +20,7 @@ import org.eclipse.osee.ote.client.msg.core.db.MessageInstance; import org.eclipse.osee.ote.message.Message; import org.eclipse.osee.ote.message.data.MessageData; import org.eclipse.osee.ote.message.enums.DataType; +import org.eclipse.osee.ote.message.interfaces.IMsgToolServiceClient; import org.eclipse.osee.ote.message.tool.MessageMode; /** @@ -27,7 +28,8 @@ import org.eclipse.osee.ote.message.tool.MessageMode; */ public class MessageDatabase extends AbstractMessageDataBase { - public MessageDatabase() { + public MessageDatabase(IMsgToolServiceClient service) { + super(service); } @Override diff --git a/plugins/org.eclipse.osee.ote.client.msg/src/org/eclipse/osee/ote/client/msg/core/internal/MessageServiceSupport.java b/plugins/org.eclipse.osee.ote.client.msg/src/org/eclipse/osee/ote/client/msg/core/internal/MessageServiceSupport.java new file mode 100644 index 00000000000..d1dd1d7a9af --- /dev/null +++ b/plugins/org.eclipse.osee.ote.client.msg/src/org/eclipse/osee/ote/client/msg/core/internal/MessageServiceSupport.java @@ -0,0 +1,153 @@ +package org.eclipse.osee.ote.client.msg.core.internal; + +import java.io.IOException; +import java.net.InetSocketAddress; +import java.net.UnknownHostException; +import java.util.Set; + +import org.eclipse.osee.ote.OTEException; +import org.eclipse.osee.ote.core.ServiceUtility; +import org.eclipse.osee.ote.message.commands.RecordCommand; +import org.eclipse.osee.ote.message.commands.SetElementValue; +import org.eclipse.osee.ote.message.commands.SubscribeToMessage; +import org.eclipse.osee.ote.message.commands.UnSubscribeToMessage; +import org.eclipse.osee.ote.message.commands.ZeroizeElement; +import org.eclipse.osee.ote.message.enums.DataType; +import org.eclipse.osee.ote.message.event.OteEventMessageUtil; +import org.eclipse.osee.ote.message.event.send.OteSendEventMessage; +import org.eclipse.osee.ote.message.tool.SubscriptionDetails; +import org.eclipse.osee.ote.remote.messages.AVAILABLE_PHYSICAL_TYPES_REQ; +import org.eclipse.osee.ote.remote.messages.GET_INET_ADDRESS_REQ; +import org.eclipse.osee.ote.remote.messages.GET_INET_ADDRESS_RESP; +import org.eclipse.osee.ote.remote.messages.SOCKET_ID; +import org.eclipse.osee.ote.remote.messages.STOP_RECORDING_CMD; +import org.eclipse.osee.ote.remote.messages.SerializedAvailablePhysicalTypesMessage; +import org.eclipse.osee.ote.remote.messages.SerializedRecordCommandMessage; +import org.eclipse.osee.ote.remote.messages.SerializedSetElementMessage; +import org.eclipse.osee.ote.remote.messages.SerializedSubscribeToMessage; +import org.eclipse.osee.ote.remote.messages.SerializedSubscriptionDetailsMessage; +import org.eclipse.osee.ote.remote.messages.SerializedUnSubscribeMessage; +import org.eclipse.osee.ote.remote.messages.SerializedZeroizeElementMessage; +import org.osgi.service.event.EventAdmin; + +public class MessageServiceSupport { + + private static EventAdmin admin; + private static OteSendEventMessage send; + + private static EventAdmin getEventAdmin(){ + if(admin == null){ + admin = ServiceUtility.getService(EventAdmin.class); + } + return admin; + } + + private static OteSendEventMessage get(){ + if(send == null){ + send = new OteSendEventMessage(getEventAdmin()); + } + return send; + } + + + public static SubscriptionDetails subscribeToMessage(SubscribeToMessage subscribeToMessage) { + SerializedSubscriptionDetailsMessage resp = new SerializedSubscriptionDetailsMessage(); + try{ + SerializedSubscribeToMessage cmd = new SerializedSubscribeToMessage(subscribeToMessage); + resp = get().synchSendAndResponse(resp, cmd, 10000); + if(resp == null){ + throw new OTEException("Timed out waiting for message response"); + } + SubscriptionDetails details = resp.getObject(); + return details; + } catch (IOException ex){ + throw new OTEException("Serialization Error", ex); + } catch (ClassNotFoundException e) { + throw new OTEException("Serialization Error", e); + } + } + + public static void unsubscribeToMessage(UnSubscribeToMessage unSubscribeToMessage) { + SerializedUnSubscribeMessage cmd; + try { + cmd = new SerializedUnSubscribeMessage(unSubscribeToMessage); + OteEventMessageUtil.postEvent(cmd); + } catch (IOException e) { + throw new OTEException("Serialization Error", e); + } + } + + public static Set<? extends DataType> getAvailablePhysicalTypes() throws OTEException { + AVAILABLE_PHYSICAL_TYPES_REQ req = new AVAILABLE_PHYSICAL_TYPES_REQ(); + try{ + SerializedAvailablePhysicalTypesMessage types = new SerializedAvailablePhysicalTypesMessage(); + types = get().synchSendAndResponse(types, req, 10000); + if(types == null){ + throw new OTEException("Timed out waiting for message response"); + } + return types.getObject(); + } catch (IOException ex){ + throw new OTEException("Serialization Error", ex); + } catch (ClassNotFoundException e) { + throw new OTEException("Serialization Error", e); + } + } + + public static InetSocketAddress getMsgUpdateSocketAddress() throws OTEException { + return getCommonAddress(SOCKET_ID.MSG_UPDATES); + } + + public static InetSocketAddress getRecorderSocketAddress() throws OTEException { + return getCommonAddress(SOCKET_ID.RECORDER); + } + + private static InetSocketAddress getCommonAddress(SOCKET_ID id){ + GET_INET_ADDRESS_REQ req = new GET_INET_ADDRESS_REQ(); + req.SOCKET_ID.setValue(id); + GET_INET_ADDRESS_RESP resp = get().synchSendAndResponse(GET_INET_ADDRESS_RESP.class, GET_INET_ADDRESS_RESP.TOPIC, req, 10000);//todo retry? + InetSocketAddress address; + if(resp == null){ + throw new OTEException("Timed out waiting for message response"); + } else { + try { + address = new InetSocketAddress(resp.ADDRESS.getAddress(), resp.ADDRESS.getPort()); + } catch (UnknownHostException e) { + throw new OTEException(e); + } + } + return address; + } + + public static void startRecording(RecordCommand cmd) { + try { + SerializedRecordCommandMessage msg = new SerializedRecordCommandMessage(cmd); + OteEventMessageUtil.postEvent(msg); + } catch (IOException e) { + throw new OTEException("Error starting recording", e); + } + } + + public static void stopRecording() { + STOP_RECORDING_CMD cmd = new STOP_RECORDING_CMD(); + OteEventMessageUtil.postEvent(cmd); + } + + public static void setElementValue(SetElementValue cmd) { + try { + SerializedSetElementMessage msg = new SerializedSetElementMessage(cmd); + OteEventMessageUtil.postEvent(msg); + } catch (IOException e) { + throw new OTEException(e); + } + } + + public static void zeroizeElement(ZeroizeElement cmd) { + try { + SerializedZeroizeElementMessage msg = new SerializedZeroizeElementMessage(cmd); + OteEventMessageUtil.postEvent(msg); + } catch (IOException e) { + throw new OTEException(e); + } + } + +} diff --git a/plugins/org.eclipse.osee.ote.client.msg/src/org/eclipse/osee/ote/client/msg/core/internal/MessageSubscription.java b/plugins/org.eclipse.osee.ote.client.msg/src/org/eclipse/osee/ote/client/msg/core/internal/MessageSubscription.java index eb51401c93b..07c849fabd9 100644 --- a/plugins/org.eclipse.osee.ote.client.msg/src/org/eclipse/osee/ote/client/msg/core/internal/MessageSubscription.java +++ b/plugins/org.eclipse.osee.ote.client.msg/src/org/eclipse/osee/ote/client/msg/core/internal/MessageSubscription.java @@ -23,7 +23,6 @@ import org.eclipse.osee.ote.message.Message; import org.eclipse.osee.ote.message.commands.SetElementValue; import org.eclipse.osee.ote.message.commands.ZeroizeElement; import org.eclipse.osee.ote.message.enums.DataType; -import org.eclipse.osee.ote.message.interfaces.IRemoteMessageService; import org.eclipse.osee.ote.message.tool.MessageMode; /** @@ -96,11 +95,11 @@ public class MessageSubscription implements IMessageSubscription { currentState = currentState.onMessageDbClosing(msgDb); } - public synchronized void attachService(IRemoteMessageService service) { + public synchronized void attachService() { currentState = currentState.onActivated(); } - public synchronized void detachService(IRemoteMessageService service) { + public synchronized void detachService() { currentState = currentState.onDeactivated(); } @@ -157,8 +156,8 @@ public class MessageSubscription implements IMessageSubscription { private void progressState() { if (msgService.getMsgDatabase() != null) { attachMessageDb(msgService.getMsgDatabase()); - if (msgService.getService() != null) { - attachService(msgService.getService()); + if(msgService.isConnected()){ + attachService(); } } } @@ -166,26 +165,26 @@ public class MessageSubscription implements IMessageSubscription { @Override public void setElementValue(List<Object> path, String value) throws Exception { final SetElementValue cmd = new SetElementValue(getMessageClassName(), getMemType(), path, value, true); - msgService.getService().setElementValue(cmd); + MessageServiceSupport.setElementValue(cmd); } @Override public void setElementValueNoSend(List<Object> path, String value) throws Exception { final SetElementValue cmd = new SetElementValue(getMessageClassName(), getMemType(), path, value, false); - msgService.getService().setElementValue(cmd); + MessageServiceSupport.setElementValue(cmd); } @Override public void send() throws Exception { final SetElementValue cmd = new SetElementValue(getMessageClassName(), getMemType(), null, null, true); - msgService.getService().setElementValue(cmd); + MessageServiceSupport.setElementValue(cmd); } @Override public void zeroize(List<Object> path) throws Exception { final ZeroizeElement cmd = new ZeroizeElement(getMessageClassName(), getMemType(), path); - msgService.getService().zeroizeElement(cmd); + MessageServiceSupport.zeroizeElement(cmd); } public void notifyCanceled() { diff --git a/plugins/org.eclipse.osee.ote.client.msg/src/org/eclipse/osee/ote/client/msg/core/internal/MessageSubscriptionService.java b/plugins/org.eclipse.osee.ote.client.msg/src/org/eclipse/osee/ote/client/msg/core/internal/MessageSubscriptionService.java index c440a74074f..3871ac0ec96 100644 --- a/plugins/org.eclipse.osee.ote.client.msg/src/org/eclipse/osee/ote/client/msg/core/internal/MessageSubscriptionService.java +++ b/plugins/org.eclipse.osee.ote.client.msg/src/org/eclipse/osee/ote/client/msg/core/internal/MessageSubscriptionService.java @@ -39,7 +39,6 @@ import org.eclipse.osee.ote.message.commands.RecordCommand; import org.eclipse.osee.ote.message.commands.RecordCommand.MessageRecordDetails; import org.eclipse.osee.ote.message.enums.DataType; import org.eclipse.osee.ote.message.interfaces.IMsgToolServiceClient; -import org.eclipse.osee.ote.message.interfaces.IRemoteMessageService; import org.eclipse.osee.ote.message.interfaces.ITestEnvironmentMessageSystem; import org.eclipse.osee.ote.message.tool.IFileTransferHandle; import org.eclipse.osee.ote.message.tool.MessageMode; @@ -61,9 +60,9 @@ public class MessageSubscriptionService implements IOteMessageService, ITestConn private final InetAddress localAddress; private final List<MessageSubscription> subscriptions = new CopyOnWriteArrayList<MessageSubscription>(); - private IMsgToolServiceClient exportedThis = null; private volatile AbstractMessageDataBase msgDatabase; private UdpFileTransferHandler fileTransferHandler; + private volatile boolean connected = false; private final ExecutorService threadPool = Executors.newFixedThreadPool(MAX_CONCURRENT_WORKER_THREADS, new ThreadFactory() { @@ -83,7 +82,7 @@ public class MessageSubscriptionService implements IOteMessageService, ITestConn * Monitors a set of channels for message updates and dispatches the updates to worker threads */ private UpdateDispatcher dispatcher = null; - private volatile IRemoteMessageService service; +// private volatile IRemoteMessageService service; private volatile IOteClientService clientService; @@ -105,7 +104,7 @@ public class MessageSubscriptionService implements IOteMessageService, ITestConn public MessageSubscriptionService() throws IOException { localAddress = InetAddress.getLocalHost(); - msgDatabase = new MessageDatabase(); + msgDatabase = new MessageDatabase(this); OseeLog.log(Activator.class, Level.INFO, "OTE client message service started on: " + localAddress.getHostAddress()); } @@ -116,8 +115,8 @@ public class MessageSubscriptionService implements IOteMessageService, ITestConn subscription.bind(name); if (msgDatabase != null) { subscription.attachMessageDb(msgDatabase); - if (service != null) { - subscription.attachService(service); + if(connected){ + subscription.attachService(); } } subscriptions.add(subscription); @@ -136,8 +135,8 @@ public class MessageSubscriptionService implements IOteMessageService, ITestConn subscription.bind(name, dataType, mode); if (msgDatabase != null) { subscription.attachMessageDb(msgDatabase); - if (service != null) { - subscription.attachService(service); + if(connected){ + subscription.attachService(); } } subscriptions.add(subscription); @@ -151,8 +150,8 @@ public class MessageSubscriptionService implements IOteMessageService, ITestConn subscription.bind(name, dataType, mode); if (msgDatabase != null) { subscription.attachMessageDb(msgDatabase); - if (service != null) { - subscription.attachService(service); + if(connected) { + subscription.attachService(); } } subscriptions.add(subscription); @@ -178,65 +177,42 @@ public class MessageSubscriptionService implements IOteMessageService, ITestConn public synchronized void onConnectionLost(IServiceConnector connector) { OseeLog.log(Activator.class, Level.INFO, "connection lost: ote client message service halted"); shutdownDispatcher(); - msgDatabase.detachService(null); + msgDatabase.detachService(); for (MessageSubscription subscription : subscriptions) { - subscription.detachService(null); + subscription.detachService(); } - exportedThis = null; - service = null; + connected = false; } @Override public synchronized void onPostConnect(ConnectionEvent event) { assert msgDatabase != null; + connected = true; OseeLog.log(Activator.class, Level.INFO, "connecting OTE client message service"); if (event.getEnvironment() instanceof ITestEnvironmentMessageSystem) { ITestEnvironmentMessageSystem env = (ITestEnvironmentMessageSystem) event.getEnvironment(); - try { - service = env.getMessageToolServiceProxy(); - if (service == null) { - throw new Exception("could not get message tool service proxy"); + try{ + dispatcher = new UpdateDispatcher(MessageServiceSupport.getMsgUpdateSocketAddress()); + try { + createProccessors(); + } catch (Exception e) { + OseeLog.log(MessageSubscriptionService.class, Level.SEVERE, "failed to create update processors", e); + return; } - exportedThis = (IMsgToolServiceClient) event.getConnector().export(this); - } catch (Exception e) { - String message = String.format( - "failed to create exported Message Tool Client. Connector class is %s", - event.getConnector().getClass().getName()); - OseeLog.log(MessageSubscriptionService.class, Level.SEVERE, - message, e); - service = null; - exportedThis = null; - return; - } - - try { - dispatcher = new UpdateDispatcher(service.getMsgUpdateSocketAddress()); - } catch (Exception e) { - OseeLog.log(MessageSubscriptionService.class, Level.SEVERE, "failed to create update dispatcher", e); - service = null; - exportedThis = null; - return; - } - try { - createProccessors(); - } catch (Exception e) { - OseeLog.log(MessageSubscriptionService.class, Level.SEVERE, "failed to create update processors", e); - service = null; - exportedThis = null; - return; - } - - msgDatabase.attachToService(service, exportedThis); - for (MessageSubscription subscription : subscriptions) { - subscription.attachService(service); + msgDatabase.attachToService(this); + for (MessageSubscription subscription : subscriptions) { + subscription.attachService(); + } + dispatcher.start(); + } catch (IOException ex){ + OseeLog.log(MessageSubscriptionService.class, Level.SEVERE, "failed to create update processors", ex); } - dispatcher.start(); } } private void createProccessors() throws IOException { - Set<? extends DataType> availableTypes = service.getAvailablePhysicalTypes(); + Set<? extends DataType> availableTypes = MessageServiceSupport.getAvailablePhysicalTypes(); for (DataType type : availableTypes) { final ChannelProcessor handler = @@ -259,21 +235,12 @@ public class MessageSubscriptionService implements IOteMessageService, ITestConn @Override public synchronized void onPreDisconnect(ConnectionEvent event) { - if (service == null) { - return; - } - msgDatabase.detachService(service); + msgDatabase.detachService(); for (MessageSubscription subscription : subscriptions) { - subscription.detachService(service); - } - try { - event.getConnector().unexport(this); - } catch (Exception e) { - OseeLog.log(MessageSubscriptionService.class, Level.WARNING, "problems unexporting Message Tool Client", e); + subscription.detachService(); } shutdownDispatcher(); - exportedThis = null; - service = null; + connected = false; } @Override @@ -288,11 +255,13 @@ public class MessageSubscriptionService implements IOteMessageService, ITestConn @Override public InetSocketAddress getAddressByType(String messageName, DataType dataType) throws RemoteException { + if(dispatcher == null){ + return null; + } final DatagramChannel channel = dispatcher.getChannel(dataType); - OseeLog.logf(Activator.class, Level.INFO, - "callback from remote msg manager: msg=%s, type=%s, ip=%s:%d\n", messageName, dataType.name(), - localAddress.toString(), channel.socket().getLocalPort()); - + if(channel == null){ + return null; + } return new InetSocketAddress(localAddress, channel.socket().getLocalPort()); } @@ -329,7 +298,7 @@ public class MessageSubscriptionService implements IOteMessageService, ITestConn @Override public synchronized IFileTransferHandle startRecording(String fileName, List<MessageRecordDetails> list) throws FileNotFoundException, IOException { - if (service == null) { + if(!connected){ throw new IllegalStateException("can't record: not connected to test server"); } if (fileTransferHandler == null) { @@ -339,7 +308,7 @@ public class MessageSubscriptionService implements IOteMessageService, ITestConn int port = PortUtil.getInstance().getValidPort(); // get the address of the socket the message recorder is going to write // data to - InetSocketAddress recorderOutputAddress = service.getRecorderSocketAddress(); + InetSocketAddress recorderOutputAddress = MessageServiceSupport.getRecorderSocketAddress(); // setup a transfer from a socket to a file TransferConfig config = @@ -349,8 +318,8 @@ public class MessageSubscriptionService implements IOteMessageService, ITestConn // send the command to start recording RecordCommand cmd = - new RecordCommand(exportedThis, new InetSocketAddress(InetAddress.getLocalHost(), port), list); - service.startRecording(cmd); + new RecordCommand(this.getTestSessionKey(), new InetSocketAddress(InetAddress.getLocalHost(), port), list); + MessageServiceSupport.startRecording(cmd); OseeLog.log( Activator.class, Level.INFO, @@ -361,7 +330,7 @@ public class MessageSubscriptionService implements IOteMessageService, ITestConn @Override public synchronized void stopRecording() throws RemoteException, IOException { try { - service.stopRecording(); + MessageServiceSupport.stopRecording(); } finally { if (fileTransferHandler != null && fileTransferHandler.hasActiveTransfers()) { fileTransferHandler.stopAllTransfers(); @@ -374,12 +343,12 @@ public class MessageSubscriptionService implements IOteMessageService, ITestConn return msgDatabase; } - public IRemoteMessageService getService() { - return service; - } - public void removeSubscription(MessageSubscription subscription) { subscriptions.remove(subscription); } + public boolean isConnected() { + return connected; + } + } diff --git a/plugins/org.eclipse.osee.ote.client.msg/src/org/eclipse/osee/ote/client/msg/core/internal/state/InactiveState.java b/plugins/org.eclipse.osee.ote.client.msg/src/org/eclipse/osee/ote/client/msg/core/internal/state/InactiveState.java index c41eef37b34..4f87f6dee8b 100644 --- a/plugins/org.eclipse.osee.ote.client.msg/src/org/eclipse/osee/ote/client/msg/core/internal/state/InactiveState.java +++ b/plugins/org.eclipse.osee.ote.client.msg/src/org/eclipse/osee/ote/client/msg/core/internal/state/InactiveState.java @@ -13,6 +13,7 @@ package org.eclipse.osee.ote.client.msg.core.internal.state; import java.util.HashSet; import java.util.Set; import java.util.logging.Level; + import org.eclipse.osee.framework.logging.OseeLog; import org.eclipse.osee.ote.client.msg.core.db.AbstractMessageDataBase; import org.eclipse.osee.ote.client.msg.core.db.MessageInstance; |