Issue #444 initial role transfer code and some cleanup

Change-Id: I45abf42df8da789532a4420259065fbb1f7ed04f

Former-commit-id: 0ef84129c4 [formerly c7276b7fddee718fd47f1f1b3fb75d5b483e62fc]
Former-commit-id: c1543afc44
This commit is contained in:
Nate Jensen 2012-04-05 17:49:12 -05:00
parent 48ca9ca105
commit 28684fd160
8 changed files with 249 additions and 77 deletions

View file

@ -19,8 +19,10 @@
**/
package com.raytheon.uf.viz.collaboration.data;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.eclipse.swt.SWT;
@ -54,13 +56,15 @@ import com.raytheon.uf.viz.collaboration.comm.provider.session.SessionManager;
import com.raytheon.uf.viz.collaboration.ui.editor.CollaborationEditor;
import com.raytheon.uf.viz.collaboration.ui.login.LoginData;
import com.raytheon.uf.viz.collaboration.ui.login.LoginDialog;
import com.raytheon.uf.viz.collaboration.ui.role.AbstractRoleEventController;
import com.raytheon.uf.viz.collaboration.ui.role.DataProviderEventController;
import com.raytheon.uf.viz.collaboration.ui.role.IRoleEventController;
import com.raytheon.uf.viz.collaboration.ui.role.ParticipantEventController;
import com.raytheon.uf.viz.collaboration.ui.role.SessionLeaderEventController;
import com.raytheon.uf.viz.collaboration.ui.session.CollaborationSessionView;
import com.raytheon.uf.viz.collaboration.ui.session.PeerToPeerView;
import com.raytheon.uf.viz.core.VizApp;
import com.raytheon.viz.ui.VizWorkbenchManager;
import com.raytheon.viz.ui.editor.AbstractEditor;
/**
* A single class that contains all data information.
@ -111,7 +115,7 @@ public class CollaborationDataManager {
*/
Map<String, IVenueSession> sessionsMap;
private Multimap<String, AbstractRoleEventController> roleEventControllersMap;
private Multimap<String, IRoleEventController> roleEventControllersMap;
Map<String, CollaborationEditor> editorsMap;
@ -332,10 +336,10 @@ public class CollaborationDataManager {
}
}
Collection<AbstractRoleEventController> controller = roleEventControllersMap
Collection<IRoleEventController> controller = roleEventControllersMap
.removeAll(sessionId);
if (controller != null) {
for (AbstractRoleEventController cont : controller) {
for (IRoleEventController cont : controller) {
cont.shutdown();
}
}
@ -578,4 +582,18 @@ public class CollaborationDataManager {
}
return result;
}
public Collection<IRoleEventController> getEventControllers(String sessionId) {
return roleEventControllersMap.get(sessionId);
}
public List<AbstractEditor> getActivelySharedEditors(String sessionId) {
List<AbstractEditor> list = new ArrayList<AbstractEditor>();
// TODO actually keep track of a list and return that
// list should be empty if you're not the data provider
list.add((AbstractEditor) VizWorkbenchManager.getInstance()
.getActiveEditor());
return list;
}
}

View file

@ -113,7 +113,8 @@ public class DataUser {
* @param sessionId
* @param role
*/
void addSessionRole(final String sessionId, final ParticipantRole role) {
public void addSessionRole(final String sessionId,
final ParticipantRole role) {
List<ParticipantRole> roleList = roleMap.get(sessionId);
if (roleList == null) {
roleList = new ArrayList<ParticipantRole>();
@ -150,7 +151,7 @@ public class DataUser {
* @param sessionId
* @param role
*/
void removeSessionRole(String sessionId, ParticipantRole role) {
public void removeSessionRole(String sessionId, ParticipantRole role) {
List<ParticipantRole> roleList = roleMap.get(sessionId);
if (roleList != null) {
roleList.remove(role);

View file

@ -30,6 +30,7 @@ import com.raytheon.uf.viz.collaboration.comm.identity.CollaborationException;
import com.raytheon.uf.viz.collaboration.comm.identity.ISharedDisplaySession;
import com.raytheon.uf.viz.collaboration.comm.identity.event.ParticipantEventType;
import com.raytheon.uf.viz.collaboration.comm.provider.event.VenueParticipantEvent;
import com.raytheon.uf.viz.collaboration.data.CollaborationDataManager;
import com.raytheon.uf.viz.collaboration.ui.editor.EditorSetup;
import com.raytheon.uf.viz.collaboration.ui.editor.SharedEditor;
import com.raytheon.uf.viz.collaboration.ui.editor.event.InputEvent;
@ -75,7 +76,8 @@ public class DataProviderEventController extends AbstractRoleEventController {
.getInstance().getActiveEditor();
SharedEditor se = EditorSetup.extractSharedEditor(editor);
try {
session.sendInitData(event.getParticipant().getQualifiedId(), se);
session.sendInitData(event.getParticipant().getQualifiedId(),
se);
} catch (CollaborationException e) {
statusHandler.handle(Priority.PROBLEM,
"Error sending initialization data to new participant "
@ -92,9 +94,9 @@ public class DataProviderEventController extends AbstractRoleEventController {
// leader. ideally no InputEvents are sent when data provider and
// session leader are one and the same
// TODO get the actively shared editor, not the active editor
AbstractEditor editor = (AbstractEditor) VizWorkbenchManager
.getInstance().getActiveEditor();
// TODO should we handle more than 1?
AbstractEditor editor = CollaborationDataManager.getInstance()
.getActivelySharedEditors(session.getSessionId()).get(0);
IDisplayPane pane = editor.getDisplayPanes()[0];
Event swtEvent = new Event();

View file

@ -0,0 +1,110 @@
/**
* 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.ui.role;
import java.util.Collection;
import java.util.Iterator;
import com.google.common.eventbus.Subscribe;
import com.raytheon.uf.viz.collaboration.comm.identity.ISharedDisplaySession;
import com.raytheon.uf.viz.collaboration.comm.identity.user.ParticipantRole;
import com.raytheon.uf.viz.collaboration.comm.provider.TransferRoleCommand;
import com.raytheon.uf.viz.collaboration.data.CollaborationDataManager;
import com.raytheon.uf.viz.collaboration.data.DataUser;
/**
* Handles the events of a session that are common to all collaborators
* regardless of role.
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Apr 5, 2012 njensen Initial creation
*
* </pre>
*
* @author njensen
* @version 1.0
*/
public class RoleAgnosticEventController extends AbstractRoleEventController {
protected RoleAgnosticEventController(ISharedDisplaySession session) {
super(session);
}
@Subscribe
public void roleTransferred(TransferRoleCommand command) {
// update the user data for this change
String oldUserName = null;
ParticipantRole changedRole = command.getRole();
if (changedRole.equals(ParticipantRole.DATA_PROVIDER)) {
oldUserName = session.getCurrentDataProvider().getFQName();
} else if (changedRole.equals(ParticipantRole.SESSION_LEADER)) {
oldUserName = session.getCurrentDataProvider().getFQName();
}
DataUser oldUser = CollaborationDataManager.getInstance().getUser(
oldUserName);
oldUser.removeSessionRole(session.getSessionId(), changedRole);
DataUser newUser = CollaborationDataManager.getInstance().getUser(
command.getUser());
newUser.addSessionRole(session.getSessionId(), changedRole);
// shut down the role specific events if applicable
if (session.getUserID().getFQName().equals(oldUserName)) {
Collection<IRoleEventController> list = CollaborationDataManager
.getInstance().getEventControllers(session.getSessionId());
Iterator<IRoleEventController> itr = list.iterator();
while (itr.hasNext()) {
IRoleEventController rc = itr.next();
if (changedRole == ParticipantRole.SESSION_LEADER
&& rc instanceof SessionLeaderEventController) {
rc.shutdown();
itr.remove();
} else if (changedRole == ParticipantRole.DATA_PROVIDER
&& rc instanceof DataProviderEventController) {
rc.shutdown();
itr.remove();
}
}
}
// start up new role if applicable
if (session.getUserID().getFQName().equals(command.getUser())) {
Collection<IRoleEventController> list = CollaborationDataManager
.getInstance().getEventControllers(session.getSessionId());
if (changedRole.equals(ParticipantRole.SESSION_LEADER)) {
SessionLeaderEventController slec = new SessionLeaderEventController(
session);
slec.startup();
list.add(slec);
} else if (changedRole.equals(ParticipantRole.DATA_PROVIDER)) {
DataProviderEventController dpec = new DataProviderEventController(
session);
dpec.startup();
list.add(dpec);
}
}
}
}

View file

@ -27,6 +27,7 @@ import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.ActionContributionItem;
import org.eclipse.jface.action.IMenuCreator;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Menu;
@ -67,11 +68,7 @@ public class CollaborationSessionView extends SessionView {
switchToAction = new Action("Transfer Role...",
Action.AS_DROP_DOWN_MENU) {
public void run() {
if ("DataProvider".equals(switchToAction.getId())) {
switchDataProvider();
} else if ("SessionLeader".equals(switchToAction.getId())) {
switchLeader();
}
// do nothing
};
};
@ -85,8 +82,11 @@ public class CollaborationSessionView extends SessionView {
}
Action leaderAction = new Action("Session Leader") {
public void run() {
switchToAction.setId("SessionLeader");
switchToAction.run();
IStructuredSelection selection = (IStructuredSelection) usersTable
.getSelection();
CollaborationUser selectedUser = (CollaborationUser) selection
.getFirstElement();
switchLeader(selectedUser.getId());
};
};
ActionContributionItem leaderItem = new ActionContributionItem(
@ -95,8 +95,11 @@ public class CollaborationSessionView extends SessionView {
Action dataProviderAction = new Action("Data Provider") {
public void run() {
switchToAction.setId("DataProvider");
switchToAction.run();
IStructuredSelection selection = (IStructuredSelection) usersTable
.getSelection();
CollaborationUser selectedUser = (CollaborationUser) selection
.getFirstElement();
switchDataProvider(selectedUser.getId());
};
};
ActionContributionItem dataProviderItem = new ActionContributionItem(
@ -118,12 +121,16 @@ public class CollaborationSessionView extends SessionView {
switchToAction.setMenuCreator(creator);
}
public void switchDataProvider() {
System.out.println("Send switchDataProvider request.");
private void switchDataProvider(String fqname) {
System.out.println("Send switchDataProvider request. " + fqname);
// TODO need to send invite/request for transfer, and then if successful
// deactivate the local ones since we won't receive the message
}
public void switchLeader() {
System.out.println("Send switchLeader request");
private void switchLeader(String fqname) {
System.out.println("Send switchLeader request. " + fqname);
// TODO need to send invite/request for transfer, and then if successful
// deactivate the local ones since we won't receive the message
}
@Override

View file

@ -31,8 +31,8 @@ import com.raytheon.uf.viz.collaboration.comm.identity.user.ParticipantRole;
*
*
* <ul>
* <li>EventBus subscription events. Implementors may to post the
* following events.</li>
* <li>EventBus subscription events. Implementors may to post the following
* events.</li>
* <ul>
* <li><strong>IVenueParticipantEvent</strong> : This event is posted when a
* venue participant enters, leaves a venue, or updates their status in the
@ -76,19 +76,6 @@ public interface ISharedDisplaySession extends IEventPublisher {
void sendInitData(IQualifiedID participant, IInitData initData)
throws CollaborationException;
/**
*
* @param subscriber
*/
void subscribeToPeerToPeerData(Object subscriber) throws CollaborationException;
/**
*
* @param subscriber
* @throws CollaborationException
*/
void unSubscribeToPeerToPeerData(Object subscriber) throws CollaborationException;
/**
*
* @param event
@ -104,6 +91,9 @@ public interface ISharedDisplaySession extends IEventPublisher {
void sendRenderableObject(IRenderable renderable)
throws CollaborationException;
void sendTransferRole(String fqName, ParticipantRole role)
throws CollaborationException;
/**
*
* @return

View file

@ -0,0 +1,68 @@
/**
* 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;
import com.raytheon.uf.common.serialization.annotations.DynamicSerialize;
import com.raytheon.uf.common.serialization.annotations.DynamicSerializeElement;
import com.raytheon.uf.viz.collaboration.comm.identity.user.ParticipantRole;
/**
* TODO Add Description
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Apr 5, 2012 njensen Initial creation
*
* </pre>
*
* @author njensen
* @version 1.0
*/
@DynamicSerialize
public class TransferRoleCommand {
@DynamicSerializeElement
private ParticipantRole role;
@DynamicSerializeElement
private String user;
public ParticipantRole getRole() {
return role;
}
public void setRole(ParticipantRole role) {
this.role = role;
}
public String getUser() {
return user;
}
public void setUser(String user) {
this.user = user;
}
}

View file

@ -62,6 +62,7 @@ import com.raytheon.uf.viz.collaboration.comm.provider.Errors;
import com.raytheon.uf.viz.collaboration.comm.provider.Presence;
import com.raytheon.uf.viz.collaboration.comm.provider.TextMessage;
import com.raytheon.uf.viz.collaboration.comm.provider.Tools;
import com.raytheon.uf.viz.collaboration.comm.provider.TransferRoleCommand;
import com.raytheon.uf.viz.collaboration.comm.provider.event.VenueParticipantEvent;
import com.raytheon.uf.viz.collaboration.comm.provider.info.InfoAdapter;
import com.raytheon.uf.viz.collaboration.comm.provider.info.Venue;
@ -126,8 +127,6 @@ public class VenueSession extends BaseSession implements IVenueSession,
private EnumSet<ParticipantRole> roles = EnumSet
.noneOf(ParticipantRole.class);
private Map<Object, Object> initSubscribers = new HashMap<Object, Object>();
private String subject;
/**
@ -360,43 +359,6 @@ public class VenueSession extends BaseSession implements IVenueSession,
}
}
/**
* Subscribe to peer to peer data events.
*
* @param An
* object that subscribes to peer to peer events.
*/
@Override
public void subscribeToPeerToPeerData(Object subscriber)
throws CollaborationException {
if (!initSubscribers.containsKey(subscriber)) {
initSubscribers.put(subscriber, subscriber);
}
PeerToPeerChat session = getP2PSession();
if (session != null) {
session.registerEventHandler(subscriber);
}
}
/**
* UnSubscribe to peer to peer data events.
*
* @param An
* object that will be unsubscribed for peer to peer events.
*/
@Override
public void unSubscribeToPeerToPeerData(Object subscriber)
throws CollaborationException {
if (initSubscribers.containsKey(subscriber)) {
initSubscribers.remove(subscriber);
PeerToPeerChat session = getP2PSession();
if (session != null) {
session.unRegisterEventHandler(subscriber);
}
}
}
/**
*
* @param participant
@ -453,6 +415,20 @@ public class VenueSession extends BaseSession implements IVenueSession,
}
}
@Override
public void sendTransferRole(String participant, ParticipantRole role)
throws CollaborationException {
if (participant != null && role != ParticipantRole.PARTICIPANT) {
TransferRoleCommand trc = new TransferRoleCommand();
trc.setRole(role);
trc.setUser(participant);
String message = Tools.marshallData(trc);
if (message != null) {
sendTextMessage(message);
}
}
}
/**
* Get the identification of the user who is the DataProvider.
*