Author: rob.stryker(a)jboss.com
Date: 2007-10-22 19:26:37 -0400 (Mon, 22 Oct 2007)
New Revision: 4431
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/JBossServerBehavior.java
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/PollThread.java
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/launch/StopLaunchConfiguration.java
Log:
JBIDE-1128
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/JBossServerBehavior.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/JBossServerBehavior.java 2007-10-22
23:15:47 UTC (rev 4430)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/JBossServerBehavior.java 2007-10-22
23:26:37 UTC (rev 4431)
@@ -23,6 +23,8 @@
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
import org.eclipse.debug.core.DebugEvent;
import org.eclipse.debug.core.DebugException;
import org.eclipse.debug.core.DebugPlugin;
@@ -30,6 +32,7 @@
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
import org.eclipse.debug.core.model.IProcess;
import org.eclipse.wst.server.core.IServer;
+import org.jboss.ide.eclipse.as.core.JBossServerCorePlugin;
import org.jboss.ide.eclipse.as.core.extensions.events.EventLogModel;
import org.jboss.ide.eclipse.as.core.extensions.events.EventLogModel.EventLogTreeItem;
import org.jboss.ide.eclipse.as.core.server.IServerStatePoller;
@@ -42,15 +45,18 @@
*
*/
public class JBossServerBehavior extends DeployableServerBehavior {
+ private static final String STOP_FAILED_MESSAGE =
+ "Command to stop server failed. The next attempt will forcefully terminate the
process.";
private PollThread pollThread = null;
protected IProcess process;
+ protected boolean nextStopRequiresForce = false;
public JBossServerBehavior() {
super();
}
public void stop(boolean force) {
int state = getServer().getServerState();
- if( force || process == null || process.isTerminated() || state ==
IServer.STATE_STOPPED) {
+ if( force || process == null || process.isTerminated() || state ==
IServer.STATE_STOPPED || nextStopRequiresForce) {
forceStop();
return;
}
@@ -64,9 +70,21 @@
}
new Thread() {public void run() {
- serverStopping();
- StopLaunchConfiguration.stop(getServer());
- }}.start();
+ serverStopping();
+ boolean success = StopLaunchConfiguration.stop(getServer());
+ if( !success ) {
+ if( !process.isTerminated() ) {
+ setServerStarted();
+
+ // report it to error log
+ IStatus s = new Status(IStatus.ERROR, JBossServerCorePlugin.PLUGIN_ID,
+ "", null);
+ JBossServerCorePlugin.getDefault().getLog().log(s);
+ pollThread.cancel(STOP_FAILED_MESSAGE);
+ nextStopRequiresForce = true;
+ }
+ }
+ }}.start();
}
public void forceStop() {
@@ -134,6 +152,7 @@
}
public void serverStarting() {
+ nextStopRequiresForce = false;
setServerStarting();
pollServer(IServerStatePoller.SERVER_UP);
}
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/PollThread.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/PollThread.java 2007-10-22
23:15:47 UTC (rev 4430)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/PollThread.java 2007-10-22
23:26:37 UTC (rev 4431)
@@ -49,6 +49,7 @@
public static final String SUCCESS =
"org.jboss.ide.eclipse.as.core.runtime.server.PollThread.success";
public static final String POLLER_NOT_FOUND =
"org.jboss.ide.eclipse.as.core.runtime.server.PollThread.pollerNotFound";
public static final String POLL_THREAD_ABORTED =
"org.jboss.ide.eclipse.as.core.runtime.server.PollThread.aborted";
+ public static final String POLL_THREAD_ABORTED_CAUSE =
"org.jboss.ide.eclipse.as.core.runtime.server.PollThread.aborted.cause";
public static final String POLL_THREAD_TIMEOUT =
"org.jboss.ide.eclipse.as.core.runtime.server.PollThread.timeout";
public static final String EXPECTED_STATE =
"org.jboss.ide.eclipse.as.core.runtime.server.PollThreadEvent.expectedState";
public static final String POLL_THREAD_EXCEPTION =
"org.jboss.ide.eclipse.as.core.runtime.server.PollThread.exception";
@@ -58,6 +59,7 @@
private boolean expectedState;
private IServerStatePoller poller;
private boolean abort;
+ private String abortMessage;
private JBossServerBehavior behavior;
private EventLogRoot eventRoot;
@@ -67,10 +69,10 @@
super(name);
this.expectedState = expectedState;
this.abort = false;
+ this.abortMessage = null;
this.behavior = behavior;
- eventRoot = EventLogModel.getModel(behavior.getServer()).getRoot();
-
- poller = discoverPoller(behavior, expectedState);
+ this.eventRoot = EventLogModel.getModel(behavior.getServer()).getRoot();
+ this.poller = discoverPoller(behavior, expectedState);
}
protected IServerStatePoller discoverPoller(JBossServerBehavior behavior, boolean
expectedState) {
@@ -88,7 +90,11 @@
}
public void cancel() {
+ cancel(null);
+ }
+ public void cancel(String message) {
abort = true;
+ abortMessage = message;
}
@@ -231,6 +237,7 @@
protected void alertEventLogAbort() {
PollThreadEvent event = new PollThreadEvent(activeEvent, POLL_THREAD_ABORTED,
expectedState);
+ event.setProperty(POLL_THREAD_ABORTED_CAUSE, abortMessage);
EventLogModel.markChanged(activeEvent);
}
protected void alertEventLogTimeout() {
@@ -250,6 +257,7 @@
EventLogModel.markChanged(activeEvent);
}
+
public class PollThreadEvent extends EventLogTreeItem {
public PollThreadEvent(SimpleTreeItem parent, String type, boolean expectedState) {
super(parent, SERVER_STATE_MAJOR_TYPE, type);
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/launch/StopLaunchConfiguration.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/launch/StopLaunchConfiguration.java 2007-10-22
23:15:47 UTC (rev 4430)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/launch/StopLaunchConfiguration.java 2007-10-22
23:26:37 UTC (rev 4431)
@@ -36,6 +36,7 @@
import org.eclipse.debug.core.ILaunchConfigurationType;
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
import org.eclipse.debug.core.ILaunchManager;
+import org.eclipse.debug.core.model.IProcess;
import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
import org.eclipse.wst.server.core.IServer;
import org.jboss.ide.eclipse.as.core.JBossServerCorePlugin;
@@ -49,15 +50,20 @@
public static final String STOP_MAIN_TYPE = "org.jboss.Shutdown";
public static final String STOP_JAR_LOC = "bin" + File.separator +
"shutdown.jar";
- public static void stop(IServer server) {
+ /* Returns whether termination was normal */
+ public static boolean stop(IServer server) {
try {
ILaunchConfigurationWorkingCopy wc = createLaunchConfiguration(server);
- wc.launch(ILaunchManager.RUN_MODE, new NullProgressMonitor());
+ ILaunch launch = wc.launch(ILaunchManager.RUN_MODE, new NullProgressMonitor());
+ IProcess stopProcess = launch.getProcesses()[0];
+ while( !stopProcess.isTerminated()) {}
+ return stopProcess.getExitValue() == 0 ? true : false;
} catch( CoreException ce ) {
// report it from here
IStatus s = new Status(IStatus.ERROR, JBossServerCorePlugin.PLUGIN_ID,
"Unexpected Exception launching stop server command: ", ce);
JBossServerCorePlugin.getDefault().getLog().log(s);
+ return false;
}
}