Merge "Issue #232 - Added support for session creation from invitation" into 11-Collaboration

Former-commit-id: 0338159662 [formerly 459aa33b196c8c37897575636ae670505d959330]
Former-commit-id: 7facfe9b7c
This commit is contained in:
Nate Jensen 2012-03-29 16:32:15 -05:00 committed by Gerrit Code Review
commit 97898c1a3c
11 changed files with 342 additions and 110 deletions

View file

@ -90,19 +90,4 @@ public interface ISession extends IEventPublisher {
* @return The session identifier.
*/
String getSessionId();
/**
* Get the session identifier of a remote session this session is following.
*
* @return The remote session id.
*/
String getFollowingSessionId();
/**
* Set the session identifier of a remote session this session is following.
*
* @param id
* The remote session identifier.
*/
void setFollowingSessionId(String id);
}

View file

@ -80,14 +80,14 @@ public interface ISharedDisplaySession extends IEventPublisher {
*
* @param subscriber
*/
void subscribeToInitData(Object subscriber) throws CollaborationException;
void subscribeToPeerToPeerData(Object subscriber) throws CollaborationException;
/**
*
* @param subscriber
* @throws CollaborationException
*/
void unSubscribeToInitData(Object subscriber) throws CollaborationException;
void unSubscribeToPeerToPeerData(Object subscriber) throws CollaborationException;
/**
*

View file

@ -51,7 +51,7 @@ public interface IVenueInvitationEvent {
*
* @return
*/
IQualifiedID getInvitor();
IQualifiedID getInviter();
/**
*
@ -64,4 +64,8 @@ public interface IVenueInvitationEvent {
*/
String getBody();
/**
* @return The sessionId of the inviter.
*/
String getSessionId();
}

View file

@ -0,0 +1,49 @@
/**
* This software was developed and / or modified by Raytheon Company,
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
*
* U.S. EXPORT CONTROLLED TECHNICAL DATA
* This software product contains export-restricted data whose
* export/transfer/disclosure is restricted by U.S. law. Dissemination
* to non-U.S. persons whether in the United States or abroad requires
* an export license or other authorization.
*
* Contractor Name: Raytheon Company
* Contractor Address: 6825 Pine Street, Suite 340
* Mail Stop B8
* Omaha, NE 68106
* 402.291.0100
*
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
* further licensing information.
**/
package com.raytheon.uf.viz.collaboration.comm.identity.user;
/**
* TODO Add Description
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Mar 29, 2012 jkorman Initial creation
*
* </pre>
*
* @author jkorman
* @version 1.0
*/
public interface IVenueId extends IQualifiedID {
String getVenueName();
String getDomain();
}

View file

@ -48,7 +48,9 @@ import com.raytheon.uf.viz.collaboration.comm.identity.IPresence;
public abstract class Tools {
public static final String TAG_INVITE_ID = "[[INVITEID#%s]]%s";
public static final String TAG_INVITE = "[[INVITEID#";
public static final String TAG_INVITE_ID = TAG_INVITE + "%s]]%s";
public static final String PROP_SESSION_ID = "sessionId";

View file

@ -21,6 +21,7 @@ package com.raytheon.uf.viz.collaboration.comm.provider.event;
import com.raytheon.uf.viz.collaboration.comm.identity.event.IVenueInvitationEvent;
import com.raytheon.uf.viz.collaboration.comm.identity.user.IQualifiedID;
import com.raytheon.uf.viz.collaboration.comm.provider.Tools;
/**
* TODO Add Description
@ -49,6 +50,8 @@ public class VenueInvitationEvent implements IVenueInvitationEvent {
private String body;
private String sessionId;
/**
*
* @param roomId
@ -62,6 +65,7 @@ public class VenueInvitationEvent implements IVenueInvitationEvent {
this.invitor = invitor;
this.subject = subject;
this.body = body;
extractSessionId();
}
/**
@ -75,10 +79,10 @@ public class VenueInvitationEvent implements IVenueInvitationEvent {
}
/**
* @see com.raytheon.uf.viz.collaboration.comm.identity.event.IVenueInvitationEvent#getInvitor()
* @see com.raytheon.uf.viz.collaboration.comm.identity.event.IVenueInvitationEvent#getInviter()
*/
@Override
public IQualifiedID getInvitor() {
public IQualifiedID getInviter() {
return invitor;
}
@ -97,5 +101,29 @@ public class VenueInvitationEvent implements IVenueInvitationEvent {
public String getBody() {
return body;
}
/**
* @return the sessionId
*/
public String getSessionId() {
return sessionId;
}
/**
* Extract the session identifier from the body of the invitation.
*/
private void extractSessionId() {
if (body != null) {
if (body.startsWith(Tools.TAG_INVITE)) {
int start = Tools.TAG_INVITE.length();
// find the end of the invite tag
int tagEnd = body.indexOf("]]");
if (tagEnd > start) {
sessionId = body.substring(start, tagEnd);
body = body.substring(tagEnd + 2);
}
}
}
}
}

View file

@ -56,8 +56,6 @@ public abstract class BaseSession implements ISession {
protected final String sessionId;
private String followingId;
private EventBus managerEventBus;
private EventBus eventBus;
@ -81,8 +79,20 @@ public abstract class BaseSession implements ISession {
*/
protected BaseSession(IContainer container, EventBus externalBus,
SessionManager manager) throws CollaborationException {
this(container, externalBus, manager, UUID.randomUUID().toString());
}
/**
*
* @param container
* @param externalBus
* @param manager
* @param sessionId
*/
protected BaseSession(IContainer container, EventBus externalBus,
SessionManager manager, String sessionId) throws CollaborationException {
// Set the session identifier.
sessionId = UUID.randomUUID().toString();
this.sessionId = sessionId;
managerEventBus = externalBus;
eventBus = new EventBus();
connectionContainer = container;
@ -90,7 +100,7 @@ public abstract class BaseSession implements ISession {
eventSubscribers = new HashMap<Object, Object>();
setup();
}
/**
*
* @throws ECFException
@ -183,28 +193,6 @@ public abstract class BaseSession implements ISession {
return sessionId;
}
/**
* Get the session identifier of a remote session this session is following.
*
* @param id
* The remote session identifier.
* @see com.raytheon.uf.viz.collaboration.comm.identity.ISession#getFollowingSessionId()
*/
@Override
public String getFollowingSessionId() {
return followingId;
}
/**
* Set the session identifier of a remote session this session is following.
*
* @see com.raytheon.uf.viz.collaboration.comm.identity.ISession#setFollowingSessionId(java.lang.String)
*/
@Override
public void setFollowingSessionId(String id) {
followingId = id;
}
// *****************
// Implement IEventPublisher methods
// *****************

View file

@ -58,6 +58,9 @@ public class DataHandler {
@Subscribe
public void handle(IVenueInvitationEvent event) {
System.out.println("DataHandler---------------------------------");
System.out.println("Received invitation " + event.getBody());
System.out.println(" venue identifer " + event.getRoomId());
System.out.println(" inviter " + event.getInviter());
System.out.println(" sessionid " + event.getSessionId());
System.out.println(" body " + event.getBody());
}
}

View file

@ -39,6 +39,7 @@ import org.eclipse.ecf.presence.chatroom.IChatRoomInfo;
import org.eclipse.ecf.presence.chatroom.IChatRoomInvitationListener;
import org.eclipse.ecf.presence.chatroom.IChatRoomManager;
import org.eclipse.ecf.presence.roster.IRoster;
import org.eclipse.ecf.provider.xmpp.identity.XMPPRoomID;
import org.jivesoftware.smack.XMPPConnection;
import com.google.common.eventbus.EventBus;
@ -59,6 +60,7 @@ import com.raytheon.uf.viz.collaboration.comm.provider.event.VenueInvitationEven
import com.raytheon.uf.viz.collaboration.comm.provider.info.InfoAdapter;
import com.raytheon.uf.viz.collaboration.comm.provider.roster.RosterManager;
import com.raytheon.uf.viz.collaboration.comm.provider.user.IDConverter;
import com.raytheon.uf.viz.collaboration.comm.provider.user.VenueId;
import com.raytheon.uf.viz.collaboration.comm.provider.user.VenueUserId;
/**
@ -259,7 +261,12 @@ public class SessionManager implements IEventPublisher {
// Close any created sessions.
for (ISession session : sessions.values()) {
session.close();
if ((chatInstance != null) && chatInstance.equals(session)) {
chatInstance.close();
chatInstance = null;
} else {
session.close();
}
}
chatInstance = null;
// Get rid of the account and roster managers
@ -281,6 +288,23 @@ public class SessionManager implements IEventPublisher {
return chatInstance;
}
public IVenueSession joinCollaborationVenue(IVenueInvitationEvent invitation)
throws CollaborationException {
VenueSession session = null;
try {
String venueName = invitation.getRoomId().getName();
String sessionId = invitation.getSessionId();
session = new VenueSession(container, eventBus, this, sessionId);
if (session != null) {
session.joinVenue(venueName);
sessions.put(session.getSessionId(), session);
}
} catch (Exception e) {
}
return session;
}
/**
*
* @param venueName
@ -466,17 +490,25 @@ public class SessionManager implements IEventPublisher {
public void handleInvitationReceived(ID roomID, ID from,
String subject, String body) {
IQualifiedID venueId = IDConverter.convertFrom(roomID);
IQualifiedID id = IDConverter.convertFrom(from);
IQualifiedID venueId = null;
if(roomID instanceof XMPPRoomID) {
XMPPRoomID room = (XMPPRoomID) roomID;
venueId = new VenueId();
venueId.setName(room.getLongName());
}
if(venueId != null) {
IQualifiedID id = IDConverter.convertFrom(from);
IChatID invitor = new VenueUserId(id.getName(),
id.getHost(), id.getResource());
IChatID invitor = new VenueUserId(id.getName(),
id.getHost(), id.getResource());
IVenueInvitationEvent invite = new VenueInvitationEvent(
venueId, invitor, subject, body);
System.out.println("Posting invitation using eventBus:"
+ eventBus.hashCode());
eventBus.post(invite);
IVenueInvitationEvent invite = new VenueInvitationEvent(
venueId, invitor, subject, body);
System.out.println("Posting invitation using eventBus:"
+ eventBus.hashCode());
eventBus.post(invite);
}
}
};
venueManager.addInvitationListener(intInvitationListener);

View file

@ -130,6 +130,16 @@ public class VenueSession extends BaseSession implements IVenueSession,
private Map<Object, Object> initSubscribers = new HashMap<Object, Object>();
/**
*
* @param container
* @param eventBus
*/
VenueSession(IContainer container, EventBus externalBus,
SessionManager manager, String sessionId) throws CollaborationException {
super(container, externalBus, manager, sessionId);
}
/**
*
* @param container
@ -139,50 +149,51 @@ public class VenueSession extends BaseSession implements IVenueSession,
SessionManager manager) throws CollaborationException {
super(container, externalBus, manager);
// Runnable r = new Runnable() {
// @Override
// public void run() {
// try {
// Thread.sleep(30000);
//
// TestJAXBObject j = new TestJAXBObject();
// j.setItem_1("This is an object");
// j.setValue(5);
// sendRenderableObject(j);
//
// VenueParticipant id = new VenueParticipant("jkorman",
// "paul", "awipscm.omaha.us.ray.com");
// id.setResource("cave");
// IInitData d = new InitData();
// ((InitData) d).setName("This is a test init data object");
//
// IDisplayEvent e = new DisplayEvent();
// ((DisplayEvent) e).setName("This is a test display event");
//
// sendInitData(id, d);
// sendEvent(id, e);
//
// Thread.sleep(10000);
// System.out.println("Sending invitation");
//
// sendInvitation("tester5@conference.awipscm.omaha.us.ray.com",
// "jkorman", "Test Room", "Join the test");
//
// } catch (Exception e) {
// System.out.println("Error sending RenderableObject");
// }
//
// }
// };
// Thread t = new Thread(r);
// t.start();
// registerEventHandler(this);
// try {
// DataHandler h = new DataHandler();
// subscribeToInitData(h);
// } catch (CollaborationException ce) {
// ce.printStackTrace();
// }
Runnable r = new Runnable() {
@Override
public void run() {
try {
Thread.sleep(30000);
// TestJAXBObject j = new TestJAXBObject();
// j.setItem_1("This is an object");
// j.setValue(5);
// sendRenderableObject(j);
//
// VenueParticipant id = new VenueParticipant("jkorman",
// "paul", "awipscm.omaha.us.ray.com");
// id.setResource("cave");
// IInitData d = new InitData();
// ((InitData) d).setName("This is a test init data object");
//
// IDisplayEvent e = new DisplayEvent();
// ((DisplayEvent) e).setName("This is a test display event");
//
// sendInitData(id, d);
// sendEvent(id, e);
//
// Thread.sleep(10000);
System.out.println("Sending invitation");
sendInvitation(
"tester5@conference.awipscm.omaha.us.ray.com",
"jkorman", "Test Room", "Join the test");
} catch (Exception e) {
System.out.println("Error sending RenderableObject");
}
}
};
Thread t = new Thread(r);
t.start();
registerEventHandler(this);
try {
DataHandler h = new DataHandler();
subscribeToPeerToPeerData(h);
} catch (CollaborationException ce) {
ce.printStackTrace();
}
}
// @Subscribe
@ -425,8 +436,7 @@ public class VenueSession extends BaseSession implements IVenueSession,
com.raytheon.uf.viz.collaboration.comm.identity.user.IChatID participant,
IInitData initData) throws CollaborationException {
PeerToPeerChat session = null;
session = getP2PSession();
PeerToPeerChat session = getP2PSession();
if (session != null) {
String message = Tools.marshallData(initData);
if (message != null) {
@ -442,14 +452,16 @@ public class VenueSession extends BaseSession implements IVenueSession,
* object that subscribes to peer to peer events.
*/
@Override
public void subscribeToInitData(Object subscriber)
public void subscribeToPeerToPeerData(Object subscriber)
throws CollaborationException {
if (!initSubscribers.containsKey(subscriber)) {
initSubscribers.put(subscriber, subscriber);
}
EventBus bus = getP2PSession().getEventPublisher();
System.out.println("Subscribe EventBus instance :" + bus.hashCode());
bus.register(subscriber);
PeerToPeerChat session = getP2PSession();
if (session != null) {
session.registerEventHandler(subscriber);
}
}
/**
@ -459,11 +471,14 @@ public class VenueSession extends BaseSession implements IVenueSession,
* object that will be unsubscribed for peer to peer events.
*/
@Override
public void unSubscribeToInitData(Object subscriber)
public void unSubscribeToPeerToPeerData(Object subscriber)
throws CollaborationException {
if (initSubscribers.containsKey(subscriber)) {
initSubscribers.remove(subscriber);
getP2PSession().getEventPublisher().unregister(subscriber);
PeerToPeerChat session = getP2PSession();
if (session != null) {
session.unRegisterEventHandler(subscriber);
}
}
}

View file

@ -0,0 +1,126 @@
/**
* This software was developed and / or modified by Raytheon Company,
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
*
* U.S. EXPORT CONTROLLED TECHNICAL DATA
* This software product contains export-restricted data whose
* export/transfer/disclosure is restricted by U.S. law. Dissemination
* to non-U.S. persons whether in the United States or abroad requires
* an export license or other authorization.
*
* Contractor Name: Raytheon Company
* Contractor Address: 6825 Pine Street, Suite 340
* Mail Stop B8
* Omaha, NE 68106
* 402.291.0100
*
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
* further licensing information.
**/
package com.raytheon.uf.viz.collaboration.comm.provider.user;
import com.raytheon.uf.viz.collaboration.comm.identity.user.IVenueId;
/**
* TODO Add Description
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Mar 29, 2012 jkorman Initial creation
*
* </pre>
*
* @author jkorman
* @version 1.0
*/
public class VenueId implements IVenueId {
private String host;
private String resource;
private String venueName;
private String name;
private String domain;
/**
* @see com.raytheon.uf.viz.collaboration.comm.identity.user.IQualifiedID#setHost(java.lang.String)
*/
@Override
public void setHost(String hostName) {
host = hostName;
}
/**
* @see com.raytheon.uf.viz.collaboration.comm.identity.user.IQualifiedID#getHost()
*/
@Override
public String getHost() {
return host;
}
/**
* @see com.raytheon.uf.viz.collaboration.comm.identity.user.IQualifiedID#setResource(java.lang.String)
*/
@Override
public void setResource(String resource) {
this.resource = resource;
}
/**
* @see com.raytheon.uf.viz.collaboration.comm.identity.user.IQualifiedID#getResource()
*/
@Override
public String getResource() {
return resource;
}
/**
* @see com.raytheon.uf.viz.collaboration.comm.identity.user.ID#setName(java.lang.String)
*/
@Override
public void setName(String userName) {
name = userName;
venueName = name;
}
/**
* @see com.raytheon.uf.viz.collaboration.comm.identity.user.ID#getName()
*/
@Override
public String getName() {
return name;
}
/**
* @see com.raytheon.uf.viz.collaboration.comm.identity.user.ID#getFQName()
*/
@Override
public String getFQName() {
return null;
}
/**
* @see com.raytheon.uf.viz.collaboration.comm.identity.user.IVenueId#getVenueName()
*/
@Override
public String getVenueName() {
return venueName;
}
/**
* @see com.raytheon.uf.viz.collaboration.comm.identity.user.IVenueId#getDomain()
*/
@Override
public String getDomain() {
return null;
}
}