geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sppa...@apache.org
Subject svn commit: r372243 - in /geronimo/devtools/trunk/modules/eclipse-plugin/plugins/org.apache.geronimo.devtools.eclipse.core/src/org/apache/geronimo/core/internal: GeronimoServerBehaviour.java PingThread.java
Date Wed, 25 Jan 2006 15:30:20 GMT
Author: sppatel
Date: Wed Jan 25 07:30:17 2006
New Revision: 372243

URL: http://svn.apache.org/viewcvs?rev=372243&view=rev
Log:
override PingThread behavior, don't need WTP pinging for us

Added:
    geronimo/devtools/trunk/modules/eclipse-plugin/plugins/org.apache.geronimo.devtools.eclipse.core/src/org/apache/geronimo/core/internal/PingThread.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=372243&r1=372242&r2=372243&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
Wed Jan 25 07:30:17 2006
@@ -52,7 +52,6 @@
 import org.eclipse.jst.server.generic.core.internal.CorePlugin;
 import org.eclipse.jst.server.generic.core.internal.GenericServerBehaviour;
 import org.eclipse.jst.server.generic.core.internal.GenericServerCoreMessages;
-import org.eclipse.jst.server.generic.core.internal.PingThread;
 import org.eclipse.wst.server.core.IModule;
 import org.eclipse.wst.server.core.IServer;
 import org.eclipse.wst.server.core.IServerListener;
@@ -146,13 +145,17 @@
 
 		return kernel;
 	}
+	
+	protected void setServerStarted() {
+		super.setServerStarted();
+	}
 
 	/*
 	 * (non-Javadoc)
 	 * 
 	 * @see org.eclipse.jst.server.generic.core.internal.GenericServerBehaviour#setServerStarted()
 	 */
-	protected void setServerStarted() {
+	/*protected void setServerStarted() {
 		Trace.trace(Trace.INFO, "--> setServerStarted()");
 		for (int tries = MAX_TRIES; tries > 0; tries--) {
 			try {
@@ -168,7 +171,7 @@
 			}
 		}
 		Trace.trace(Trace.INFO, "<-- setServerStarted()");
-	}
+	}*/
 
 	protected boolean isKernelAlive() {
 		try {
@@ -401,26 +404,28 @@
 	 */
 	protected void setupLaunch(ILaunch launch, String launchMode,
 			IProgressMonitor monitor) throws CoreException {
-		if ("true".equals(launch.getLaunchConfiguration().getAttribute(ATTR_STOP, "false"))) //$NON-NLS-1$
//$NON-NLS-2$
+
+		if ("true".equals(launch.getLaunchConfiguration().getAttribute(
+				ATTR_STOP, "false")))
+			return;
+
+		if (!SocketUtil.isLocalhost(getServer().getHost()))
 			return;
 
 		String host = getServer().getHost();
+
 		ServerPort[] ports = getServer().getServerPorts(null);
-		ServerPort sp = null;
-		if (SocketUtil.isLocalhost(host)) {
-			for (int i = 0; i < ports.length; i++) {
-				sp = ports[i];
-				if (SocketUtil.isPortInUse(ports[i].getPort(), 5))
-					throw new CoreException(new Status(IStatus.ERROR,
-							CorePlugin.PLUGIN_ID, 0,
-							GenericServerCoreMessages.bind(
-									GenericServerCoreMessages.errorPortInUse,
-									Integer.toString(sp.getPort()), sp
-											.getName()), null));
-			}
+		for (int i = 0; i < ports.length; i++) {
+			ServerPort sp = ports[i];
+			if (SocketUtil.isPortInUse(ports[i].getPort(), 5))
+				throw new CoreException(new Status(IStatus.ERROR,
+						CorePlugin.PLUGIN_ID, 0, GenericServerCoreMessages
+								.bind(GenericServerCoreMessages.errorPortInUse,
+										Integer.toString(sp.getPort()), sp
+												.getName()), null));
 		}
 
-		stopPing();
+		stopUpdateServerStateTask();
 		setServerState(IServer.STATE_STARTING);
 		setMode(launchMode);
 
@@ -435,7 +440,7 @@
 							|| state == IServer.STATE_STOPPED) {
 						GeronimoServerBehaviour.this.getServer()
 								.removeServerListener(this);
-						startPing();
+						startUpdateServerStateTask();
 					}
 				}
 			}
@@ -443,27 +448,20 @@
 
 		getServer().addServerListener(listener);
 
-		// ping server to check for startup
-		try {
-			String url = "http://" + host;
-			int port = sp.getPort();
-			if (port != 80)
-				url += ":" + port;
-			ping = new PingThread(getServer(), url, this);
-		} catch (Exception e) {
-			Trace.trace(Trace.SEVERE, "Can't ping for server startup.");
-		}
+		PingThread pingThread = new PingThread(this);
+		pingThread.start();
+
 	}
 
-	private void startPing() {
-		Trace.trace(Trace.INFO, "startPing()");
+	private void startUpdateServerStateTask() {
+		Trace.trace(Trace.INFO, "startUpdateServerStateTask()");
 		timer = new Timer(true);
 		timer.schedule(new UpdateServerStateTask(this), 10000,
 				TIMER_TASK_INTERVAL * 1000);
 	}
 
-	private void stopPing() {
-		Trace.trace(Trace.INFO, "stopPing()");
+	private void stopUpdateServerStateTask() {
+		Trace.trace(Trace.INFO, "stopUpdateServerStateTask()");
 		if (timer != null)
 			timer.cancel();
 	}
@@ -475,7 +473,7 @@
 	 */
 	protected void initialize(IProgressMonitor monitor) {
 		Trace.trace(Trace.INFO, "GeronimoServerBehavior.initialize()");
-		startPing();
+		startUpdateServerStateTask();
 	}
 
 }

Added: geronimo/devtools/trunk/modules/eclipse-plugin/plugins/org.apache.geronimo.devtools.eclipse.core/src/org/apache/geronimo/core/internal/PingThread.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/PingThread.java?rev=372243&view=auto
==============================================================================
--- geronimo/devtools/trunk/modules/eclipse-plugin/plugins/org.apache.geronimo.devtools.eclipse.core/src/org/apache/geronimo/core/internal/PingThread.java
(added)
+++ geronimo/devtools/trunk/modules/eclipse-plugin/plugins/org.apache.geronimo.devtools.eclipse.core/src/org/apache/geronimo/core/internal/PingThread.java
Wed Jan 25 07:30:17 2006
@@ -0,0 +1,73 @@
+/**
+ * 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 org.eclipse.wst.server.core.util.SocketUtil;
+
+public class PingThread extends Thread {
+
+	private static final int PING_DELAY = 5000;
+	private static final int PING_INTERVAL = 5000;
+	private static final int MAX_PINGS = 40;
+
+	private GeronimoServerBehaviour geronimoServer;
+
+	public PingThread(GeronimoServerBehaviour geronimoServer) {
+		super();
+		this.geronimoServer = geronimoServer;
+		this.setDaemon(true);
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see java.lang.Runnable#run()
+	 */
+	public void run() {
+
+		if (!SocketUtil.isLocalhost(geronimoServer.getServer().getHost())) {
+			return;
+		}
+
+		try {
+			sleep(PING_DELAY);
+		} catch (InterruptedException e) {
+			// ignore
+		}
+
+		for (int tries = MAX_PINGS; tries > 0; tries--) {
+
+			if (geronimoServer.isKernelFullyStarted()) {
+				Trace.trace(Trace.INFO, "Ping: success");
+				geronimoServer.setServerStarted();
+				return;
+			}
+
+			Trace.trace(Trace.INFO, "Ping: failed");
+
+			try {
+				sleep(PING_INTERVAL);
+			} catch (InterruptedException e) {
+				// ignore
+			}
+		}
+
+		Trace.trace(Trace.SEVERE, "Ping: Can't ping for server startup.");
+		geronimoServer.getServer().stop(false);
+
+	}
+
+}

Propchange: geronimo/devtools/trunk/modules/eclipse-plugin/plugins/org.apache.geronimo.devtools.eclipse.core/src/org/apache/geronimo/core/internal/PingThread.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/PingThread.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/PingThread.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message