You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by jd...@apache.org on 2006/09/04 01:49:11 UTC
svn commit: r439875 - in
/geronimo/server/trunk/maven-plugins/geronimo-maven-plugin: pom.xml
src/main/java/org/apache/geronimo/mavenplugins/geronimo/ServerProxy.java
src/main/java/org/apache/geronimo/mavenplugins/geronimo/StartServerMojo.java
Author: jdillon
Date: Sun Sep 3 16:49:11 2006
New Revision: 439875
URL: http://svn.apache.org/viewvc?view=rev&rev=439875
Log:
Adding ServerProxy helper to facilitate checking if the server is loaded
Unfortunately I was not able to figure out how to do this with JMX alone, so we need to depend on geronimo-kernel to pick up classes
Added:
geronimo/server/trunk/maven-plugins/geronimo-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/geronimo/ServerProxy.java (with props)
Modified:
geronimo/server/trunk/maven-plugins/geronimo-maven-plugin/pom.xml
geronimo/server/trunk/maven-plugins/geronimo-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/geronimo/StartServerMojo.java
Modified: geronimo/server/trunk/maven-plugins/geronimo-maven-plugin/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/maven-plugins/geronimo-maven-plugin/pom.xml?view=diff&rev=439875&r1=439874&r2=439875
==============================================================================
--- geronimo/server/trunk/maven-plugins/geronimo-maven-plugin/pom.xml (original)
+++ geronimo/server/trunk/maven-plugins/geronimo-maven-plugin/pom.xml Sun Sep 3 16:49:11 2006
@@ -35,7 +35,20 @@
<description>
Geronimo plugin for Maven 2; used to install, start and stop the server.
</description>
-
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.geronimo.modules</groupId>
+ <artifactId>geronimo-kernel</artifactId>
+ <version>${pom.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>mx4j</groupId>
+ <artifactId>mx4j-remote</artifactId>
+ </dependency>
+ </dependencies>
+
<build>
<plugins>
<plugin>
Added: geronimo/server/trunk/maven-plugins/geronimo-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/geronimo/ServerProxy.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/maven-plugins/geronimo-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/geronimo/ServerProxy.java?view=auto&rev=439875
==============================================================================
--- geronimo/server/trunk/maven-plugins/geronimo-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/geronimo/ServerProxy.java (added)
+++ geronimo/server/trunk/maven-plugins/geronimo-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/geronimo/ServerProxy.java Sun Sep 3 16:49:11 2006
@@ -0,0 +1,182 @@
+/*
+ * Copyright 2006 The Apache Software Foundation
+ *
+ * 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.mavenplugins.geronimo;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+import java.util.Iterator;
+import java.io.IOException;
+
+import javax.management.remote.JMXServiceURL;
+import javax.management.remote.JMXConnector;
+import javax.management.remote.JMXConnectorFactory;
+import javax.management.MBeanServerConnection;
+
+//
+// FIXME: It should be possible to query state with-out any Geronimo classes,
+// just using JMX interfaces.
+//
+
+import org.apache.geronimo.gbean.AbstractName;
+import org.apache.geronimo.gbean.AbstractNameQuery;
+import org.apache.geronimo.kernel.Kernel;
+import org.apache.geronimo.kernel.config.PersistentConfigurationList;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * Helper to communicate with a remote server via JMX.
+ *
+ * @version $Rev$ $Date$
+ */
+public class ServerProxy
+{
+ private static final Log log = LogFactory.getLog(ServerProxy.class);
+
+ private JMXServiceURL url;
+
+ private Map environment;
+
+ private MBeanServerConnection mbeanConnection;
+
+ private Throwable lastError;
+
+ public ServerProxy(final JMXServiceURL url, final Map environment) throws Exception {
+ init(url, environment);
+ }
+
+ public ServerProxy(final int port, final String username, final String password) throws Exception {
+ //
+ // FIXME: Should be able to pass in hostname too
+ //
+
+ this("service:jmx:rmi://localhost/jndi/rmi://localhost:" + port + "/JMXConnector", username, password);
+ }
+
+ public ServerProxy(final String url, final String username, final String password) throws Exception {
+ assert url != null;
+ assert username != null;
+ assert password != null;
+
+ Map env = new HashMap();
+ env.put("jmx.remote.credentials", new String[] {username, password});
+
+ init(new JMXServiceURL(url), env);
+ }
+
+ private void init(final JMXServiceURL url, final Map environment) throws Exception {
+ assert url != null;
+ assert environment != null;
+
+ this.url = url;
+ this.environment = new HashMap();
+ this.environment.put("jmx.remote.credentials", new String[] {"system", "manager"});
+
+ log.info("Initialized with URL: " + url);
+ }
+
+ private MBeanServerConnection getConnection() throws IOException {
+ if (this.mbeanConnection == null) {
+ log.info("Connecting to: " + url);
+
+ JMXConnector connector = JMXConnectorFactory.connect(url, environment);
+ this.mbeanConnection = connector.getMBeanServerConnection();
+ }
+
+ return mbeanConnection;
+ }
+
+ public boolean isFullyStarted() {
+ boolean fullyStarted = true;
+
+ try {
+ AbstractNameQuery query = new AbstractNameQuery(PersistentConfigurationList.class.getName());
+ Set result = listGBeans(query);
+ Iterator iter = result.iterator();
+ while (iter.hasNext()) {
+ AbstractName name = (AbstractName)iter.next();
+ boolean started = getBooleanAttribute(name, "kernelFullyStarted");
+ if (!started) {
+ fullyStarted = false;
+ break;
+ }
+ }
+ }
+ catch (IOException e) {
+ log.debug("Connection failure; ignoring", e);
+ fullyStarted = false;
+ lastError = e;
+ }
+ catch (Exception e) {
+ log.warn("Unable to determine if the kernel is fully started", e);
+ fullyStarted = false;
+ lastError = e;
+ }
+
+ return fullyStarted;
+ }
+
+ public Throwable getLastError() {
+ return lastError;
+ }
+
+ //
+ // Kernel invocation helpers
+ //
+
+ private Object invoke(final String operation, final Object[] args, final String[] signature) throws Exception {
+ assert operation != null;
+ assert args != null;
+ assert signature != null;
+
+ return getConnection().invoke(Kernel.KERNEL, operation, args, signature);
+ }
+
+ private Object invoke(final String operation, final Object[] args) throws Exception {
+ assert args != null;
+
+ String[] signature = new String[args.length];
+ for (int i=0; i<args.length; i++) {
+ signature[i] = args[i].getClass().getName();
+ }
+
+ return invoke(operation, args, signature);
+ }
+
+ private Set listGBeans(final AbstractNameQuery query) throws Exception {
+ return (Set)invoke("listGBeans", new Object[] { query });
+ }
+
+ private Object getAttribute(final AbstractName name, final String attribute) throws Exception {
+ assert name != null;
+ assert attribute != null;
+
+ return invoke("getAttribute", new Object[] { name, attribute });
+ }
+
+ private boolean getBooleanAttribute(final AbstractName name, final String attribute) throws Exception {
+ Object obj = getAttribute(name, attribute);
+ if (obj instanceof Boolean) {
+ return ((Boolean)obj).booleanValue();
+ }
+ else {
+ throw new RuntimeException("Attribute is not of type Boolean: " + attribute);
+ }
+ }
+}
Propchange: geronimo/server/trunk/maven-plugins/geronimo-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/geronimo/ServerProxy.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: geronimo/server/trunk/maven-plugins/geronimo-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/geronimo/ServerProxy.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: geronimo/server/trunk/maven-plugins/geronimo-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/geronimo/ServerProxy.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: geronimo/server/trunk/maven-plugins/geronimo-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/geronimo/StartServerMojo.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/maven-plugins/geronimo-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/geronimo/StartServerMojo.java?view=diff&rev=439875&r1=439874&r2=439875
==============================================================================
--- geronimo/server/trunk/maven-plugins/geronimo-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/geronimo/StartServerMojo.java (original)
+++ geronimo/server/trunk/maven-plugins/geronimo-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/geronimo/StartServerMojo.java Sun Sep 3 16:49:11 2006
@@ -19,7 +19,6 @@
import org.apache.maven.plugin.MojoExecutionException;
import java.io.File;
-import java.net.URL;
import java.util.Timer;
import java.util.TimerTask;
@@ -219,14 +218,8 @@
timer.schedule(timeoutTask, verifyTimeout * 1000);
}
- //
- // TODO: Check the status via JMX:
- //
- // "service:jmx:rmi://localhost/jndi/rmi://localhost:" + port + "/JMXConnector"
- //
-
// Verify server started
- URL url = new URL("http://localhost:8080");
+ ServerProxy server = new ServerProxy(port, username, password);
boolean started = false;
while (!started) {
if (verifyTimedOut.isSet()) {
@@ -237,28 +230,21 @@
throw new MojoExecutionException("Failed to start Geronimo server", errorHolder.getCause());
}
- log.debug("Trying connection to: " + url);
+ started = server.isFullyStarted();
- try {
- url.openConnection().getContent();
- started = true;
- }
- catch (Exception e) {
- // ignore
- }
+ if (!started) {
+ Throwable error = server.getLastError();
+ if (error != null) {
+ log.debug("Server query failed; ignoring", error);
+ }
- Thread.sleep(1000);
+ Thread.sleep(1000);
+ }
}
// Stop the timer, server should be up now
timeoutTask.cancel();
-
- //
- // HACK: Give it a few seconds... our detection method here is lossy
- //
-
- Thread.sleep(10000);
-
+
log.info("Geronimo server started");
if (!background) {