You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by sp...@apache.org on 2006/08/11 04:18:07 UTC

svn commit: r430623 - in /geronimo/devtools/eclipse-plugin/trunk/plugins: org.apache.geronimo.st.core/src/org/apache/geronimo/st/core/ org.apache.geronimo.st.jmxagent/src/org/apache/geronimo/st/jmxagent/ org.apache.geronimo.st.v1.core/src/org/apache/ge...

Author: sppatel
Date: Thu Aug 10 19:18:06 2006
New Revision: 430623

URL: http://svn.apache.org/viewvc?rev=430623&view=rev
Log:
GERONIMODEVTOOLS-98 fix intermittant NoInitialContextException on startup

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.jmxagent/src/org/apache/geronimo/st/jmxagent/Activator.java
    geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v1.core/src/org/apache/geronimo/st/v1/core/GeronimoServerBehaviour.java
    geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v11.core/src/org/apache/geronimo/st/v11/core/GeronimoServerBehaviour.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?rev=430623&r1=430622&r2=430623&view=diff
==============================================================================
--- 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 Thu Aug 10 19:18:06 2006
@@ -15,9 +15,11 @@
  */
 package org.apache.geronimo.st.core;
 
+import java.net.MalformedURLException;
 import java.net.URL;
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
@@ -25,6 +27,10 @@
 
 import javax.enterprise.deploy.spi.DeploymentManager;
 import javax.enterprise.deploy.spi.TargetModuleID;
+import javax.management.MBeanServerConnection;
+import javax.management.remote.JMXConnector;
+import javax.management.remote.JMXConnectorFactory;
+import javax.management.remote.JMXServiceURL;
 
 import org.apache.geronimo.st.core.commands.DeploymentCmdStatus;
 import org.apache.geronimo.st.core.commands.DeploymentCommandFactory;
@@ -200,6 +206,8 @@
 		}
 		if (allpublished)
 			setServerPublishState(IServer.PUBLISH_STATE_NONE);
+
+		GeronimoConnectionFactory.getInstance().destroy(getServer());
 	}
 
 	/*
@@ -524,5 +532,31 @@
 		}
 
 		return modulePath;
+	}
+
+	protected MBeanServerConnection getServerConnection() throws Exception {
+		Map map = new HashMap();
+		String user = getGeronimoServer().getAdminID();
+		String password = getGeronimoServer().getAdminPassword();
+		map.put("jmx.remote.credentials", new String[] { user, password });
+		map.put("java.naming.factory.initial", "com.sun.jndi.rmi.registry.RegistryContextFactory");
+		map.put("java.naming.factory.url.pkgs", "org.apache.geronimo.naming");
+		map.put("java.naming.provider.url", "rmi://" + getServer().getHost()
+				+ ":1099");
+
+		String url = getGeronimoServer().getJMXServiceURL();
+		if (url != null) {
+			try {
+				JMXServiceURL address = new JMXServiceURL(url);
+				JMXConnector jmxConnector = JMXConnectorFactory.connect(address, map);
+				MBeanServerConnection connection = jmxConnector.getMBeanServerConnection();
+				Trace.trace(Trace.INFO, "Connected to kernel. " + url);
+				return connection;
+			} catch (MalformedURLException e) {
+				e.printStackTrace();
+			}
+		}
+
+		return null;
 	}
 }

Modified: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.jmxagent/src/org/apache/geronimo/st/jmxagent/Activator.java
URL: http://svn.apache.org/viewvc/geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.jmxagent/src/org/apache/geronimo/st/jmxagent/Activator.java?rev=430623&r1=430622&r2=430623&view=diff
==============================================================================
--- geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.jmxagent/src/org/apache/geronimo/st/jmxagent/Activator.java (original)
+++ geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.jmxagent/src/org/apache/geronimo/st/jmxagent/Activator.java Thu Aug 10 19:18:06 2006
@@ -18,7 +18,6 @@
 
 import org.eclipse.core.runtime.Plugin;
 import org.eclipse.core.runtime.Status;
-import org.osgi.framework.BundleContext;
 
 /**
  * The activator class controls the plug-in life cycle
@@ -38,26 +37,6 @@
 	 */
 	public Activator() {
 		plugin = this;
-	}
-
-	/*
-	 * (non-Javadoc)
-	 * 
-	 * @see org.eclipse.core.runtime.Plugins#start(org.osgi.framework.BundleContext)
-	 */
-	public void start(BundleContext context) throws Exception {
-		super.start(context);
-	}
-
-	/*
-	 * (non-Javadoc)
-	 * 
-	 * @see org.eclipse.core.runtime.Plugin#stop(org.osgi.framework.BundleContext)
-	 */
-	public void stop(BundleContext context) throws Exception {
-		JMXAgent.getInstance().stop();
-		plugin = null;
-		super.stop(context);
 	}
 
 	/**

Modified: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v1.core/src/org/apache/geronimo/st/v1/core/GeronimoServerBehaviour.java
URL: http://svn.apache.org/viewvc/geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v1.core/src/org/apache/geronimo/st/v1/core/GeronimoServerBehaviour.java?rev=430623&r1=430622&r2=430623&view=diff
==============================================================================
--- geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v1.core/src/org/apache/geronimo/st/v1/core/GeronimoServerBehaviour.java (original)
+++ geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v1.core/src/org/apache/geronimo/st/v1/core/GeronimoServerBehaviour.java Thu Aug 10 19:18:06 2006
@@ -83,37 +83,29 @@
 		Trace.trace(Trace.INFO, "<-- stop()");
 	}
 
-	private Kernel getKernel() throws SecurityException {
-
+	/**
+	 * @return
+	 * @throws SecurityException
+	 */
+	protected Kernel getKernel() throws SecurityException {
 		if (kernel == null) {
-			Map map = new HashMap();
-			String user = getGeronimoServer().getAdminID();
-			String password = getGeronimoServer().getAdminPassword();
-			map.put("jmx.remote.credentials", new String[] { user, password });
 			try {
-				String url = getGeronimoServer().getJMXServiceURL();
-				if (url == null)
-					return null;
-				JMXServiceURL address = new JMXServiceURL(url);
-				try {
-					JMXConnector jmxConnector = JMXConnectorFactory.connect(address, map);
-					MBeanServerConnection mbServerConnection = jmxConnector.getMBeanServerConnection();
-					kernel = new KernelDelegate(mbServerConnection);
-					Trace.trace(Trace.INFO, "Connected to kernel: " + url);
-				} catch (SecurityException e) {
-					throw e;
-				} catch (Exception e) {
-					Trace.trace(Trace.WARNING, "Kernel connection failed." + url);
-				}
-			} catch (MalformedURLException e) {
+				MBeanServerConnection connection = getServerConnection();
+				if (connection != null)
+					kernel = new KernelDelegate(connection);
+			} catch (SecurityException e) {
+				throw e;
+			} catch (Exception e) {
+				Trace.trace(Trace.WARNING, "Kernel connection failed.");
 				e.printStackTrace();
 			}
 		}
-
 		return kernel;
 	}
 
-	/* (non-Javadoc)
+	/*
+	 * (non-Javadoc)
+	 * 
 	 * @see org.apache.geronimo.st.core.IGeronimoServerBehavior#isKernelAlive()
 	 */
 	public boolean isKernelAlive() {
@@ -132,7 +124,9 @@
 		return false;
 	}
 
-	/* (non-Javadoc)
+	/*
+	 * (non-Javadoc)
+	 * 
 	 * @see org.apache.geronimo.st.core.IGeronimoServerBehavior#isFullyStarted()
 	 */
 	public boolean isFullyStarted() {
@@ -157,33 +151,38 @@
 		return false;
 	}
 
-	/* (non-Javadoc)
+	/*
+	 * (non-Javadoc)
+	 * 
 	 * @see org.apache.geronimo.st.core.GenericGeronimoServerBehaviour#getConfigId(org.eclipse.wst.server.core.IModule)
 	 */
 	public String getConfigId(IModule module) {
 		return GeronimoV1Utils.getConfigId(module);
 	}
-	
-	
-	/* (non-Javadoc)
+
+	/*
+	 * (non-Javadoc)
+	 * 
 	 * @see org.apache.geronimo.st.core.IGeronimoServerBehavior#getTargets()
 	 */
 	public Target[] getTargets() {
 		return null;
 	}
-	
-	/* (non-Javadoc)
+
+	/*
+	 * (non-Javadoc)
+	 * 
 	 * @see org.eclipse.wst.server.core.internal.IModulePublishHelper#getPublishDirectory(org.eclipse.wst.server.core.IModule[])
 	 */
 	public IPath getPublishDirectory(IModule[] module) {
-		if(module == null || module.length == 0)
+		if (module == null || module.length == 0)
 			return null;
-		
+
 		try {
 			String configId = getConfigId(module[0]);
 			ObjectName on = Configuration.getConfigurationObjectName(URI.create(configId));
 			GBeanData data = kernel.getGBeanData(on);
-			URL url = (URL) data.getAttribute("baseURL");	
+			URL url = (URL) data.getAttribute("baseURL");
 			return getModulePath(module, url);
 		} catch (MalformedObjectNameException e) {
 			e.printStackTrace();
@@ -192,11 +191,13 @@
 		} catch (InternalKernelException e) {
 			e.printStackTrace();
 		}
-		
+
 		return null;
 	}
-	
-	/* (non-Javadoc)
+
+	/*
+	 * (non-Javadoc)
+	 * 
 	 * @see org.apache.geronimo.st.core.GenericGeronimoServerBehaviour#getContextClassLoader()
 	 */
 	protected ClassLoader getContextClassLoader() {

Modified: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v11.core/src/org/apache/geronimo/st/v11/core/GeronimoServerBehaviour.java
URL: http://svn.apache.org/viewvc/geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v11.core/src/org/apache/geronimo/st/v11/core/GeronimoServerBehaviour.java?rev=430623&r1=430622&r2=430623&view=diff
==============================================================================
--- geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v11.core/src/org/apache/geronimo/st/v11/core/GeronimoServerBehaviour.java (original)
+++ geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v11.core/src/org/apache/geronimo/st/v11/core/GeronimoServerBehaviour.java Thu Aug 10 19:18:06 2006
@@ -16,17 +16,11 @@
 package org.apache.geronimo.st.v11.core;
 
 import java.io.IOException;
-import java.net.MalformedURLException;
 import java.net.URL;
-import java.util.HashMap;
-import java.util.Map;
 import java.util.Set;
 
 import javax.enterprise.deploy.spi.Target;
 import javax.management.MBeanServerConnection;
-import javax.management.remote.JMXConnector;
-import javax.management.remote.JMXConnectorFactory;
-import javax.management.remote.JMXServiceURL;
 import javax.naming.directory.NoSuchAttributeException;
 
 import org.apache.geronimo.deployment.plugin.TargetImpl;
@@ -40,8 +34,8 @@
 import org.apache.geronimo.kernel.config.InvalidConfigException;
 import org.apache.geronimo.kernel.config.PersistentConfigurationList;
 import org.apache.geronimo.kernel.repository.Artifact;
-import org.apache.geronimo.st.core.GeronimoServerBehaviourDelegate;
 import org.apache.geronimo.st.core.GeronimoConnectionFactory;
+import org.apache.geronimo.st.core.GeronimoServerBehaviourDelegate;
 import org.apache.geronimo.st.jmxagent.Activator;
 import org.apache.geronimo.st.jmxagent.JMXAgent;
 import org.apache.geronimo.st.v11.core.internal.Trace;
@@ -97,34 +91,23 @@
 		Trace.trace(Trace.INFO, "<-- stop()");
 	}
 
+	/**
+	 * @return
+	 * @throws SecurityException
+	 */
 	protected Kernel getKernel() throws SecurityException {
-
 		if (kernel == null) {
-			Map map = new HashMap();
-			String user = getGeronimoServer().getAdminID();
-			String password = getGeronimoServer().getAdminPassword();
-			map.put("jmx.remote.credentials", new String[] { user, password });
 			try {
-				String url = getGeronimoServer().getJMXServiceURL();
-				if (url == null)
-					return null;
-				JMXServiceURL address = new JMXServiceURL(url);
-				try {
-					JMXConnector jmxConnector = JMXConnectorFactory.connect(address, map);
-					MBeanServerConnection mbServerConnection = jmxConnector.getMBeanServerConnection();
-					kernel = new KernelDelegate(mbServerConnection);
-					Trace.trace(Trace.INFO, "Connected to kernel." + url);
-				} catch (SecurityException e) {
-					throw e;
-				} catch (Exception e) {
-					Trace.trace(Trace.WARNING, "Kernel connection failed."
-							+ url);
-				}
-			} catch (MalformedURLException e) {
+				MBeanServerConnection connection = getServerConnection();
+				if (connection != null)
+					kernel = new KernelDelegate(connection);
+			} catch (SecurityException e) {
+				throw e;
+			} catch (Exception e) {
+				Trace.trace(Trace.WARNING, "Kernel connection failed.");
 				e.printStackTrace();
 			}
 		}
-
 		return kernel;
 	}
 
@@ -215,9 +198,10 @@
 	public IPath getPublishDirectory(IModule[] module) {
 		if (module == null || module.length == 0)
 			return null;
-		
-		if(getGeronimoServer().isRunFromWorkspace()) {
-			//TODO fix me, see if project root, component root, or output container should be returned
+
+		if (getGeronimoServer().isRunFromWorkspace()) {
+			// TODO fix me, see if project root, component root, or output
+			// container should be returned
 			return module[module.length - 1].getProject().getLocation();
 		} else {
 			try {
@@ -233,7 +217,7 @@
 				e.printStackTrace();
 			} catch (InternalKernelException e) {
 				e.printStackTrace();
-			}			
+			}
 		}
 
 		return null;