Issue #427 minor fixes
Change-Id: I9788992b2de751f75ab2cc5112f2cf0492c214ad Former-commit-id:fa8b5b3400
[formerly 40e9906f41f0fa2ae4c87d3c2a2acb2406fd4e25] Former-commit-id:0f25c8ffa6
This commit is contained in:
parent
9602216cda
commit
a692caba1c
2 changed files with 92 additions and 77 deletions
|
@ -27,11 +27,8 @@ import java.util.Map;
|
|||
|
||||
import org.eclipse.ecf.core.IContainer;
|
||||
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.util.ECFException;
|
||||
import org.eclipse.ecf.presence.IPresenceContainerAdapter;
|
||||
import org.eclipse.ecf.presence.im.IChatMessage;
|
||||
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.
|
||||
*
|
||||
* <pre>
|
||||
*
|
||||
*
|
||||
* SOFTWARE HISTORY
|
||||
*
|
||||
*
|
||||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* Mar 21, 2012 jkorman Initial creation
|
||||
*
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
*
|
||||
* @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
|
||||
*
|
||||
* <pre>
|
||||
*
|
||||
*
|
||||
* SOFTWARE HISTORY
|
||||
*
|
||||
*
|
||||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* Feb 27, 2012 jkorman Initial creation
|
||||
*
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
*
|
||||
* @author jkorman
|
||||
* @version 1.0
|
||||
*/
|
||||
private static class InternalListener {
|
||||
|
||||
|
||||
private IMessageListener messageListener;
|
||||
|
||||
|
||||
private IPresenceListener presenceListener;
|
||||
|
||||
private IMessageFilter filter;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param listener
|
||||
|
@ -100,7 +98,7 @@ public class PeerToPeerChat extends BaseSession implements IPeerToPeer, IEventPu
|
|||
public InternalListener(IMessageListener listener, IMessageFilter filter) {
|
||||
messageListener = listener;
|
||||
this.filter = filter;
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -108,7 +106,8 @@ public class PeerToPeerChat extends BaseSession implements IPeerToPeer, IEventPu
|
|||
* @param listener
|
||||
* @param filter
|
||||
*/
|
||||
public InternalListener(IPresenceListener listener, IMessageFilter filter) {
|
||||
public InternalListener(IPresenceListener listener,
|
||||
IMessageFilter filter) {
|
||||
presenceListener = listener;
|
||||
this.filter = filter;
|
||||
}
|
||||
|
@ -142,7 +141,7 @@ public class PeerToPeerChat extends BaseSession implements IPeerToPeer, IEventPu
|
|||
private List<InternalListener> messageListeners = null;
|
||||
|
||||
private Namespace namespace = null;
|
||||
|
||||
|
||||
private IChatMessageSender chatSender = null;
|
||||
|
||||
/**
|
||||
|
@ -151,11 +150,20 @@ public class PeerToPeerChat extends BaseSession implements IPeerToPeer, IEventPu
|
|||
* @param externalBus
|
||||
* @param manager
|
||||
*/
|
||||
PeerToPeerChat(IContainer container, EventBus externalBus, SessionManager manager) {
|
||||
PeerToPeerChat(IContainer container, EventBus externalBus,
|
||||
SessionManager 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) {
|
||||
// Assume success
|
||||
int status = Errors.NO_ERROR;
|
||||
if(chatSender != null) {
|
||||
if (chatSender != null) {
|
||||
ID toID = createID(message.getTo().getName());
|
||||
String subject = message.getSubject();
|
||||
String body = message.getBody();
|
||||
Collection<Property> properties = message.getProperties();
|
||||
Map<String, String> props = null;
|
||||
if((properties != null) && (properties.size() > 0)) {
|
||||
if ((properties != null) && (properties.size() > 0)) {
|
||||
props = new HashMap<String, String>();
|
||||
for(Property p : properties) {
|
||||
props.put(p.getKey(),p.getValue());
|
||||
for (Property p : properties) {
|
||||
props.put(p.getKey(), p.getValue());
|
||||
}
|
||||
}
|
||||
try {
|
||||
chatSender.sendChatMessage(toID, null, IChatMessage.Type.CHAT, subject, body, props);
|
||||
chatSender.sendChatMessage(toID, null, IChatMessage.Type.CHAT,
|
||||
subject, body, props);
|
||||
} catch (ECFException e) {
|
||||
System.out.println("Error sending message");
|
||||
e.printStackTrace();
|
||||
|
@ -187,8 +196,11 @@ public class PeerToPeerChat extends BaseSession implements IPeerToPeer, IEventPu
|
|||
|
||||
/**
|
||||
* 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
|
||||
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");
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
|
@ -209,8 +221,10 @@ public class PeerToPeerChat extends BaseSession implements IPeerToPeer, IEventPu
|
|||
*
|
||||
*/
|
||||
@Override
|
||||
public IMessageListener addMessageListener(IMessageListener listener, IMessageFilter filter) {
|
||||
InternalListener messageListener = new InternalListener(listener, filter);
|
||||
public IMessageListener addMessageListener(IMessageListener listener,
|
||||
IMessageFilter filter) {
|
||||
InternalListener messageListener = new InternalListener(listener,
|
||||
filter);
|
||||
messageListeners.add(messageListener);
|
||||
return listener;
|
||||
}
|
||||
|
@ -221,8 +235,8 @@ public class PeerToPeerChat extends BaseSession implements IPeerToPeer, IEventPu
|
|||
@Override
|
||||
public Collection<IMessageListener> getMessageListeners() {
|
||||
Collection<IMessageListener> listeners = new ArrayList<IMessageListener>();
|
||||
synchronized(messageListeners) {
|
||||
for(InternalListener intListener : messageListeners) {
|
||||
synchronized (messageListeners) {
|
||||
for (InternalListener intListener : messageListeners) {
|
||||
listeners.add(intListener.messageListener);
|
||||
}
|
||||
}
|
||||
|
@ -235,11 +249,10 @@ public class PeerToPeerChat extends BaseSession implements IPeerToPeer, IEventPu
|
|||
@Override
|
||||
public IMessageListener removeMessageListener(IMessageListener listener) {
|
||||
IMessageListener removed = null;
|
||||
if(messageListeners.remove(listener)) {
|
||||
if (messageListeners.remove(listener)) {
|
||||
removed = listener;
|
||||
}
|
||||
return removed;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -44,7 +44,6 @@ import org.eclipse.ecf.presence.chatroom.IChatRoomParticipantListener;
|
|||
import org.eclipse.ecf.provider.xmpp.identity.XMPPRoomID;
|
||||
|
||||
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.IMessage;
|
||||
import com.raytheon.uf.viz.collaboration.comm.identity.IPresence;
|
||||
|
@ -225,46 +224,48 @@ public class VenueSession extends BaseSession implements IVenueSession,
|
|||
} finally {
|
||||
initListeners();
|
||||
}
|
||||
// Runnable r = new Runnable() {
|
||||
// @Override
|
||||
// public void run() {
|
||||
// try {
|
||||
// Thread.sleep(20000);
|
||||
//
|
||||
// TestJAXBObject j = new TestJAXBObject();
|
||||
// j.setItem_1("This is an object");
|
||||
// j.setValue(5);
|
||||
// sendRenderableObject(j);
|
||||
// } catch (Exception e) {
|
||||
// System.out.println("Error sending RenderableObject");
|
||||
// }
|
||||
// }
|
||||
// };
|
||||
// Thread t = new Thread(r);
|
||||
// t.start();
|
||||
// registerEventHandler(this);
|
||||
// Runnable r = new Runnable() {
|
||||
// @Override
|
||||
// public void run() {
|
||||
// try {
|
||||
// Thread.sleep(20000);
|
||||
//
|
||||
// TestJAXBObject j = new TestJAXBObject();
|
||||
// j.setItem_1("This is an object");
|
||||
// j.setValue(5);
|
||||
// sendRenderableObject(j);
|
||||
// } catch (Exception e) {
|
||||
// System.out.println("Error sending RenderableObject");
|
||||
// }
|
||||
// }
|
||||
// };
|
||||
// Thread t = new Thread(r);
|
||||
// t.start();
|
||||
// registerEventHandler(this);
|
||||
}
|
||||
|
||||
// @Subscribe
|
||||
// public void handle(IRenderable renderable) {
|
||||
// System.out.println("Renderable found");
|
||||
// if(renderable instanceof TestJAXBObject) {
|
||||
// TestJAXBObject j = (TestJAXBObject) renderable;
|
||||
// if(j.getValue() < 100) {
|
||||
// System.out.println(String.format("%s %d Renderable", j.getItem_1(), j.getValue()));
|
||||
// j.setValue(j.getValue() + 200);
|
||||
// j.setItem_1("Now for the return trip");
|
||||
// try {
|
||||
// sendRenderableObject(j);
|
||||
// } catch (CollaborationException ce) {
|
||||
// System.out.println("Error sending RenderableObject");
|
||||
// }
|
||||
// } else {
|
||||
// System.out.println(String.format("%s %d Renderable", j.getItem_1(), j.getValue()));
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// @Subscribe
|
||||
// public void handle(IRenderable renderable) {
|
||||
// System.out.println("Renderable found");
|
||||
// if(renderable instanceof TestJAXBObject) {
|
||||
// TestJAXBObject j = (TestJAXBObject) renderable;
|
||||
// if(j.getValue() < 100) {
|
||||
// System.out.println(String.format("%s %d Renderable", j.getItem_1(),
|
||||
// j.getValue()));
|
||||
// j.setValue(j.getValue() + 200);
|
||||
// j.setItem_1("Now for the return trip");
|
||||
// try {
|
||||
// sendRenderableObject(j);
|
||||
// } catch (CollaborationException ce) {
|
||||
// System.out.println("Error sending RenderableObject");
|
||||
// }
|
||||
// } else {
|
||||
// System.out.println(String.format("%s %d Renderable", j.getItem_1(),
|
||||
// j.getValue()));
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
/**
|
||||
*
|
||||
* @throws ECFException
|
||||
|
@ -617,7 +618,8 @@ public class VenueSession extends BaseSession implements IVenueSession,
|
|||
* @param participant
|
||||
* @param initData
|
||||
* @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
|
||||
public void sendInitData(
|
||||
|
@ -629,7 +631,7 @@ public class VenueSession extends BaseSession implements IVenueSession,
|
|||
if (session != null) {
|
||||
String message = Tools.marshallData(initData);
|
||||
if (message != null) {
|
||||
session.sendPeerToPeer(participant.getFQName(), message);
|
||||
session.sendPeerToPeer(participant.getName(), message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue