1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-04 07:35:24 +02:00

[180602] [api] Remove Communications Daemon and associated classes. Got rid of the daemon, daemon listener, communications preference page, start/stop daemon action and all related preference constants, messages, labels, tooltips and F1 help messages.

This commit is contained in:
Kushal Munir 2007-04-03 01:22:11 +00:00
parent 2f54eead46
commit a5179f9821
15 changed files with 1 additions and 872 deletions

View file

@ -920,15 +920,6 @@ selected matches in that file will also be removed from the view.</description>
</description>
</context>
<!-- General RSE communications preference page -->
<context id="cmmp0000">
<description>This is the RSE communications preferences page. These preferences are not specific to any single RSE connection. The <b>RSE communications daemon</b> can be used by local Workbench functions to listen for incoming socket requests from remote systems. The daemon can be started and stopped from the pull down menu in the RSE's Remote Systems view.
Use the start RSE communications daemon checkbox to automatically start the daemon when the Workbench is started.
Use the port preference to change which local TCP/IP port the daemon uses to listen for incoming requests. A valid TCP/IP port number must be entered. If the port is changed and the daemon is currently running then the daemon will be stopped and restarted on the new port when the preference page is closed.</description>
</context>
<!-- file cache preference page -->
<context id="fchp0000">
<description>This is the RSE file cache preference page.

View file

@ -726,13 +726,7 @@ public class SystemResources extends NLS
public static String RESID_PERCONNECTION_FILTERPOOL;
// RSE Communication Perferences
public static String RESID_PREF_COMMUNICATIONS_TITLE;
public static String RESID_PREF_DAEMON_PORT_LABEL;
public static String RESID_PREF_DAEMON_PORT_TOOLTIP;
public static String RESID_PREF_DAEMON_AUTOSTART_LABEL;
public static String RESID_PREF_DAEMON_AUTOSTART_TOOLTIP;
// RSE Communication Preferences
public static String RESID_PREF_IP_ADDRESS_LABEL;
public static String RESID_PREF_IP_AUTO_LABEL;
public static String RESID_PREF_IP_AUTO_TOOLTIP;

View file

@ -89,12 +89,6 @@ RESID_PREF_SYSTYPE_COLHDG_USERID=Default User ID
##############################################################
# Preference pages for general communications
##############################################################
RESID_PREF_COMMUNICATIONS_TITLE=RSE Communications Preferences
RESID_PREF_DAEMON_PORT_LABEL=RSE communications daemon port number (1 - 65536)
RESID_PREF_DAEMON_PORT_TOOLTIP=Enter the local port number for the daemon to listen on
RESID_PREF_DAEMON_AUTOSTART_LABEL=Start RSE communications daemon on Workbench startup
RESID_PREF_DAEMON_AUTOSTART_TOOLTIP=Select the checkbox to start daemon on startup
RESID_PREF_IP_ADDRESS_LABEL= Workstation network address
RESID_PREF_IP_AUTO_LABEL= Automatically detect IP address of workstation
RESID_PREF_IP_AUTO_TOOLTIP= Allow automatic detection of the IP address of your workstation. This setting should work in most cases
@ -1098,11 +1092,6 @@ ACTION_SELECT_INPUT_LABEL=Select Input...
ACTION_SELECT_INPUT_DLG=Select Input
ACTION_SELECT_INPUT_TOOLTIP=Select the input for the view
ACTION_DAEMON_START_LABEL=Start Communications Daemon
ACTION_DAEMON_START_TOOLTIP=Start the RSE communications daemon
ACTION_DAEMON_STOP_LABEL=Stop Communications Daemon
ACTION_DAEMON_STOP_TOOLTIP=Stop the RSE communications daemon
ACTION_SELECTCONNECTION_LABEL=Select Connection
ACTION_SELECTCONNECTION_TOOLTIP=Bring up a dialog for selecting a connection

View file

@ -1,93 +0,0 @@
/********************************************************************************
* Copyright (c) 2002, 2006 IBM Corporation. All rights reserved.
* This program and the accompanying materials are made available under the terms
* of the Eclipse Public License v1.0 which accompanies this distribution, and is
* available at http://www.eclipse.org/legal/epl-v10.html
*
* Initial Contributors:
* The following IBM employees contributed to the Remote System Explorer
* component that contains this file: David McKnight, Kushal Munir,
* Michael Berger, David Dykstal, Phil Coulthard, Don Yantzi, Eric Simpson,
* Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley.
*
* Contributors:
* {Name} (company) - description of contribution.
********************************************************************************/
package org.eclipse.rse.internal.ui.actions;
import org.eclipse.jface.action.IAction;
import org.eclipse.rse.core.comm.SystemCommunicationsDaemon;
import org.eclipse.rse.internal.ui.SystemResources;
import org.eclipse.rse.ui.RSEUIPlugin;
import org.eclipse.rse.ui.actions.SystemBaseAction;
import org.eclipse.swt.widgets.Shell;
/**
* Action to start and stop RSE communications daemon
*/
public class SystemStartCommunicationsDaemonAction extends SystemBaseAction implements IAction
{
/**
* Constructor
*
* @param shell
*/
public SystemStartCommunicationsDaemonAction(Shell shell)
{
super(SystemResources.ACTION_DAEMON_STOP_LABEL,
SystemResources.ACTION_DAEMON_STOP_TOOLTIP,
shell);
setHelp(RSEUIPlugin.HELPPREFIX + "dmna0000"); //$NON-NLS-1$
if (!SystemCommunicationsDaemon.isAutoStart() || !SystemCommunicationsDaemon.getInstance().isRunning())
{
setActionLabelToStart();
}
SystemCommunicationsDaemon.setAction(this);
}
/* (non-Javadoc)
* @see org.eclipse.jface.action.IAction#run()
*/
public void run() {
SystemCommunicationsDaemon daemon = SystemCommunicationsDaemon.getInstance();
if (daemon.isRunning())
{
daemon.stopDaemon();
// Change the menu label for the action
setActionLabelToStart();
}
else
{
daemon.startDaemon();
// Change the menu label for the action
setActionLabelToStop();
}
}
/**
* Helper method for changing the action text and tooltip to start
*/
public void setActionLabelToStart()
{
setText(SystemResources.ACTION_DAEMON_START_LABEL);
setToolTipText(SystemResources.ACTION_DAEMON_START_TOOLTIP);
}
/**
* Helper method for changing the action text and tooltip to stop
*/
public void setActionLabelToStop()
{
setText(SystemResources.ACTION_DAEMON_STOP_LABEL);
setToolTipText(SystemResources.ACTION_DAEMON_STOP_TOOLTIP);
}
}

View file

@ -1,123 +0,0 @@
/********************************************************************************
* Copyright (c) 2002, 2006 IBM Corporation. All rights reserved.
* This program and the accompanying materials are made available under the terms
* of the Eclipse Public License v1.0 which accompanies this distribution, and is
* available at http://www.eclipse.org/legal/epl-v10.html
*
* Initial Contributors:
* The following IBM employees contributed to the Remote System Explorer
* component that contains this file: David McKnight, Kushal Munir,
* Michael Berger, David Dykstal, Phil Coulthard, Don Yantzi, Eric Simpson,
* Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley.
*
* Contributors:
* {Name} (company) - description of contribution.
********************************************************************************/
package org.eclipse.rse.internal.ui.propertypages;
import org.eclipse.jface.preference.FieldEditorPreferencePage;
import org.eclipse.jface.preference.IntegerFieldEditor;
import org.eclipse.rse.core.comm.SystemCommunicationsDaemon;
import org.eclipse.rse.internal.ui.SystemResources;
import org.eclipse.rse.ui.ISystemMessages;
import org.eclipse.rse.ui.ISystemPreferencesConstants;
import org.eclipse.rse.ui.Mnemonics;
import org.eclipse.rse.ui.RSEUIPlugin;
import org.eclipse.rse.ui.SystemWidgetHelpers;
import org.eclipse.rse.ui.propertypages.SystemBooleanFieldEditor;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPreferencePage;
import org.eclipse.ui.PlatformUI;
/**
* Preference page for generic Remote System communication preferences
*/
public class SystemCommunicationsPreferencePage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage
{
private IntegerFieldEditor portEditor;
/**
* Constructor
*/
public SystemCommunicationsPreferencePage()
{
super(GRID);
setPreferenceStore(RSEUIPlugin.getDefault().getPreferenceStore());
// setDescription(SystemResources.RESID_PREF_COMMUNICATIONS_TITLE); dwd description is not readable by screen reader
}
/**
* Configure the composite. We intercept to set the help.
*/
public void createControl(Composite parent)
{
super.createControl(parent);
PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(), RSEUIPlugin.HELPPREFIX + "cmmp0000"); //$NON-NLS-1$
}
/**
*
*/
protected void createFieldEditors()
{
Composite parent= getFieldEditorParent();
// Auto-start the daemon preference
SystemBooleanFieldEditor autoStartEditor = new SystemBooleanFieldEditor(
ISystemPreferencesConstants.DAEMON_AUTOSTART,
SystemResources.RESID_PREF_DAEMON_AUTOSTART_LABEL,
parent
);
autoStartEditor.setToolTipText(SystemResources.RESID_PREF_DAEMON_AUTOSTART_TOOLTIP);
addField(autoStartEditor);
// Daemon port preference
portEditor = new IntegerFieldEditor(
ISystemPreferencesConstants.DAEMON_PORT,
SystemResources.RESID_PREF_DAEMON_PORT_LABEL,
parent
);
portEditor.setValidRange(1, 65536);
portEditor.setErrorMessage(RSEUIPlugin.getPluginMessage(ISystemMessages.MSG_VALIDATE_PORT_NOTVALID).getLevelOneText());
addField(portEditor);
portEditor.getTextControl(parent).setToolTipText(SystemResources.RESID_PREF_DAEMON_PORT_TOOLTIP);
SystemWidgetHelpers.setHelp(portEditor.getTextControl(parent), RSEUIPlugin.HELPPREFIX + "cmmp0000"); //$NON-NLS-1$
(new Mnemonics()).setOnPreferencePage(true).setMnemonics(parent);
}
/**
* Inherited method.
*/
public void init(IWorkbench workbench)
{
}
/**
* @see FieldEditorPreferencePage#performOk()
*/
public boolean performOk() {
// Restart the communications daemon if required
int port = portEditor.getIntValue();
SystemCommunicationsDaemon daemon = SystemCommunicationsDaemon.getInstance();
// Restart communications daemon if it is already running and the
// port number has changed
if (daemon.isRunning() && port != daemon.getPort()) {
SystemCommunicationsDaemon.getInstance().stopDaemon();
SystemCommunicationsDaemon.getInstance().startDaemon();
}
return super.performOk();
}
}

View file

@ -63,7 +63,6 @@ import org.eclipse.rse.internal.ui.actions.SystemCollapseAllAction;
import org.eclipse.rse.internal.ui.actions.SystemPreferenceQualifyConnectionNamesAction;
import org.eclipse.rse.internal.ui.actions.SystemPreferenceRestoreStateAction;
import org.eclipse.rse.internal.ui.actions.SystemPreferenceShowFilterPoolsAction;
import org.eclipse.rse.internal.ui.actions.SystemStartCommunicationsDaemonAction;
import org.eclipse.rse.internal.ui.actions.SystemWorkWithProfilesAction;
import org.eclipse.rse.model.ISystemResourceChangeEvents;
import org.eclipse.rse.model.SystemRegistry;
@ -696,17 +695,6 @@ public class SystemViewPart
SystemCascadingPreferencesAction preferencesAction = new SystemCascadingPreferencesAction(shell);
menuMgr.add(preferencesAction.getSubMenu());
menuMgr.add(new Separator());
menuMgr.add(new SystemStartCommunicationsDaemonAction(shell));
if (viewPart != null)
{
/*
SystemCascadingTeamAction teamAction = new SystemCascadingTeamAction(shell, viewPart);
menuMgr.add(new Separator());
menuMgr.add(teamAction.getSubMenu());
*/
}
SystemViewMenuListener menuListener = new SystemViewMenuListener(true); // true says this is a persistent menu
if (viewPart instanceof ISystemMessageLine)
menuListener.setShowToolTipText(true, (ISystemMessageLine) viewPart);

View file

@ -23,16 +23,6 @@ public interface ISystemPreferencesConstants {
* root
*/
public static final String ROOT = "org.eclipse.rse.preferences."; //$NON-NLS-1$
/*
* dstore preference keys
*/
public static final String DAEMON_AUTOSTART = ROOT + "daemon.autostart"; //$NON-NLS-1$
public static final String DAEMON_PORT = ROOT + "daemon.port"; //$NON-NLS-1$
/*
* dstore preference default values
*/
public static final boolean DEFAULT_DAEMON_AUTOSTART = false;
public static final int DEFAULT_DAEMON_PORT = 4300;
/*
* uda preference keys
*/

View file

@ -38,7 +38,6 @@ import org.eclipse.rse.core.SystemBasePlugin;
import org.eclipse.rse.core.SystemResourceListener;
import org.eclipse.rse.core.SystemResourceManager;
import org.eclipse.rse.core.comm.ISystemKeystoreProvider;
import org.eclipse.rse.core.comm.SystemCommunicationsDaemon;
import org.eclipse.rse.core.comm.SystemKeystoreProviderManager;
import org.eclipse.rse.core.model.ISystemProfile;
import org.eclipse.rse.core.model.ISystemProfileManager;
@ -104,18 +103,9 @@ public class RSEUIPlugin extends SystemBasePlugin implements ISystemMessageProvi
IProject remoteSystemsProject = SystemResourceManager.getRemoteSystemsProject();
SystemResourceListener listener = SystemResourceListener.getListener(remoteSystemsProject);
SystemResourceManager.startResourceEventListening(listener);
// Auto-start RSE communications daemon if required
SystemCommunicationsDaemon daemon = SystemCommunicationsDaemon.getInstance();
if (SystemCommunicationsDaemon.isAutoStart()) {
daemon.startDaemon(false);
}
registerDynamicPopupMenuExtensions();
registerKeystoreProviders();
// new support to allow products to not pre-create a local connection
if (SystemResourceManager.isFirstTime() && SystemPreferencesManager.getShowLocalConnection()) {
@ -615,12 +605,6 @@ public class RSEUIPlugin extends SystemBasePlugin implements ISystemMessageProvi
// remove workspace listener for our project
SystemResourceManager.endResourceEventListening();
// Stop RSE communications daemon if required, the stopDaemon method checks if the daemon is running or not
SystemCommunicationsDaemon daemon = SystemCommunicationsDaemon.getInstance();
daemon.stopDaemon();
// call this last
super.stop(context);

View file

@ -79,7 +79,6 @@ public class SystemPreferencesManager {
public static void initDefaults() {
migrateCorePreferences();
initDefaultsUI();
initDefaultsComm();
savePreferences();
}
@ -105,17 +104,6 @@ public class SystemPreferencesManager {
boolean value = (property == null) ? defaultValue : property.equals(Boolean.toString(true));
return value;
}
/**
* Set default communications preferences
*/
private static void initDefaultsComm() {
RSEUIPlugin ui = RSEUIPlugin.getDefault();
Preferences store = ui.getPluginPreferences();
store.setDefault(ISystemPreferencesConstants.DAEMON_AUTOSTART, ISystemPreferencesConstants.DEFAULT_DAEMON_AUTOSTART);
store.setDefault(ISystemPreferencesConstants.DAEMON_PORT, ISystemPreferencesConstants.DEFAULT_DAEMON_PORT);
ui.savePluginPreferences();
}
public static boolean getShowLocalConnection() {
return showLocalConnection;

View file

@ -73,7 +73,6 @@ Perspective.Explorer = Remote System Explorer
PreferencePage.Logging = Logging
PreferencePage.RemoteSystems = Remote Systems
PreferencePage.Signon = Passwords
PreferencePage.Communications = Communications
Nature.RemoteSystemsNature = Remote System Nature
Nature.RemoteSystemsTempNature = Remote System Temp Nature

View file

@ -164,12 +164,6 @@ Contributors:
class="org.eclipse.rse.ui.propertypages.SignonPreferencePage"
id="org.eclipse.rse.ui.preferences.SignonPreferencePage">
</page>
<page
name="%PreferencePage.Communications"
category="org.eclipse.rse.ui.preferences.RemoteSystemsPreferencePage"
class="org.eclipse.rse.internal.ui.propertypages.SystemCommunicationsPreferencePage"
id="org.eclipse.rse.ui.preferences.SystemCommunicationsPreferencePage">
</page>
</extension>
<extension

View file

@ -1,44 +0,0 @@
/********************************************************************************
* Copyright (c) 2002, 2006 IBM Corporation. All rights reserved.
* This program and the accompanying materials are made available under the terms
* of the Eclipse Public License v1.0 which accompanies this distribution, and is
* available at http://www.eclipse.org/legal/epl-v10.html
*
* Initial Contributors:
* The following IBM employees contributed to the Remote System Explorer
* component that contains this file: David McKnight, Kushal Munir,
* Michael Berger, David Dykstal, Phil Coulthard, Don Yantzi, Eric Simpson,
* Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley.
*
* Contributors:
* {Name} (company) - description of contribution.
********************************************************************************/
package org.eclipse.rse.core.comm;
import java.net.Socket;
/**
* This interface allows any class to use the RSE communications daemon to
* accept socket requests from a remote function. When a the RSE communications
* daemon accepts a socket request it reads the first 4 bytes, converts this to
* an integer and compares the integer against all registered
* ISystemCommunicationDaemonListeners, handing the socket off to the first match.
*/
public interface ISystemCommunicationsDaemonHandler {
/**
* The handleRequest method is invoked by the RSE communications daemon when
* a new socket connection is established and the requestKey matches for this
* handler. The handleRequest method will be invoked on a new thread.
* <br><br>
* It is the implementors responsability to close the socket and clean
* up all associated resources (like the InputStream) when finished.
*
* @param socket The communications socket connected to the remote peer. The only
* thing read of the socket will have been the request key.
*/
public void handleRequest(Socket socket, int requestKey);
}

View file

@ -1,32 +0,0 @@
/********************************************************************************
* Copyright (c) 2002, 2006 IBM Corporation. All rights reserved.
* This program and the accompanying materials are made available under the terms
* of the Eclipse Public License v1.0 which accompanies this distribution, and is
* available at http://www.eclipse.org/legal/epl-v10.html
*
* Initial Contributors:
* The following IBM employees contributed to the Remote System Explorer
* component that contains this file: David McKnight, Kushal Munir,
* Michael Berger, David Dykstal, Phil Coulthard, Don Yantzi, Eric Simpson,
* Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley.
*
* Contributors:
* {Name} (company) - description of contribution.
********************************************************************************/
package org.eclipse.rse.core.comm;
/**
* Listener interface for thoes that are interested in events from the SystemCommunicationsDaemon.
*
* @author yantzi
*/
public interface ISystemCommunicationsDaemonListener
{
/**
* This method is invoked whenever the state of the SystemCommunicationsDaemon changes. For example
* if the daemon is started, stopped or ends in error.
*/
public void daemonStateChanged(SystemCommunicationsDaemonEvent event);
}

View file

@ -1,446 +0,0 @@
/********************************************************************************
* Copyright (c) 2002, 2006 IBM Corporation. All rights reserved.
* This program and the accompanying materials are made available under the terms
* of the Eclipse Public License v1.0 which accompanies this distribution, and is
* available at http://www.eclipse.org/legal/epl-v10.html
*
* Initial Contributors:
* The following IBM employees contributed to the Remote System Explorer
* component that contains this file: David McKnight, Kushal Munir,
* Michael Berger, David Dykstal, Phil Coulthard, Don Yantzi, Eric Simpson,
* Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley.
*
* Contributors:
* {Name} (company) - description of contribution.
********************************************************************************/
package org.eclipse.rse.core.comm;
import java.io.IOException;
import java.io.InputStream;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Hashtable;
import java.util.List;
import java.util.Map;
import java.util.Vector;
import org.eclipse.rse.core.SystemBasePlugin;
import org.eclipse.rse.internal.ui.actions.SystemStartCommunicationsDaemonAction;
import org.eclipse.rse.services.clientserver.messages.SystemMessage;
import org.eclipse.rse.ui.ISystemMessages;
import org.eclipse.rse.ui.ISystemPreferencesConstants;
import org.eclipse.rse.ui.RSEUIPlugin;
import org.eclipse.rse.ui.actions.DisplaySystemMessageAction;
import org.eclipse.swt.widgets.Display;
/**
* Communications daemon that can be used by other functions for receiving incoming socket
* requests. Functions need to implement the ICommunicationsDaemonHandler interface and register
* a unique 4 byte id (as an integer) which the server sends across the socket to let the
* daemon know which local function to pass the socket off to.
*/
public class SystemCommunicationsDaemon extends Thread {
private static final String THREAD_NAME = "RSE daemon"; //$NON-NLS-1$
// Communication Daemon Request Handlers
private static Map handlers = new Hashtable(50);
private static List _listeners = new Vector(10);
// Starting point for dynamically generated keys
private static int _nextKey = 0xD0000000;
// Instance fields
private static SystemCommunicationsDaemon inst = null;
private boolean halt = false;
private ServerSocket serverSocket;
private boolean displayErrors = true;
// We need to hold a reference to the _startAction in order to change the "Stop Daemon" label
// to "Start Daemon" if the daemon fails.
private static SystemStartCommunicationsDaemonAction _startAction;
/**
* Inner class for running ICommunicationHandlers on a new thread. This is done
* for two main reasons:
* 1. Allow the communication daemon to continue handling requests while
* processing other requests (this is important because some requests
* like the program verifiers run long.
* 2. Keep the communications daemon safe from crashes (unhandled exceptions)
* in the communication handlers.
*/
protected class CommunicationHandlerThread extends Thread
{
private ISystemCommunicationsDaemonHandler _handler;
private Socket _socket;
private int _requestKey;
protected CommunicationHandlerThread(ISystemCommunicationsDaemonHandler handler, Socket socket, int requestKey)
{
_handler = handler;
_socket = socket;
_requestKey = requestKey;
}
public void run()
{
_handler.handleRequest(_socket, _requestKey);
}
}
/**
* Singleton, so constructor is private. Use the getInstance method
* to retrieve and instance of this class.
*/
private SystemCommunicationsDaemon() {
}
/**
* Returns the singleton instance of this class. If the an instance
* has already been created then it is returned, otherwise a new
* instance is created and returned.
*/
public static synchronized SystemCommunicationsDaemon getInstance()
{
if (inst == null)
{
inst = new SystemCommunicationsDaemon();
}
return inst;
}
/*
* Stop the communications daemon
*/
private void halt() {
halt = true;
if (serverSocket != null) {
try {
serverSocket.close();
// yantzi:2.1.2 (defect 49812) wait for RSE daemon thread to finish (wait at most 5 seconds)
if (inst != null)
{
inst.join(5000);
}
}
catch (IOException e)
{
SystemBasePlugin.logError("RSE Communications daemon: Unable to close socket", e); //$NON-NLS-1$
}
catch (InterruptedException e)
{
// some other thread interrupted this one (which should not happen
SystemBasePlugin.logError("SystemCommunicationsDaemon.halt", e); //$NON-NLS-1$
}
}
}
/**
* @see Thread#run()
*/
public void run() {
byte[] buffer;
Socket socket = null;
InputStream in = null;
setName(THREAD_NAME);
// Create server socket and start listening
int port = RSEUIPlugin.getDefault().getPreferenceStore().getInt(ISystemPreferencesConstants.DAEMON_PORT);
try {
serverSocket = new ServerSocket(port);
fireStateChangeEvent(SystemCommunicationsDaemonEvent.STARTED);
// Process incoming socket connections
while (!halt) {
socket = serverSocket.accept();
// Pass incoming socket off to the appropriate handler,
// the first four bytes (integer) determines the handler.
in = socket.getInputStream();
buffer = new byte[4];
in.read(buffer);
// RequestKey (integer) must be sent as Big Endian (high order bits first)
// convert first four bytes to Java integer
int requestKey = 0 | (buffer[0] << 24);
requestKey = requestKey | ((buffer[1] << 24) >>> 8);
requestKey = requestKey | ((buffer[2] << 24) >>> 16);
requestKey = requestKey | ((buffer[3] << 24) >>> 24);
// yantzi: 5.0.1: changed from asking hanlder for request key to requiring
// handler to provide key when they are registered.
ISystemCommunicationsDaemonHandler handler = (ISystemCommunicationsDaemonHandler) handlers.get(new Integer(requestKey));
if (handler != null)
{
new CommunicationHandlerThread(handler, socket, requestKey).start();
}
else
{
// handler not found
SystemBasePlugin.logWarning("SystemCommunicationsDaemon: Handler not found for key " + requestKey); //$NON-NLS-1$
socket.close();
}
}
} catch (IOException e) {
if (!halt)
{
SystemBasePlugin.logError("CommunicationsDaemon, IOException occured during communications daemon request",e); //$NON-NLS-1$
fireStateChangeEvent(SystemCommunicationsDaemonEvent.STOPPED_IN_ERROR);
// yantzi:2.1.2 (defect 51016) Suppress error messages when workbench is first starting up
if (displayErrors)
{
SystemMessage msg = RSEUIPlugin.getPluginMessage(ISystemMessages.MSG_COMM_DAEMON_NOTSTARTED);
msg.makeSubstitution(new Integer(port));
Display.getDefault().asyncExec(new DisplaySystemMessageAction(msg));
}
// Reset label of action
if (_startAction != null)
{
_startAction.setActionLabelToStart();
}
}
else
{
fireStateChangeEvent(SystemCommunicationsDaemonEvent.STOPPED);
}
} finally {
serverSocket = null;
//dy need to get a new thread next time in order to re-run
inst = null;
}
}
/**
* Start the communications daemon if it is not already running
*/
public synchronized void startDaemon()
{
startDaemon(true);
}
/**
* Start the communications daemon if it is not already running
*
* @param displayErrors true if error messages should be displayed, false
* if they should be not be displayed.
*/
public synchronized void startDaemon(boolean displayErrors) {
if (!isRunning())
{
SystemBasePlugin.logDebugMessage("CommunicationsDaemon.startDaemon()", "Starting iSeries Communications Daemon"); //$NON-NLS-1$ //$NON-NLS-2$
//yantzi:2.1.2 added boolean to suppress error messages when workbench is first being started
if (_startAction != null)
{
_startAction.setActionLabelToStop();
}
// Just in case someone cached an old copy of the daemon ...
SystemCommunicationsDaemon daemon = getInstance();
daemon.displayErrors = displayErrors;
daemon.start();
}
else
{
SystemBasePlugin.logDebugMessage("CommunicationsDaemon.startDaemon()", "Daemon already started"); //$NON-NLS-1$ //$NON-NLS-2$
}
}
/**
* Stops the communications daemon if it is running
*/
public synchronized void stopDaemon() {
if (isRunning())
{
if (_startAction != null)
{
_startAction.setActionLabelToStart();
}
SystemBasePlugin.logDebugMessage("RSE CommunicationsDaemon.stopDaemon()", "Stopping iSeries Communications Daemon"); //$NON-NLS-1$ //$NON-NLS-2$
getInstance().halt();
// Need to get rid of the old Thread object and create a new
// one next time (calling start on the same thread object twice
// does not seem to work. DY
inst = null;
}
else
{
SystemBasePlugin.logDebugMessage("RSE CommunicationsDaemon.stopDaemon()", "Daemon already stopped"); //$NON-NLS-1$ //$NON-NLS-2$
}
}
/**
* Returns the port the daemon is currently running on, or zero if the
* daemon is not running.
*/
public synchronized int getPort() {
if (isRunning())
{
return serverSocket.getLocalPort();
}
return 0;
}
/**
* Check to see if the iSeries communications daemon is running
*
* @return true if the communications daemon is running, false if it
* is not running
*/
public synchronized boolean isRunning() {
return serverSocket != null;
}
//
// Helper methods
//
/**
* Returns the user preference for auto-starting the communications daemon
* when the Workbench starts.
*/
public static boolean isAutoStart() {
return RSEUIPlugin.getDefault().getPreferenceStore().getBoolean(ISystemPreferencesConstants.DAEMON_AUTOSTART);
}
/**
* Add a new CommunicationsDaemonHandler
*
* @see ISystemCommunicationsDaemonHandler
*
* @param requestKey
*
* The request key must be four byte integer key used by this handler. This
* is the first thing that much be sent over the socket from the corresponding
* client / server when connecting to the RSE communications daemon. The daemon
* when then compare this integer against all registered handlers and pass off the
* socket connection (via the handleRequest method) to the first match.
*
* Use the SystemCommunicationsDaemon.getInstance().addCommunicationsDaemonHandler(...)
* method to register with the daemon. There is also a corresponding remove method.
*
* Known handlers:
* RSEInteractiveJobHandler 0x67DF7A14
* CODECommIntegrationHandler 0xA387E2CD
* iSeries DebugEngine
*
* <b>The range of integers from 0xD0000000 to 0xFFFFFFFF is reserved for dyanmically
* generated kes.
*
* @return true if the handler was registered, false it the handler was not registered because
* the requestKey is already being used
*/
public boolean addCommunicationsDaemonHandler(ISystemCommunicationsDaemonHandler handler, int requestKey)
{
Integer key = new Integer(requestKey);
if (!handlers.containsKey(key))
{
handlers.put(key, handler);
return true;
}
return false;
}
/**
* Remove a CommunicationsDaemonHandler
*
* @see ISystemCommunicationsDaemonHandler
*/
public void removeCommunicationsDaemonHandler(int requestKey)
{
handlers.remove(new Integer(requestKey));
}
/**
* Sets the SystemStartCommunicationsDaemon action. This is used to change the
* label of the action if the daemon fails to start or fails during regular
* operation.
*/
public static void setAction(SystemStartCommunicationsDaemonAction action)
{
_startAction = action;
}
/**
* getNextKey() can be called to generated a dynamic key used by any communications
* handler. They generated key is guaranteed to be unique. Callers still need to
* call the addCommunicationsDaemonHandler() method to register their handler.
*/
public static int getNextKey()
{
int key;
synchronized (handlers)
{
key = _nextKey;
if (_nextKey == 0xFFFFFFFF)
{
_nextKey = 0xD0000000;
}
else
{
_nextKey++;
}
}
return key;
}
/**
* Add an ISystemCommunicationsDaemonListener listener to receive state change events from the SystemCommunicationsDaemon.
*/
public static void addDaemonListener(ISystemCommunicationsDaemonListener listener)
{
if (!_listeners.contains(listener))
{
_listeners.add(listener);
}
}
/**
* Remove the ISystemCommunicationsDaemonListener listener.
*/
public static void removeDaemonListener(ISystemCommunicationsDaemonListener listener)
{
_listeners.remove(listener);
}
/**
* Fire a state change event for the daemon
*/
private static void fireStateChangeEvent(int newstate)
{
if (_listeners.size() > 0)
{
SystemCommunicationsDaemonEvent event = new SystemCommunicationsDaemonEvent(newstate);
for (int i = 0; i < _listeners.size(); i++)
{
((ISystemCommunicationsDaemonListener) _listeners.get(i)).daemonStateChanged(event);
}
}
}
}

View file

@ -1,50 +0,0 @@
/********************************************************************************
* Copyright (c) 2002, 2006 IBM Corporation. All rights reserved.
* This program and the accompanying materials are made available under the terms
* of the Eclipse Public License v1.0 which accompanies this distribution, and is
* available at http://www.eclipse.org/legal/epl-v10.html
*
* Initial Contributors:
* The following IBM employees contributed to the Remote System Explorer
* component that contains this file: David McKnight, Kushal Munir,
* Michael Berger, David Dykstal, Phil Coulthard, Don Yantzi, Eric Simpson,
* Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley.
*
* Contributors:
* {Name} (company) - description of contribution.
********************************************************************************/
package org.eclipse.rse.core.comm;
/**
* Event data for the SystemCommunicationsDaemon.
*
* @author yantzi
*/
public class SystemCommunicationsDaemonEvent
{
// Communications daemon event types
public static final int STARTED = 1;
public static final int STOPPED = 2;
public static final int STOPPED_IN_ERROR = 3;
private int state;
/**
* Constructor for SystemCommunicationsDaemonEvent
*
* @state The new state for the daemon.
*/
public SystemCommunicationsDaemonEvent(int state)
{
this.state = state;
}
/**
* Get the new state for the communications daemon.
*/
public int getState()
{
return state;
}
}