Author: rob.stryker(a)jboss.com
Date: 2012-08-17 05:15:53 -0400 (Fri, 17 Aug 2012)
New Revision: 43086
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.rse.core/src/org/jboss/ide/eclipse/as/rse/core/AbstractRSEBehaviourDelegate.java
trunk/as/plugins/org.jboss.ide.eclipse.as.rse.core/src/org/jboss/ide/eclipse/as/rse/core/AbstractRSELaunchDelegate.java
trunk/as/plugins/org.jboss.ide.eclipse.as.rse.core/src/org/jboss/ide/eclipse/as/rse/core/RSEHostShellModel.java
Log:
JBIDE-11990 to trunk
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.rse.core/src/org/jboss/ide/eclipse/as/rse/core/AbstractRSEBehaviourDelegate.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.rse.core/src/org/jboss/ide/eclipse/as/rse/core/AbstractRSEBehaviourDelegate.java 2012-08-17
08:26:50 UTC (rev 43085)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.rse.core/src/org/jboss/ide/eclipse/as/rse/core/AbstractRSEBehaviourDelegate.java 2012-08-17
09:15:53 UTC (rev 43086)
@@ -14,10 +14,13 @@
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.Status;
import org.eclipse.wst.server.core.IServer;
import org.jboss.ide.eclipse.as.core.server.IServerStatePoller;
import org.jboss.ide.eclipse.as.core.server.internal.AbstractJBossBehaviourDelegate;
import org.jboss.ide.eclipse.as.core.util.PollThreadUtils;
+import org.jboss.ide.eclipse.as.rse.core.RSEHostShellModel.ServerShellModel;
public abstract class AbstractRSEBehaviourDelegate extends AbstractJBossBehaviourDelegate
{
@@ -47,9 +50,27 @@
} // else wait for the poller to set the proper state
}
+ private String pid;
+ public void setPid(String pid) {
+ this.pid = pid;
+ }
+
@Override
- protected void forceStop() {
+ protected synchronized void forceStop() {
+ if( getServer().getServerState() == IServer.STATE_STOPPED)
+ return;
+ String localPid = pid;
+ pid = null;
setServerStopped();
+ if( localPid != null ) {
+ try {
+ ServerShellModel model = RSEHostShellModel.getInstance().getModel(getServer());
+ String cmd = "kill -9 " + localPid;
+ model.executeRemoteCommand("/", cmd, new String[]{}, new
NullProgressMonitor(), 2000, true);
+ } catch(CoreException ce ) {
+ RSECorePlugin.getLog().log(new Status(IStatus.ERROR, RSECorePlugin.PLUGIN_ID,
"Unable to terminate remote process " + pid, ce));
+ }
+ }
}
protected abstract String getShutdownCommand(IServer server) throws CoreException;
@@ -63,5 +84,10 @@
public void onServerStopping() {
pollServer(IServerStatePoller.SERVER_DOWN);
}
+ @Override
+ protected void setServerStopped() {
+ super.setServerStopped();
+ pid = null;
+ }
}
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.rse.core/src/org/jboss/ide/eclipse/as/rse/core/AbstractRSELaunchDelegate.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.rse.core/src/org/jboss/ide/eclipse/as/rse/core/AbstractRSELaunchDelegate.java 2012-08-17
08:26:50 UTC (rev 43085)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.rse.core/src/org/jboss/ide/eclipse/as/rse/core/AbstractRSELaunchDelegate.java 2012-08-17
09:15:53 UTC (rev 43086)
@@ -23,6 +23,7 @@
import org.eclipse.rse.services.shells.IHostShell;
import org.eclipse.rse.services.shells.IHostShellChangeEvent;
import org.eclipse.rse.services.shells.IHostShellOutputListener;
+import org.jboss.ide.eclipse.as.core.server.IJBossBehaviourDelegate;
import org.jboss.ide.eclipse.as.core.server.IJBossLaunchDelegate;
import org.jboss.ide.eclipse.as.core.server.internal.DelegatingServerBehavior;
import org.jboss.ide.eclipse.as.core.server.internal.DeployableServerBehavior;
@@ -33,12 +34,16 @@
public abstract class AbstractRSELaunchDelegate extends
AbstractJBossStartLaunchConfiguration
implements IJBossLaunchDelegate {
+ public static final String DELIMETER = ":";
+ public static final String ECHO_KEY_DISCOVER_PID =
"JBTOOLS_SERVER_START_CMD";
protected void executeRemoteCommand(String command, DelegatingServerBehavior behavior)
throws CoreException {
try {
ServerShellModel model =
RSEHostShellModel.getInstance().getModel(behavior.getServer());
IHostShell shell = model.createStartupShell("/", command, new String[] {},
new NullProgressMonitor());
- addShellOutputListener(shell);
+ addShellOutputListener(shell, behavior);
+ String getPidCommand = "echo \"" + ECHO_KEY_DISCOVER_PID + DELIMETER +
behavior.getServer().getId() + DELIMETER + "\"$!";
+ shell.writeToShell(getPidCommand);
} catch (SystemMessageException sme) {
// could not connect to remote system
behavior.setServerStopped();
@@ -47,8 +52,8 @@
MessageFormat.format("Could not execute command on remote server {0}. Please
ensure the server is reachable.", behavior.getServer().getName()), sme));
}
}
- // Only for debugging
- private void addShellOutputListener(IHostShell shell) {
+
+ private void addShellOutputListener(final IHostShell shell, final
DelegatingServerBehavior behavior) {
if( shell == null )
return; // No listener needed for a null shell.
IHostShellOutputListener listener = null;
@@ -56,12 +61,19 @@
public void shellOutputChanged(IHostShellChangeEvent event) {
IHostOutput[] out = event.getLines();
for (int i = 0; i < out.length; i++) {
- // TODO listen here for obvious exceptions or failures
- // System.out.println(out[i]);
+ if( out[i].toString().startsWith(ECHO_KEY_DISCOVER_PID)) {
+ // pid found
+ int lastColon = out[i].toString().lastIndexOf(DELIMETER);
+ String pid = out[i].toString().substring(lastColon+1);
+ IJBossBehaviourDelegate del = behavior.getDelegate();
+ if( del instanceof AbstractRSEBehaviourDelegate) {
+ ((AbstractRSEBehaviourDelegate)del).setPid(pid);
+ }
+ }
}
}
};
- // shell.addOutputListener(listener);
+ shell.addOutputListener(listener);
}
protected void launchPingThread(DeployableServerBehavior beh) {
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.rse.core/src/org/jboss/ide/eclipse/as/rse/core/RSEHostShellModel.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.rse.core/src/org/jboss/ide/eclipse/as/rse/core/RSEHostShellModel.java 2012-08-17
08:26:50 UTC (rev 43085)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.rse.core/src/org/jboss/ide/eclipse/as/rse/core/RSEHostShellModel.java 2012-08-17
09:15:53 UTC (rev 43086)
@@ -192,7 +192,7 @@
if( !done[0]) {
statusLine[0] = statusLine[1];
statusLine[1] = lines[i].getString();
- System.out.println(lines[i].getString());
+ System.out.println("RSEHostShellModel debug out: " +
lines[i].getString());
}
if( serverId.equals(statusLine[1]))
@@ -210,6 +210,7 @@
singleUseShell = null;
}
String s = statusLine[0];
+ done[0] = true; // ensure a cleanup
if( s != null ) {
try {
Integer i = Integer.parseInt(s);
Show replies by date