Issue #2630 added away timeout for collaboration inactivity

eclipse job in connection subscriber
preferences added to collaboration prefs page


Former-commit-id: 7e952c5ba8 [formerly 24190efb75] [formerly 7e952c5ba8 [formerly 24190efb75] [formerly 57fb953b8d [formerly c6fded1429e44033bb989c1d9caaac87c72eb440]]]
Former-commit-id: 57fb953b8d
Former-commit-id: 7410c36783 [formerly 53273c4e5a]
Former-commit-id: 07b9ab8b7b
This commit is contained in:
Brian Clements 2014-01-14 15:30:31 -06:00
parent c934358ccc
commit 72b75a821d
5 changed files with 226 additions and 7 deletions

View file

@ -19,6 +19,7 @@
**/
package com.raytheon.uf.viz.collaboration.ui;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IWorkbench;
@ -48,6 +49,7 @@ import com.raytheon.uf.viz.collaboration.comm.provider.user.UserId;
import com.raytheon.uf.viz.collaboration.display.data.SessionColorManager;
import com.raytheon.uf.viz.collaboration.display.data.SharedDisplaySessionMgr;
import com.raytheon.uf.viz.collaboration.ui.actions.PeerToPeerChatAction;
import com.raytheon.uf.viz.collaboration.ui.jobs.AwayTimeOut;
import com.raytheon.uf.viz.collaboration.ui.prefs.CollabPrefConstants;
import com.raytheon.uf.viz.collaboration.ui.session.CollaborationSessionView;
import com.raytheon.uf.viz.collaboration.ui.session.PeerToPeerView;
@ -67,6 +69,7 @@ import com.raytheon.viz.ui.views.CaveWorkbenchPageManager;
* ------------ ---------- ----------- --------------------------
* Jun 8, 2012 njensen Initial creation
* Dec 18, 2013 2562 bclement fixed venue invite
* Jan 14, 2014 2630 bclement added away timeout
*
* </pre>
*
@ -83,6 +86,8 @@ public class ConnectionSubscriber {
private IWorkbenchListener wbListener;
private final AwayTimeOut awayTimeOut = new AwayTimeOut();
private ConnectionSubscriber() {
}
@ -142,12 +147,15 @@ public class ConnectionSubscriber {
}
};
PlatformUI.getWorkbench().addWorkbenchListener(wbListener);
awayTimeOut.setSystem(true);
awayTimeOut.setPriority(Job.LONG);
awayTimeOut.schedule();
}
}
private void dispose(CollaborationConnection connection) {
if (connection != null) {
awayTimeOut.cancel();
try {
ISession p2pSession = connection.getPeerToPeerSession();
p2pSession.unregisterEventHandler(this);

View file

@ -0,0 +1,192 @@
/**
* 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.jobs;
import java.awt.MouseInfo;
import java.awt.Point;
import java.awt.PointerInfo;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.jface.preference.IPersistentPreferenceStore;
import org.jivesoftware.smack.packet.Presence;
import org.jivesoftware.smack.packet.Presence.Mode;
import com.raytheon.uf.common.status.IUFStatusHandler;
import com.raytheon.uf.common.status.UFStatus;
import com.raytheon.uf.common.time.util.TimeUtil;
import com.raytheon.uf.viz.collaboration.comm.identity.CollaborationException;
import com.raytheon.uf.viz.collaboration.comm.provider.Tools;
import com.raytheon.uf.viz.collaboration.comm.provider.session.CollaborationConnection;
import com.raytheon.uf.viz.collaboration.ui.Activator;
import com.raytheon.uf.viz.collaboration.ui.prefs.CollabPrefConstants;
/**
* Monitors user input to change collaboration status to away if inactive for a
* set period of time
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Jan 14, 2014 2630 bclement Initial creation
*
* </pre>
*
* @author bclement
* @version 1.0
*/
public class AwayTimeOut extends Job {
private static final IUFStatusHandler log = UFStatus
.getHandler(AwayTimeOut.class);
// poll every 30 seconds when active
public static final long ACTIVE_POLL_PERIOD = 30 * TimeUtil.MILLIS_PER_SECOND;
// look for new activity every second when away
public static final long AWAY_POLL_PERIOD = TimeUtil.MILLIS_PER_SECOND;
private Point previousLocation;
private long previousTime;
private boolean timerSetAway = false;
private Presence previousPresence;
/**
* @param name
* job name
* @param period
* how often to poll for activity
*/
public AwayTimeOut(String name) {
super(name);
this.previousLocation = getMouseLocation();
this.previousTime = System.currentTimeMillis();
}
/**
* Default constructor, gets configuration from system properties
*/
public AwayTimeOut() {
this("Away Timout Monitor");
}
/* (non-Javadoc)
* @see org.eclipse.core.runtime.jobs.Job#run(org.eclipse.core.runtime.IProgressMonitor)
*/
@Override
protected IStatus run(IProgressMonitor monitor) {
try {
IPersistentPreferenceStore prefs = Activator.getDefault()
.getPreferenceStore();
boolean idleEnabled = prefs
.getBoolean(CollabPrefConstants.AWAY_ON_IDLE);
CollaborationConnection connection = CollaborationConnection
.getConnection();
if (!idleEnabled || connection == null || !connection.isConnected()) {
return Status.OK_STATUS;
}
Point location = getMouseLocation();
long time = System.currentTimeMillis();
long sinceLastChange = time - previousTime;
long timeoutMillis = prefs.getInt(CollabPrefConstants.AWAY_TIMEOUT)
* TimeUtil.MILLIS_PER_MINUTE;
if (location.equals(previousLocation)) {
if (sinceLastChange > timeoutMillis) {
goAway();
}
} else {
if (timerSetAway) {
// only set to available if timer changed the status to away
comeBack();
}
this.previousLocation = location;
this.previousTime = time;
}
return Status.OK_STATUS;
} finally {
schedule(timerSetAway ? AWAY_POLL_PERIOD : ACTIVE_POLL_PERIOD);
}
}
/**
* Set user status to away if they are available
*/
private void goAway() {
CollaborationConnection connection = CollaborationConnection
.getConnection();
Presence presence = connection.getPresence();
if (presence.getMode().equals(Mode.available)) {
previousPresence = presence;
Presence newPresence = new Presence(presence.getType(),
presence.getStatus(), presence.getPriority(), Mode.away);
Tools.copyProperties(presence, newPresence);
timerSetAway = sendPresence(connection, newPresence);
}
}
/**
* Restore status to what it was before timeout
*/
private void comeBack() {
if (previousPresence != null) {
CollaborationConnection connection = CollaborationConnection
.getConnection();
sendPresence(connection, previousPresence);
timerSetAway = false;
}
}
/**
* Update user status
*
* @param connection
* @param presence
* @return true if update was successful
*/
private boolean sendPresence(CollaborationConnection connection,
Presence presence) {
boolean rval = false;
try {
connection.getAccountManager().sendPresence(presence);
rval = true;
} catch (CollaborationException e) {
log.error("Unable to change status based on inactivity", e);
}
return rval;
}
/**
* @return current mouse location
*/
private static Point getMouseLocation() {
PointerInfo info = MouseInfo.getPointerInfo();
return info.getLocation();
}
}

View file

@ -20,7 +20,7 @@
package com.raytheon.uf.viz.collaboration.ui.prefs;
/**
* TODO Add Description
* Collaboration preferences constants used to interact with preference store
*
* <pre>
*
@ -29,13 +29,13 @@ package com.raytheon.uf.viz.collaboration.ui.prefs;
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Apr 24, 2012 njensen Initial creation
* Jan 14, 2014 2630 bclement added away on idle constants
*
* </pre>
*
* @author njensen
* @version 1.0
*/
public class CollabPrefConstants {
public static final String P_SERVER = "collaborationServer";
@ -48,6 +48,12 @@ public class CollabPrefConstants {
public static final String AUTO_JOIN = "autojoin";
public static final String AWAY_ON_IDLE = "awayOnIdle";
public static final String AWAY_TIMEOUT = "awayTimeOut";
public static final int AWAY_TIMEOUT_DEFAULT = 10; // ten minutes
public class HttpCollaborationConfiguration {
public static final String P_SESSION_CONFIGURED = "http.sessionConfigured";

View file

@ -26,7 +26,7 @@ import org.jivesoftware.smack.packet.Presence.Mode;
import com.raytheon.uf.viz.collaboration.ui.Activator;
/**
* TODO Add Description
* Initialization for collaboration preference store properties
*
* <pre>
*
@ -35,13 +35,13 @@ import com.raytheon.uf.viz.collaboration.ui.Activator;
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Apr 24, 2012 njensen Initial creation
* Jan 14, 2014 2630 bclement added away on idle defaults
*
* </pre>
*
* @author njensen
* @version 1.0
*/
public class CollabPrefInitializer extends AbstractPreferenceInitializer {
/*
@ -64,6 +64,9 @@ public class CollabPrefInitializer extends AbstractPreferenceInitializer {
store.setDefault(CollabPrefConstants.P_STATUS,
Mode.available.toString());
store.setDefault(CollabPrefConstants.P_MESSAGE, "");
store.setDefault(CollabPrefConstants.AWAY_ON_IDLE, true);
store.setDefault(CollabPrefConstants.AWAY_TIMEOUT,
CollabPrefConstants.AWAY_TIMEOUT_DEFAULT);
}
}

View file

@ -22,6 +22,7 @@ package com.raytheon.uf.viz.collaboration.ui.prefs;
import org.eclipse.jface.preference.BooleanFieldEditor;
import org.eclipse.jface.preference.FieldEditor;
import org.eclipse.jface.preference.FieldEditorPreferencePage;
import org.eclipse.jface.preference.IntegerFieldEditor;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPreferencePage;
@ -29,7 +30,7 @@ import com.raytheon.uf.viz.collaboration.comm.provider.session.CollaborationConn
import com.raytheon.uf.viz.collaboration.ui.Activator;
/**
* TODO Add Description
* Collaboration specific preferences editor
*
* <pre>
*
@ -38,13 +39,13 @@ import com.raytheon.uf.viz.collaboration.ui.Activator;
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Apr 27, 2012 mnash Initial creation
* Jan 14, 2014 2630 bclement added away on idle
*
* </pre>
*
* @author mnash
* @version 1.0
*/
public class CollaborationPreferencePage extends FieldEditorPreferencePage
implements IWorkbenchPreferencePage {
@ -80,6 +81,15 @@ public class CollaborationPreferencePage extends FieldEditorPreferencePage
CollabPrefConstants.AUTO_JOIN, "Join Discussion On Login",
getFieldEditorParent());
this.addField(autojoinColl);
FieldEditor toggleIdle = new BooleanFieldEditor(
CollabPrefConstants.AWAY_ON_IDLE, "Change Status On Idle",
getFieldEditorParent());
this.addField(toggleIdle);
FieldEditor awayTimeOut = new IntegerFieldEditor(
CollabPrefConstants.AWAY_TIMEOUT,
"Minutes Before Becoming Idle:", getFieldEditorParent());
this.addField(awayTimeOut);
}
/*