geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sppa...@apache.org
Subject svn commit: r479741 - in /geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/src/org/apache/geronimo/st/core: GeronimoServerBehaviourDelegate.java UpdateServerStateTask.java
Date Mon, 27 Nov 2006 19:53:34 GMT
Author: sppatel
Date: Mon Nov 27 11:53:33 2006
New Revision: 479741

URL: http://svn.apache.org/viewvc?view=rev&rev=479741
Log:
fix server restart issue where dialog box pops ups with invalid failure during restart action

Modified:
    geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/src/org/apache/geronimo/st/core/GeronimoServerBehaviourDelegate.java
    geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/src/org/apache/geronimo/st/core/UpdateServerStateTask.java

Modified: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/src/org/apache/geronimo/st/core/GeronimoServerBehaviourDelegate.java
URL: http://svn.apache.org/viewvc/geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/src/org/apache/geronimo/st/core/GeronimoServerBehaviourDelegate.java?view=diff&rev=479741&r1=479740&r2=479741
==============================================================================
--- geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/src/org/apache/geronimo/st/core/GeronimoServerBehaviourDelegate.java
(original)
+++ geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/src/org/apache/geronimo/st/core/GeronimoServerBehaviourDelegate.java
Mon Nov 27 11:53:33 2006
@@ -89,7 +89,9 @@
  */
 abstract public class GeronimoServerBehaviourDelegate extends ServerBehaviourDelegate implements
IGeronimoServerBehavior {
 
-	public static final int TIMER_TASK_INTERVAL = 10;
+	public static final int TIMER_TASK_INTERVAL = 20;
+	
+	public static final int TIMER_TASK_DELAY = 20;
 
 	protected IProgressMonitor _monitor;
 
@@ -715,7 +717,7 @@
 	protected void startUpdateServerStateTask() {
 		Trace.trace(Trace.INFO, "startUpdateServerStateTask() " + getServer().getName());
 		timer = new Timer(true);
-		timer.schedule(new UpdateServerStateTask(this, getServer()), 10000, TIMER_TASK_INTERVAL
* 1000);
+		timer.schedule(new UpdateServerStateTask(this, getServer()), TIMER_TASK_DELAY * 1000, TIMER_TASK_INTERVAL
* 1000);
 	}
 
 	protected void stopUpdateServerStateTask() {

Modified: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/src/org/apache/geronimo/st/core/UpdateServerStateTask.java
URL: http://svn.apache.org/viewvc/geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/src/org/apache/geronimo/st/core/UpdateServerStateTask.java?view=diff&rev=479741&r1=479740&r2=479741
==============================================================================
--- geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/src/org/apache/geronimo/st/core/UpdateServerStateTask.java
(original)
+++ geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/src/org/apache/geronimo/st/core/UpdateServerStateTask.java
Mon Nov 27 11:53:33 2006
@@ -18,6 +18,7 @@
 
 import java.util.TimerTask;
 
+import org.apache.geronimo.st.core.internal.Trace;
 import org.eclipse.wst.server.core.IServer;
 import org.eclipse.wst.server.core.ServerCore;
 import org.eclipse.wst.server.core.internal.Server;
@@ -31,8 +32,7 @@
 
 	private IServer server;
 
-	public UpdateServerStateTask(IGeronimoServerBehavior delegate,
-			IServer server) {
+	public UpdateServerStateTask(IGeronimoServerBehavior delegate, IServer server) {
 		super();
 		this.delegate = delegate;
 		this.server = server;
@@ -44,47 +44,47 @@
 	 * @see java.util.TimerTask#run()
 	 */
 	public void run() {
-		synchronized (delegate) {
-			//Trace.trace(Trace.INFO, "--> UpdateServerStateTask.run() " + server.getName());
+		if (canUpdateState()) {
+			updateServerState();
+		}
+	}
 
-			// Only start the task if the connection URL is unqiue for all
-			// g-servers or if other servers that are different instances but do
-			// share the same connection URL's are stopped
-			IGeronimoServer thisServer = (IGeronimoServer) this.server
-					.loadAdapter(IGeronimoServer.class, null);
-
-			IServer[] allServers = ServerCore.getServers();
-			boolean allUnique = true;
-			boolean allNonUniqueStopped = true;
-			for (int i = 0; i < allServers.length; i++) {
-				IServer server = allServers[i];
-				IGeronimoServer gs = (IGeronimoServer) server.loadAdapter(
-						IGeronimoServer.class, null);
-				if (gs != null && !this.server.getId().equals(server.getId())) {
-					if (gs.getJMXServiceURL().equals(
-							thisServer.getJMXServiceURL())) {
-						allUnique = false;
-						if (!server.getRuntime().getLocation().equals(
-								this.server.getRuntime().getLocation())
-								&& server.getServerState() != IServer.STATE_STOPPED) {
-							allNonUniqueStopped = false;
-						}
+	/**
+	 * Returns true if either the connection URL is unique for all g-servers or
+	 * if all other servers that share the same connection URL but have
+	 * different runtime locations are stopped.
+	 * 
+	 * @return true if ok to update state
+	 */
+	private boolean canUpdateState() {
+		IGeronimoServer thisServer = (IGeronimoServer) this.server.loadAdapter(IGeronimoServer.class,
null);
+		IServer[] allServers = ServerCore.getServers();
+		for (int i = 0; i < allServers.length; i++) {
+			IServer server = allServers[i];
+			IGeronimoServer gs = (IGeronimoServer) server.loadAdapter(IGeronimoServer.class, null);
+			if (gs != null && !this.server.getId().equals(server.getId())) {
+				if (isSameConnectionURL(gs, thisServer)) {
+					if (!isSameRuntimeLocation(server) && server.getServerState() != IServer.STATE_STOPPED)
{
+						Trace.trace(Trace.WARNING, server.getId() + " Cannot update server state.  URL conflict
between multiple servers.");
+						return false;
 					}
 				}
 			}
+		}
 
-			//Trace.trace(Trace.INFO, "allUnique = " + allUnique + ", allNonUniqueStopped = " + allNonUniqueStopped);
+		return true;
+	}
 
-			if (allUnique || allNonUniqueStopped) {
-				//Trace.trace(Trace.INFO, "updating state...");
-				updateServerState();
-			}
+	private boolean isSameRuntimeLocation(IServer server) {
+		return server.getRuntime().getLocation().equals(this.server.getRuntime().getLocation());
+	}
 
-			//Trace.trace(Trace.INFO, "<-- UpdateServerStateTask.run() " + server.getName());
-		}
+	private boolean isSameConnectionURL(IGeronimoServer server, IGeronimoServer thisServer)
{
+		return server.getJMXServiceURL().equals(thisServer.getJMXServiceURL());
 	}
 
 	private void updateServerState() {
+		Trace.trace(Trace.INFO, ">> " + server.getId() + " Updating Server State.");
 		try {
 			switch (server.getServerState()) {
 			case IServer.STATE_STOPPED:
@@ -104,6 +104,7 @@
 		} catch (Exception e) {
 			e.printStackTrace();
 		}
+		Trace.trace(Trace.INFO, "<< " + server.getId() + " Updating Server State.");
 	}
 
 	private void updateFromStopped() {
@@ -127,9 +128,7 @@
 	private boolean isFullyStarted() {
 		ClassLoader old = Thread.currentThread().getContextClassLoader();
 		try {
-			Thread.currentThread().setContextClassLoader(
-					((GeronimoServerBehaviourDelegate) delegate)
-							.getContextClassLoader());
+			Thread.currentThread().setContextClassLoader(((GeronimoServerBehaviourDelegate) delegate).getContextClassLoader());
 			return delegate.isFullyStarted();
 		} finally {
 			Thread.currentThread().setContextClassLoader(old);



Mime
View raw message