From 27c2635ce298f093046feb764ed173e999561e7b Mon Sep 17 00:00:00 2001 From: James Korman Date: Wed, 4 Apr 2012 13:41:25 -0500 Subject: [PATCH] Issue #437 - Corrected venue command message loopback Former-commit-id: 23a2cd033a8d45068e3607890bfa6ef469b7e4b9 [formerly 23a2cd033a8d45068e3607890bfa6ef469b7e4b9 [formerly c3ba8bd9416f18358f2a976ee2104e4e614321c3]] Former-commit-id: e663a9e5dca1fd23bdf60cb16c6445f485574ac3 Former-commit-id: 44b07395fb3cd9f456cac3ea39d1468c8d2664c1 --- .../comm/provider/session/BaseSession.java | 51 ++++++++++++------- .../session/PeerToPeerCommHelper.java | 7 --- .../comm/provider/session/SessionManager.java | 14 ++++- .../comm/provider/session/VenueSession.java | 39 ++++++++++++-- 4 files changed, 80 insertions(+), 31 deletions(-) diff --git a/cave/com.raytheon.uf.viz.collaboration/src/com/raytheon/uf/viz/collaboration/comm/provider/session/BaseSession.java b/cave/com.raytheon.uf.viz.collaboration/src/com/raytheon/uf/viz/collaboration/comm/provider/session/BaseSession.java index e58071717b..eada16283e 100644 --- a/cave/com.raytheon.uf.viz.collaboration/src/com/raytheon/uf/viz/collaboration/comm/provider/session/BaseSession.java +++ b/cave/com.raytheon.uf.viz.collaboration/src/com/raytheon/uf/viz/collaboration/comm/provider/session/BaseSession.java @@ -149,6 +149,40 @@ public abstract class BaseSession implements ISession { return connectionPresence; } + /** + * + * @return + */ + EventBus getManagerEventPublisher() { + return managerEventBus; + } + + /** + * + * @return + */ + SessionManager getSessionManager() { + return sessionManager; + } + + /** + * + * @param name + * @return + */ + public ID createID(String name) throws IDCreateException { + ID id = null; + name += "/foo"; // TODO fix this in a better way + if (connectionNamespace != null) { + id = IDFactory.getDefault().createID(connectionNamespace, name); + } + return id; + } + + // ***************** + // Implement IEventPublisher methods + // ***************** + /** * @see com.raytheon.uf.viz.collaboration.comm.identity.ISession#getUserID() */ @@ -230,21 +264,4 @@ public abstract class BaseSession implements ISession { return eventBus; } - EventBus getManagerEventPublisher() { - return managerEventBus; - } - - /** - * - * @param name - * @return - */ - public ID createID(String name) throws IDCreateException { - ID id = null; - name += "/foo"; // TODO fix this in a better way - if (connectionNamespace != null) { - id = IDFactory.getDefault().createID(connectionNamespace, name); - } - return id; - } } diff --git a/cave/com.raytheon.uf.viz.collaboration/src/com/raytheon/uf/viz/collaboration/comm/provider/session/PeerToPeerCommHelper.java b/cave/com.raytheon.uf.viz.collaboration/src/com/raytheon/uf/viz/collaboration/comm/provider/session/PeerToPeerCommHelper.java index 5888d95131..60d6ae063b 100644 --- a/cave/com.raytheon.uf.viz.collaboration/src/com/raytheon/uf/viz/collaboration/comm/provider/session/PeerToPeerCommHelper.java +++ b/cave/com.raytheon.uf.viz.collaboration/src/com/raytheon/uf/viz/collaboration/comm/provider/session/PeerToPeerCommHelper.java @@ -76,9 +76,6 @@ public class PeerToPeerCommHelper implements IIMMessageListener { @Override public void handleMessageEvent(IIMMessageEvent messageEvent) { - System.out.println("Handling event " - + messageEvent.getClass().getName()); - if (messageEvent instanceof IChatMessageEvent) { IChatMessageEvent event = (IChatMessageEvent) messageEvent; System.out.println(" message event.body " @@ -95,10 +92,6 @@ public class PeerToPeerCommHelper implements IIMMessageListener { routeMessage(msg); } } - } else { - if(messageEvent != null) { - System.out.println(messageEvent.getClass().getName() + " trapped in PeerToPeerCommHelper"); - } } } diff --git a/cave/com.raytheon.uf.viz.collaboration/src/com/raytheon/uf/viz/collaboration/comm/provider/session/SessionManager.java b/cave/com.raytheon.uf.viz.collaboration/src/com/raytheon/uf/viz/collaboration/comm/provider/session/SessionManager.java index 9e81a4803a..4ec65dd6db 100644 --- a/cave/com.raytheon.uf.viz.collaboration/src/com/raytheon/uf/viz/collaboration/comm/provider/session/SessionManager.java +++ b/cave/com.raytheon.uf.viz.collaboration/src/com/raytheon/uf/viz/collaboration/comm/provider/session/SessionManager.java @@ -217,6 +217,14 @@ public class SessionManager implements IEventPublisher { } } + /** + * Return the account string that was used to create this manager. + * @return The account string. + */ + public String getAccount() { + return account; + } + /** * Get the account manager for this connection. * @@ -353,8 +361,10 @@ public class SessionManager implements IEventPublisher { if (session != null) { session.createVenue(venueName, subject); - IChatID me = new VenueUserId("jkorman", - "awipscm.omaha.us.ray.com"); + String name = Tools.parseName(account); + String host = Tools.parseHost(account); + + IChatID me = new VenueUserId(name, host); session.setSessionLeader(me); session.setSessionDataProvider(me); diff --git a/cave/com.raytheon.uf.viz.collaboration/src/com/raytheon/uf/viz/collaboration/comm/provider/session/VenueSession.java b/cave/com.raytheon.uf.viz.collaboration/src/com/raytheon/uf/viz/collaboration/comm/provider/session/VenueSession.java index 9795119e73..eb64535d38 100644 --- a/cave/com.raytheon.uf.viz.collaboration/src/com/raytheon/uf/viz/collaboration/comm/provider/session/VenueSession.java +++ b/cave/com.raytheon.uf.viz.collaboration/src/com/raytheon/uf/viz/collaboration/comm/provider/session/VenueSession.java @@ -149,7 +149,6 @@ public class VenueSession extends BaseSession implements IVenueSession, VenueSession(IContainer container, EventBus externalBus, SessionManager manager) throws CollaborationException { super(container, externalBus, manager); - } /** @@ -352,10 +351,10 @@ public class VenueSession extends BaseSession implements IVenueSession, if (session != null) { String message = Tools.marshallData(initData); if (message != null) { - + TextMessage msg = new TextMessage(participant, message); msg.setProperty(Tools.PROP_SESSION_ID, getSessionId()); - + session.sendPeerToPeer(msg); } } @@ -414,7 +413,7 @@ public class VenueSession extends BaseSession implements IVenueSession, if (session != null) { String message = Tools.marshallData(event); if (message != null) { - + TextMessage msg = new TextMessage(participant, message); msg.setProperty(Tools.PROP_SESSION_ID, getSessionId()); session.sendPeerToPeer(msg); @@ -659,7 +658,9 @@ public class VenueSession extends BaseSession implements IVenueSession, IChatRoomMessage m = ((IChatRoomMessageEvent) messageEvent) .getChatRoomMessage(); - distributeMessage(convertMessage(m)); + if (accept(m)) { + distributeMessage(convertMessage(m)); + } } } }; @@ -673,6 +674,34 @@ public class VenueSession extends BaseSession implements IVenueSession, return errorStatus; } + /** + * Examine the incoming message to determine if it should be forwarded. The + * method looks at the from identifier to determine who sent the message. + * + * @param message + * A message to accept. + * @return Should the message be accepted. + */ + private boolean accept(IChatRoomMessage message) { + boolean acceptMessage = true; + + String body = message.getMessage(); + // Command data only + if (body.startsWith(SEND_CMD)) { + ID from = message.getFromID(); + + String name = Tools.parseName(from.getName()); + String host = Tools.parseHost(from.getName()); + + String account = getSessionManager().getAccount(); + String aName = Tools.parseName(account); + if (aName.equals(name)) { + acceptMessage = false; + } + } + return acceptMessage; + } + /** * * @param message