@Override public void running(IJobChangeEvent event) { fireReadyToAcceptEvent(); } @Override
public WaitForConnectionJob(IProcess waitProcess, ListeningConnector connector, Map<String, Connector.Argument> arguments) { super(getLabel()); fWaitProcess = waitProcess; fConnector = connector; fArguments = arguments; }
/** * Return true if this connector should continue listening for further connections. */ protected boolean continueListening() { return !isTerminated() && (fWaitForConnectionJob != null && !fWaitForConnectionJob.fListeningStopped) && (fConnectionLimit <= 0 || fConnectionLimit - fAccepted > 0); }
@Override public void connect(Map<String, String> arguments, IProgressMonitor monitor, ILaunch launch) throws CoreException { if (monitor == null) { monitor = new NullProgressMonitor(); } monitor.subTask(LaunchingMessages.SocketListenConnector_2); ListeningConnector connector= getListeningConnector(); String portNumberString = arguments.get("port"); //$NON-NLS-1$ if (portNumberString == null) { abort(LaunchingMessages.SocketAttachConnector_Port_unspecified_for_remote_connection__2, null, IJavaLaunchConfigurationConstants.ERR_UNSPECIFIED_PORT); } Map<String, Connector.Argument> acceptArguments = connector.defaultArguments(); Connector.Argument param= acceptArguments.get("port"); //$NON-NLS-1$ param.setValue(portNumberString); // retain default behaviour to accept 1 connection only int connectionLimit = 1; if (arguments.containsKey("connectionLimit")) { //$NON-NLS-1$ connectionLimit = Integer.valueOf(arguments.get("connectionLimit")); //$NON-NLS-1$ } try { monitor.subTask(NLS.bind(LaunchingMessages.SocketListenConnector_3, new String[]{portNumberString})); connector.startListening(acceptArguments); SocketListenConnectorProcess process = new SocketListenConnectorProcess(launch, portNumberString, connectionLimit); process.waitForConnection(connector, acceptArguments); } catch (IOException e) { abort(LaunchingMessages.SocketListenConnector_4, e, IJavaLaunchConfigurationConstants.ERR_REMOTE_VM_CONNECTION_FAILED); } catch (IllegalConnectorArgumentsException e) { abort(LaunchingMessages.SocketListenConnector_4, e, IJavaLaunchConfigurationConstants.ERR_REMOTE_VM_CONNECTION_FAILED); } }
if (isTerminated()){ throw new CoreException(getStatus(LaunchingMessages.SocketListenConnectorProcess_0, null, IJavaLaunchConfigurationConstants.ERR_REMOTE_VM_CONNECTION_FAILED));
/** * Tells the listening connector to stop listening. Ensures * that the socket is closed and the port released. Sets a flag * so that the IOException thrown by the connector's accept method * will be ignored. */ protected void stopListening() { if (!fListeningStopped){ try{ fListeningStopped = true; fConnector.stopListening(fArguments); } catch (IOException e) { done(getStatus(LaunchingMessages.SocketListenConnectorProcess_5, e, IJavaLaunchConfigurationConstants.ERR_REMOTE_VM_CONNECTION_FAILED)); } catch (IllegalConnectorArgumentsException e) { done(getStatus(LaunchingMessages.SocketListenConnectorProcess_5, e, IJavaLaunchConfigurationConstants.ERR_REMOTE_VM_CONNECTION_FAILED)); } } }
@Override public void done(IJobChangeEvent event) { if (event.getResult().isOK() && continueListening()) { fWaitForConnectionJob.schedule(); } else { try{ terminate(); } catch (DebugException e){} } } });
@Override public void terminate() throws DebugException { if (!fTerminated){ fTerminated = true; if (fWaitForConnectionJob != null){ fWaitForConnectionJob.cancel(); fWaitForConnectionJob.stopListening(); fWaitForConnectionJob = null; } fireTerminateEvent(); } }
@Override public void done(IJobChangeEvent event) { if (event.getResult().equals(Status.CANCEL_STATUS)){ try{ terminate(); } catch (DebugException e){} } } });
monitor.subTask(NLS.bind(LaunchingMessages.SocketListenConnector_3, new String[]{portNumberString})); connector.startListening(acceptArguments); SocketListenConnectorProcess process = new SocketListenConnectorProcess(launch,portNumberString); launch.addProcess(process); process.waitForConnection(connector, acceptArguments); } catch (IOException e) { abort(LaunchingMessages.SocketListenConnector_4, e, IJavaLaunchConfigurationConstants.ERR_REMOTE_VM_CONNECTION_FAILED);
if (isTerminated()){ throw new CoreException(getStatus(LaunchingMessages.SocketListenConnectorProcess_0, null, IJavaLaunchConfigurationConstants.ERR_REMOTE_VM_CONNECTION_FAILED));
/** * Tells the listening connector to stop listening. Ensures * that the socket is closed and the port released. Sets a flag * so that the IOException thrown by the connector's accept method * will be ignored. */ protected void stopListening() { if (!fListeningStopped){ try{ fListeningStopped = true; fConnector.stopListening(fArguments); } catch (IOException e) { done(getStatus(LaunchingMessages.SocketListenConnectorProcess_5, e, IJavaLaunchConfigurationConstants.ERR_REMOTE_VM_CONNECTION_FAILED)); } catch (IllegalConnectorArgumentsException e) { done(getStatus(LaunchingMessages.SocketListenConnectorProcess_5, e, IJavaLaunchConfigurationConstants.ERR_REMOTE_VM_CONNECTION_FAILED)); } } }
@Override public void terminate() throws DebugException { if (!fTerminated){ fTerminated = true; fLaunch.removeProcess(this); if (fWaitForConnectionJob != null){ fWaitForConnectionJob.cancel(); fWaitForConnectionJob.stopListening(); fWaitForConnectionJob = null; } fireTerminateEvent(); } }
return Status.CANCEL_STATUS; return getStatus(LaunchingMessages.SocketListenConnectorProcess_4, e, IJavaLaunchConfigurationConstants.ERR_REMOTE_VM_CONNECTION_FAILED); } catch (IllegalConnectorArgumentsException e) { return getStatus(LaunchingMessages.SocketListenConnectorProcess_4, e, IJavaLaunchConfigurationConstants.ERR_REMOTE_VM_CONNECTION_FAILED);
public WaitForConnectionJob(ListeningConnector connector, Map<String, Connector.Argument> arguments) { super(getLabel()); fConnector = connector; fArguments = arguments; }
@Override public void running(IJobChangeEvent event) { fireReadyToAcceptEvent(); } @Override
return Status.CANCEL_STATUS; return getStatus(LaunchingMessages.SocketListenConnectorProcess_4, e, IJavaLaunchConfigurationConstants.ERR_REMOTE_VM_CONNECTION_FAILED); } catch (IllegalConnectorArgumentsException e) { return getStatus(LaunchingMessages.SocketListenConnectorProcess_4, e, IJavaLaunchConfigurationConstants.ERR_REMOTE_VM_CONNECTION_FAILED); } finally {