geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jdil...@apache.org
Subject svn commit: r453457 - in /geronimo/server/trunk/maven-plugins/geronimo-maven-plugin/src: main/java/org/apache/geronimo/mavenplugins/geronimo/server/WaitForServerMojo.java site/apt/usage/server.apt
Date Fri, 06 Oct 2006 01:51:19 GMT
Author: jdillon
Date: Thu Oct  5 18:51:18 2006
New Revision: 453457

URL: http://svn.apache.org/viewvc?view=rev&rev=453457
Log:
Add goal to simply wait for a server to be started

Added:
    geronimo/server/trunk/maven-plugins/geronimo-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/geronimo/server/WaitForServerMojo.java
  (with props)
Modified:
    geronimo/server/trunk/maven-plugins/geronimo-maven-plugin/src/site/apt/usage/server.apt

Added: geronimo/server/trunk/maven-plugins/geronimo-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/geronimo/server/WaitForServerMojo.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/maven-plugins/geronimo-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/geronimo/server/WaitForServerMojo.java?view=auto&rev=453457
==============================================================================
--- geronimo/server/trunk/maven-plugins/geronimo-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/geronimo/server/WaitForServerMojo.java
(added)
+++ geronimo/server/trunk/maven-plugins/geronimo-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/geronimo/server/WaitForServerMojo.java
Thu Oct  5 18:51:18 2006
@@ -0,0 +1,102 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.server;
+
+import org.apache.maven.plugin.MojoExecutionException;
+
+import org.apache.geronimo.genesis.ObjectHolder;
+import org.apache.geronimo.mavenplugins.geronimo.ServerProxy;
+import org.apache.geronimo.mavenplugins.geronimo.reporting.ReportingMojoSupport;
+
+import java.util.Timer;
+import java.util.TimerTask;
+
+/**
+ * Wait for a Geronimo server to start.
+ *
+ * @goal wait-for-server
+ *
+ * @version $Rev$ $Date$
+ */
+public class WaitForServerMojo
+    extends ReportingMojoSupport
+{
+    /**
+     * Time in seconds to wait while verifing that the server has started.
+     *
+     * @parameter expression="${timeout}" default-value="-1"
+     */
+    private int timeout = -1;
+
+    private Timer timer = new Timer(true);
+
+    //
+    // TODO: See if start-server can share some of this code
+    //
+
+    protected void doExecute() throws Exception {
+        log.info("Waiting for Geronimo server...");
+
+        // Setup a callback to time out verification
+        final ObjectHolder verifyTimedOut = new ObjectHolder();
+
+        TimerTask timeoutTask = new TimerTask() {
+            public void run() {
+                verifyTimedOut.set(Boolean.TRUE);
+            }
+        };
+
+        if (timeout > 0) {
+            log.debug("Starting verify timeout task; triggers in: " + timeout + "s");
+            timer.schedule(timeoutTask, timeout * 1000);
+        }
+
+        // Verify server started
+        ServerProxy server = new ServerProxy(hostname, port, username, password);
+        boolean started = false;
+        while (!started) {
+            if (verifyTimedOut.isSet()) {
+                throw new MojoExecutionException("Unable to verify if the server was started
in the given time");
+            }
+
+            started = server.isFullyStarted();
+
+            if (!started) {
+                Throwable error = server.getLastError();
+                if (error != null) {
+                    log.debug("Server query failed; ignoring", error);
+                }
+
+                Thread.sleep(1000);
+            }
+        }
+
+        // Stop the timer, server should be up now
+        timeoutTask.cancel();
+
+        log.info("Geronimo server started");
+    }
+
+    protected String getGoalName() {
+        //
+        //FIXME: There has to be way this can be computed instead of hardcoded absolutely.
+        //
+        return "wait-for-server";
+    }
+}

Propchange: geronimo/server/trunk/maven-plugins/geronimo-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/geronimo/server/WaitForServerMojo.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/server/trunk/maven-plugins/geronimo-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/geronimo/server/WaitForServerMojo.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/server/WaitForServerMojo.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: geronimo/server/trunk/maven-plugins/geronimo-maven-plugin/src/site/apt/usage/server.apt
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/maven-plugins/geronimo-maven-plugin/src/site/apt/usage/server.apt?view=diff&rev=453457&r1=453456&r2=453457
==============================================================================
--- geronimo/server/trunk/maven-plugins/geronimo-maven-plugin/src/site/apt/usage/server.apt
(original)
+++ geronimo/server/trunk/maven-plugins/geronimo-maven-plugin/src/site/apt/usage/server.apt
Thu Oct  5 18:51:18 2006
@@ -154,6 +154,18 @@
 mvn geronimo:start -Ddebug=true
 +----------+
 
+ If you already have a server started and just need to wait until the server has started:
+
++----------+
+mvn geronimo:wait-for-server
++----------+
+
+ To only wait for a specific period you can sepcify a timeout in sections:
+
++----------+
+mvn geronimo:wait-for-server -Dtimeout=60
++----------+
+
 * Stopping Geronimo Server
 
  To stop a server using the defaults, which is probably fine in most cases, just invoke the
{{stop}} goal.



Mime
View raw message