Issue #427 minor fixes

Change-Id: I9788992b2de751f75ab2cc5112f2cf0492c214ad

Former-commit-id: 0f25c8ffa6 [formerly fa8b5b3400 [formerly 40e9906f41f0fa2ae4c87d3c2a2acb2406fd4e25]]
Former-commit-id: fa8b5b3400
Former-commit-id: ab63accc61
This commit is contained in:
Nate Jensen 2012-03-27 09:56:46 -05:00
parent 2132a997ca
commit 1952d1fbfe
2 changed files with 92 additions and 77 deletions

View file

@ -27,11 +27,8 @@ import java.util.Map;
import org.eclipse.ecf.core.IContainer; import org.eclipse.ecf.core.IContainer;
import org.eclipse.ecf.core.identity.ID; import org.eclipse.ecf.core.identity.ID;
import org.eclipse.ecf.core.identity.IDCreateException;
import org.eclipse.ecf.core.identity.IDFactory;
import org.eclipse.ecf.core.identity.Namespace; import org.eclipse.ecf.core.identity.Namespace;
import org.eclipse.ecf.core.util.ECFException; import org.eclipse.ecf.core.util.ECFException;
import org.eclipse.ecf.presence.IPresenceContainerAdapter;
import org.eclipse.ecf.presence.im.IChatMessage; import org.eclipse.ecf.presence.im.IChatMessage;
import org.eclipse.ecf.presence.im.IChatMessageSender; import org.eclipse.ecf.presence.im.IChatMessageSender;
@ -52,46 +49,47 @@ import com.raytheon.uf.viz.collaboration.comm.provider.Errors;
* Only one instance of this class should be created. * Only one instance of this class should be created.
* *
* <pre> * <pre>
* *
* SOFTWARE HISTORY * SOFTWARE HISTORY
* *
* Date Ticket# Engineer Description * Date Ticket# Engineer Description
* ------------ ---------- ----------- -------------------------- * ------------ ---------- ----------- --------------------------
* Mar 21, 2012 jkorman Initial creation * Mar 21, 2012 jkorman Initial creation
* *
* </pre> * </pre>
* *
* @author jkorman * @author jkorman
* @version 1.0 * @version 1.0
*/ */
public class PeerToPeerChat extends BaseSession implements IPeerToPeer, IEventPublisher { public class PeerToPeerChat extends BaseSession implements IPeerToPeer,
IEventPublisher {
/** /**
* *
* TODO Add Description * TODO Add Description
* *
* <pre> * <pre>
* *
* SOFTWARE HISTORY * SOFTWARE HISTORY
* *
* Date Ticket# Engineer Description * Date Ticket# Engineer Description
* ------------ ---------- ----------- -------------------------- * ------------ ---------- ----------- --------------------------
* Feb 27, 2012 jkorman Initial creation * Feb 27, 2012 jkorman Initial creation
* *
* </pre> * </pre>
* *
* @author jkorman * @author jkorman
* @version 1.0 * @version 1.0
*/ */
private static class InternalListener { private static class InternalListener {
private IMessageListener messageListener; private IMessageListener messageListener;
private IPresenceListener presenceListener; private IPresenceListener presenceListener;
private IMessageFilter filter; private IMessageFilter filter;
/** /**
* *
* @param listener * @param listener
@ -100,7 +98,7 @@ public class PeerToPeerChat extends BaseSession implements IPeerToPeer, IEventPu
public InternalListener(IMessageListener listener, IMessageFilter filter) { public InternalListener(IMessageListener listener, IMessageFilter filter) {
messageListener = listener; messageListener = listener;
this.filter = filter; this.filter = filter;
} }
/** /**
@ -108,7 +106,8 @@ public class PeerToPeerChat extends BaseSession implements IPeerToPeer, IEventPu
* @param listener * @param listener
* @param filter * @param filter
*/ */
public InternalListener(IPresenceListener listener, IMessageFilter filter) { public InternalListener(IPresenceListener listener,
IMessageFilter filter) {
presenceListener = listener; presenceListener = listener;
this.filter = filter; this.filter = filter;
} }
@ -142,7 +141,7 @@ public class PeerToPeerChat extends BaseSession implements IPeerToPeer, IEventPu
private List<InternalListener> messageListeners = null; private List<InternalListener> messageListeners = null;
private Namespace namespace = null; private Namespace namespace = null;
private IChatMessageSender chatSender = null; private IChatMessageSender chatSender = null;
/** /**
@ -151,11 +150,20 @@ public class PeerToPeerChat extends BaseSession implements IPeerToPeer, IEventPu
* @param externalBus * @param externalBus
* @param manager * @param manager
*/ */
PeerToPeerChat(IContainer container, EventBus externalBus, SessionManager manager) { PeerToPeerChat(IContainer container, EventBus externalBus,
SessionManager manager) {
super(container, externalBus, manager); super(container, externalBus, manager);
try {
setup();
} catch (ECFException e) {
// TODO
e.printStackTrace();
}
chatSender = getConnectionPresenceAdapter().getChatManager()
.getChatMessageSender();
} }
/** /**
* *
*/ */
@ -163,20 +171,21 @@ public class PeerToPeerChat extends BaseSession implements IPeerToPeer, IEventPu
public int sendPeerToPeer(IMessage message) { public int sendPeerToPeer(IMessage message) {
// Assume success // Assume success
int status = Errors.NO_ERROR; int status = Errors.NO_ERROR;
if(chatSender != null) { if (chatSender != null) {
ID toID = createID(message.getTo().getName()); ID toID = createID(message.getTo().getName());
String subject = message.getSubject(); String subject = message.getSubject();
String body = message.getBody(); String body = message.getBody();
Collection<Property> properties = message.getProperties(); Collection<Property> properties = message.getProperties();
Map<String, String> props = null; Map<String, String> props = null;
if((properties != null) && (properties.size() > 0)) { if ((properties != null) && (properties.size() > 0)) {
props = new HashMap<String, String>(); props = new HashMap<String, String>();
for(Property p : properties) { for (Property p : properties) {
props.put(p.getKey(),p.getValue()); props.put(p.getKey(), p.getValue());
} }
} }
try { try {
chatSender.sendChatMessage(toID, null, IChatMessage.Type.CHAT, subject, body, props); chatSender.sendChatMessage(toID, null, IChatMessage.Type.CHAT,
subject, body, props);
} catch (ECFException e) { } catch (ECFException e) {
System.out.println("Error sending message"); System.out.println("Error sending message");
e.printStackTrace(); e.printStackTrace();
@ -187,8 +196,11 @@ public class PeerToPeerChat extends BaseSession implements IPeerToPeer, IEventPu
/** /**
* Send a message to the named recipient. * Send a message to the named recipient.
* @param to The recipient of the message. *
* @param message The body of the message to send. * @param to
* The recipient of the message.
* @param message
* The body of the message to send.
*/ */
@Override @Override
public int sendPeerToPeer(String to, String message) { public int sendPeerToPeer(String to, String message) {
@ -201,7 +213,7 @@ public class PeerToPeerChat extends BaseSession implements IPeerToPeer, IEventPu
System.out.println("Error sending message"); System.out.println("Error sending message");
e.printStackTrace(); e.printStackTrace();
} }
return status; return status;
} }
@ -209,8 +221,10 @@ public class PeerToPeerChat extends BaseSession implements IPeerToPeer, IEventPu
* *
*/ */
@Override @Override
public IMessageListener addMessageListener(IMessageListener listener, IMessageFilter filter) { public IMessageListener addMessageListener(IMessageListener listener,
InternalListener messageListener = new InternalListener(listener, filter); IMessageFilter filter) {
InternalListener messageListener = new InternalListener(listener,
filter);
messageListeners.add(messageListener); messageListeners.add(messageListener);
return listener; return listener;
} }
@ -221,8 +235,8 @@ public class PeerToPeerChat extends BaseSession implements IPeerToPeer, IEventPu
@Override @Override
public Collection<IMessageListener> getMessageListeners() { public Collection<IMessageListener> getMessageListeners() {
Collection<IMessageListener> listeners = new ArrayList<IMessageListener>(); Collection<IMessageListener> listeners = new ArrayList<IMessageListener>();
synchronized(messageListeners) { synchronized (messageListeners) {
for(InternalListener intListener : messageListeners) { for (InternalListener intListener : messageListeners) {
listeners.add(intListener.messageListener); listeners.add(intListener.messageListener);
} }
} }
@ -235,11 +249,10 @@ public class PeerToPeerChat extends BaseSession implements IPeerToPeer, IEventPu
@Override @Override
public IMessageListener removeMessageListener(IMessageListener listener) { public IMessageListener removeMessageListener(IMessageListener listener) {
IMessageListener removed = null; IMessageListener removed = null;
if(messageListeners.remove(listener)) { if (messageListeners.remove(listener)) {
removed = listener; removed = listener;
} }
return removed; return removed;
} }
} }

View file

@ -44,7 +44,6 @@ import org.eclipse.ecf.presence.chatroom.IChatRoomParticipantListener;
import org.eclipse.ecf.provider.xmpp.identity.XMPPRoomID; import org.eclipse.ecf.provider.xmpp.identity.XMPPRoomID;
import com.google.common.eventbus.EventBus; import com.google.common.eventbus.EventBus;
import com.google.common.eventbus.Subscribe;
import com.raytheon.uf.viz.collaboration.comm.identity.CollaborationException; import com.raytheon.uf.viz.collaboration.comm.identity.CollaborationException;
import com.raytheon.uf.viz.collaboration.comm.identity.IMessage; import com.raytheon.uf.viz.collaboration.comm.identity.IMessage;
import com.raytheon.uf.viz.collaboration.comm.identity.IPresence; import com.raytheon.uf.viz.collaboration.comm.identity.IPresence;
@ -225,46 +224,48 @@ public class VenueSession extends BaseSession implements IVenueSession,
} finally { } finally {
initListeners(); initListeners();
} }
// Runnable r = new Runnable() { // Runnable r = new Runnable() {
// @Override // @Override
// public void run() { // public void run() {
// try { // try {
// Thread.sleep(20000); // Thread.sleep(20000);
// //
// TestJAXBObject j = new TestJAXBObject(); // TestJAXBObject j = new TestJAXBObject();
// j.setItem_1("This is an object"); // j.setItem_1("This is an object");
// j.setValue(5); // j.setValue(5);
// sendRenderableObject(j); // sendRenderableObject(j);
// } catch (Exception e) { // } catch (Exception e) {
// System.out.println("Error sending RenderableObject"); // System.out.println("Error sending RenderableObject");
// } // }
// } // }
// }; // };
// Thread t = new Thread(r); // Thread t = new Thread(r);
// t.start(); // t.start();
// registerEventHandler(this); // registerEventHandler(this);
} }
// @Subscribe // @Subscribe
// public void handle(IRenderable renderable) { // public void handle(IRenderable renderable) {
// System.out.println("Renderable found"); // System.out.println("Renderable found");
// if(renderable instanceof TestJAXBObject) { // if(renderable instanceof TestJAXBObject) {
// TestJAXBObject j = (TestJAXBObject) renderable; // TestJAXBObject j = (TestJAXBObject) renderable;
// if(j.getValue() < 100) { // if(j.getValue() < 100) {
// System.out.println(String.format("%s %d Renderable", j.getItem_1(), j.getValue())); // System.out.println(String.format("%s %d Renderable", j.getItem_1(),
// j.setValue(j.getValue() + 200); // j.getValue()));
// j.setItem_1("Now for the return trip"); // j.setValue(j.getValue() + 200);
// try { // j.setItem_1("Now for the return trip");
// sendRenderableObject(j); // try {
// } catch (CollaborationException ce) { // sendRenderableObject(j);
// System.out.println("Error sending RenderableObject"); // } catch (CollaborationException ce) {
// } // System.out.println("Error sending RenderableObject");
// } else { // }
// System.out.println(String.format("%s %d Renderable", j.getItem_1(), j.getValue())); // } else {
// } // System.out.println(String.format("%s %d Renderable", j.getItem_1(),
// } // j.getValue()));
// } // }
// }
// }
/** /**
* *
* @throws ECFException * @throws ECFException
@ -617,7 +618,8 @@ public class VenueSession extends BaseSession implements IVenueSession,
* @param participant * @param participant
* @param initData * @param initData
* @throws CollaborationException * @throws CollaborationException
* @see com.raytheon.uf.viz.collaboration.comm.identity.ISharedDisplaySession#sendInitData(com.raytheon.uf.viz.collaboration.comm.identity.user.IChatID, com.raytheon.uf.viz.collaboration.comm.identity.event.IInitData) * @see com.raytheon.uf.viz.collaboration.comm.identity.ISharedDisplaySession#sendInitData(com.raytheon.uf.viz.collaboration.comm.identity.user.IChatID,
* com.raytheon.uf.viz.collaboration.comm.identity.event.IInitData)
*/ */
@Override @Override
public void sendInitData( public void sendInitData(
@ -629,7 +631,7 @@ public class VenueSession extends BaseSession implements IVenueSession,
if (session != null) { if (session != null) {
String message = Tools.marshallData(initData); String message = Tools.marshallData(initData);
if (message != null) { if (message != null) {
session.sendPeerToPeer(participant.getFQName(), message); session.sendPeerToPeer(participant.getName(), message);
} }
} }
} }