geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sppa...@apache.org
Subject svn commit: r371556 - in /geronimo/devtools/trunk/modules/eclipse-plugin/plugins/org.apache.geronimo.devtools.eclipse.core/src/org/apache/geronimo/core/internal: GeronimoServerBehaviour.java UpdateServerStateTask.java
Date Mon, 23 Jan 2006 15:35:46 GMT
Author: sppatel
Date: Mon Jan 23 07:35:42 2006
New Revision: 371556

URL: http://svn.apache.org/viewcvs?rev=371556&view=rev
Log:
server state task

Added:
    geronimo/devtools/trunk/modules/eclipse-plugin/plugins/org.apache.geronimo.devtools.eclipse.core/src/org/apache/geronimo/core/internal/UpdateServerStateTask.java
  (with props)
Modified:
    geronimo/devtools/trunk/modules/eclipse-plugin/plugins/org.apache.geronimo.devtools.eclipse.core/src/org/apache/geronimo/core/internal/GeronimoServerBehaviour.java

Modified: geronimo/devtools/trunk/modules/eclipse-plugin/plugins/org.apache.geronimo.devtools.eclipse.core/src/org/apache/geronimo/core/internal/GeronimoServerBehaviour.java
URL: http://svn.apache.org/viewcvs/geronimo/devtools/trunk/modules/eclipse-plugin/plugins/org.apache.geronimo.devtools.eclipse.core/src/org/apache/geronimo/core/internal/GeronimoServerBehaviour.java?rev=371556&r1=371555&r2=371556&view=diff
==============================================================================
--- geronimo/devtools/trunk/modules/eclipse-plugin/plugins/org.apache.geronimo.devtools.eclipse.core/src/org/apache/geronimo/core/internal/GeronimoServerBehaviour.java
(original)
+++ geronimo/devtools/trunk/modules/eclipse-plugin/plugins/org.apache.geronimo.devtools.eclipse.core/src/org/apache/geronimo/core/internal/GeronimoServerBehaviour.java
Mon Jan 23 07:35:42 2006
@@ -16,11 +16,12 @@
 package org.apache.geronimo.core.internal;
 
 import java.net.MalformedURLException;
+import java.rmi.ConnectException;
 import java.util.Arrays;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.Set;
-import java.util.TimerTask;
+import java.util.Timer;
 
 import javax.enterprise.deploy.spi.TargetModuleID;
 import javax.management.MBeanServerConnection;
@@ -54,7 +55,7 @@
 
 	private static final int MAX_TRIES = 30;
 
-	private static final int TIMER_TASK_INTERVAL = 30;
+	private static final int TIMER_TASK_INTERVAL = 10;
 
 	private IProgressMonitor _monitor = null;
 
@@ -62,10 +63,6 @@
 
 	public GeronimoServerBehaviour() {
 		super();
-		/*
-		 * Timer timer = new Timer(true); timer.schedule(new
-		 * UpdateServerStateTask(), 0, TIMER_TASK_INTERVAL * 1000);
-		 */
 	}
 
 	/*
@@ -73,7 +70,9 @@
 	 * 
 	 * @see org.eclipse.wst.server.core.model.ServerBehaviourDelegate#stop(boolean)
 	 */
-	public void stop(boolean force) {
+	public synchronized void stop(boolean force) {
+
+		Trace.trace(Trace.INFO, "--> stop()");
 
 		setServerState(IServer.STATE_STOPPING);
 
@@ -88,6 +87,8 @@
 
 		// kill the process
 		super.stop(true);
+
+		Trace.trace(Trace.INFO, "<-- stop()");
 	}
 
 	private String getJMXServiceURL() {
@@ -139,7 +140,8 @@
 	 * 
 	 * @see org.eclipse.jst.server.generic.core.internal.GenericServerBehaviour#setServerStarted()
 	 */
-	protected void setServerStarted() {
+	protected synchronized void setServerStarted() {
+		Trace.trace(Trace.INFO, "--> setServerStarted()");
 		for (int tries = MAX_TRIES; tries > 0; tries--) {
 			try {
 				Thread.sleep(5000);
@@ -147,20 +149,26 @@
 				// ignore
 			}
 			boolean isFullyStarted = isKernelFullyStarted();
-			Trace.trace(Trace.INFO, "kernelFullyStarted = " + isFullyStarted
-					+ ", " + (tries - 1) + " attempts left.");
+			Trace.trace(Trace.INFO, "kernelFullyStarted = " + isFullyStarted);
 			if (isFullyStarted) {
 				setServerState(IServer.STATE_STARTED);
 				break;
 			}
 		}
+		Trace.trace(Trace.INFO, "<-- setServerStarted()");
 	}
 
-	private boolean isKernelAlive() {
-		return getKernel() != null && kernel.isRunning();
+	protected boolean isKernelAlive() {
+		try {
+			return getKernel() != null && kernel.isRunning();
+		} catch (Exception e) {
+			e.printStackTrace();
+			kernel = null;
+		}
+		return false;
 	}
 
-	private boolean isKernelFullyStarted() {
+	protected boolean isKernelFullyStarted() {
 		if (isKernelAlive()) {
 			Set configLists = kernel.listGBeans(new GBeanQuery(null,
 					PersistentConfigurationList.class.getName()));
@@ -203,7 +211,7 @@
 			// TODO This case is flawed due to WTP Bugzilla 123676
 			invokeCommand(deltaKind, module[0]);
 		}
-		
+
 		setModulePublishState(module, IServer.PUBLISH_STATE_NONE);
 
 		Trace.trace(Trace.INFO, "<< publishModule()");
@@ -352,38 +360,16 @@
 		}
 	}
 
-	/**
-	 * This timer task runs at scheduled intervals to sync the server state if
-	 * the users controls the server instance outside of the eclipse workbench.
-	 * 
-	 * WTP manages the server process, and if the process is dead, the state is
-	 * updated. So the only scenario that needs to be considered is if the
-	 * server is restarted.
+	/*
+	 * (non-Javadoc)
 	 * 
-	 * FIXME When the server is stop the GeronimoServerBehavior instance is
-	 * destroyed so the task never runs to handle this scenario.
+	 * @see org.eclipse.wst.server.core.model.ServerBehaviourDelegate#initialize(org.eclipse.core.runtime.IProgressMonitor)
 	 */
-	private class UpdateServerStateTask extends TimerTask {
-
-		/*
-		 * (non-Javadoc)
-		 * 
-		 * @see java.lang.Runnable#run()
-		 */
-		public void run() {
-			synchronized (GeronimoServerBehaviour.this) {
-				Trace.trace(Trace.INFO, "--> UpdateServerStateTask.run()");
-				int currentState = getServer().getServerState();
-				if (currentState == IServer.STATE_STOPPED && isKernelAlive()) {
-					if (isKernelFullyStarted()) {
-						setServerState(IServer.STATE_STARTED);
-					} else {
-						setServerState(IServer.STATE_STARTING);
-					}
-				}
-				Trace.trace(Trace.INFO, "<-- UpdateServerStateTask.run()");
-			}
-		}
+	protected void initialize(IProgressMonitor monitor) {
+		Trace.trace(Trace.INFO, "GeronimoServerBehavior.initialize()");
+		Timer timer = new Timer(true);
+		timer.schedule(new UpdateServerStateTask(this), 0,
+				TIMER_TASK_INTERVAL * 1000);
 	}
 
 }

Added: geronimo/devtools/trunk/modules/eclipse-plugin/plugins/org.apache.geronimo.devtools.eclipse.core/src/org/apache/geronimo/core/internal/UpdateServerStateTask.java
URL: http://svn.apache.org/viewcvs/geronimo/devtools/trunk/modules/eclipse-plugin/plugins/org.apache.geronimo.devtools.eclipse.core/src/org/apache/geronimo/core/internal/UpdateServerStateTask.java?rev=371556&view=auto
==============================================================================
--- geronimo/devtools/trunk/modules/eclipse-plugin/plugins/org.apache.geronimo.devtools.eclipse.core/src/org/apache/geronimo/core/internal/UpdateServerStateTask.java
(added)
+++ geronimo/devtools/trunk/modules/eclipse-plugin/plugins/org.apache.geronimo.devtools.eclipse.core/src/org/apache/geronimo/core/internal/UpdateServerStateTask.java
Mon Jan 23 07:35:42 2006
@@ -0,0 +1,85 @@
+/**
+ * Copyright 2004, 2005 The Apache Software Foundation or its licensors, as applicable
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.geronimo.core.internal;
+
+import java.util.TimerTask;
+
+import org.eclipse.wst.server.core.IServer;
+import org.eclipse.wst.server.core.internal.Server;
+
+public class UpdateServerStateTask extends TimerTask {
+
+	GeronimoServerBehaviour delegate;
+
+	public UpdateServerStateTask(GeronimoServerBehaviour delegate) {
+		super();
+		this.delegate = delegate;
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see java.util.TimerTask#run()
+	 */
+	public void run() {
+		synchronized (delegate) {
+			Trace.trace(Trace.INFO, "--> UpdateServerStateTask.run()");
+			int currentState = delegate.getServer().getServerState();
+			Server server = (Server) delegate.getServer();
+			try {
+				switch (currentState) {
+				case IServer.STATE_STOPPED:
+					if (delegate.isKernelAlive())
+						updateFromStopped(server);
+					break;
+				case IServer.STATE_STARTING:
+					if (delegate.isKernelAlive())
+						updateFromStarting(server);
+					else {
+						server.setServerState(IServer.STATE_STOPPED);
+					}
+					break;
+				case IServer.STATE_STARTED:
+					updateFromStarted(server);
+					break;
+				}
+			} catch (Exception e) {
+				e.printStackTrace();
+			}
+			Trace.trace(Trace.INFO, "<-- UpdateServerStateTask.run()");
+		}
+	}
+
+	private void updateFromStopped(Server server) {
+		if (delegate.isKernelFullyStarted()) {
+			server.setServerState(IServer.STATE_STARTED);
+		} else {
+			server.setServerState(IServer.STATE_STARTING);
+		}
+	}
+
+	private void updateFromStarting(Server server) {
+		if (delegate.isKernelFullyStarted())
+			server.setServerState(IServer.STATE_STARTED);
+	}
+
+	private void updateFromStarted(Server server) {
+		if (!delegate.isKernelAlive()) {
+			server.setServerState(IServer.STATE_STOPPED);
+		}
+	}
+
+}

Propchange: geronimo/devtools/trunk/modules/eclipse-plugin/plugins/org.apache.geronimo.devtools.eclipse.core/src/org/apache/geronimo/core/internal/UpdateServerStateTask.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/devtools/trunk/modules/eclipse-plugin/plugins/org.apache.geronimo.devtools.eclipse.core/src/org/apache/geronimo/core/internal/UpdateServerStateTask.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/devtools/trunk/modules/eclipse-plugin/plugins/org.apache.geronimo.devtools.eclipse.core/src/org/apache/geronimo/core/internal/UpdateServerStateTask.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message