Save This Page
Home » geronimo-2.2-source-release » org.apache.geronimo.mavenplugins.geronimo.server » [javadoc | source]
    1   /**
    2    *  Licensed to the Apache Software Foundation (ASF) under one
    3    *  or more contributor license agreements.  See the NOTICE file
    4    *  distributed with this work for additional information
    5    *  regarding copyright ownership.  The ASF licenses this file
    6    *  to you under the Apache License, Version 2.0 (the
    7    *  "License"); you may not use this file except in compliance
    8    *  with the License.  You may obtain a copy of the License at
    9    *
   10    *    http://www.apache.org/licenses/LICENSE-2.0
   11    *
   12    *  Unless required by applicable law or agreed to in writing,
   13    *  software distributed under the License is distributed on an
   14    *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
   15    *  KIND, either express or implied.  See the License for the
   16    *  specific language governing permissions and limitations
   17    *  under the License.
   18    */
   19   package org.apache.geronimo.mavenplugins.geronimo.server;
   20   
   21   import org.apache.maven.plugin.MojoExecutionException;
   22   
   23   import org.codehaus.mojo.pluginsupport.util.ObjectHolder;
   24   
   25   import org.apache.geronimo.mavenplugins.geronimo.ServerProxy;
   26   import org.apache.geronimo.mavenplugins.geronimo.reporting.ReportingMojoSupport;
   27   
   28   import java.util.Timer;
   29   import java.util.TimerTask;
   30   
   31   /**
   32    * Wait for a Geronimo server to start.
   33    *
   34    * @goal wait-for-server
   35    *
   36    * @version $Rev: 666809 $ $Date: 2008-06-11 12:54:01 -0700 (Wed, 11 Jun 2008) $
   37    */
   38   public class WaitForServerMojo
   39       extends ReportingMojoSupport
   40   {
   41       /**
   42        * Time in seconds to wait while verifing that the server has started.
   43        *
   44        * @parameter expression="${timeout}" default-value="-1"
   45        */
   46       private int timeout = -1;
   47   
   48       private Timer timer = new Timer(true);
   49   
   50       //
   51       // TODO: See if start-server can share some of this code
   52       //
   53   
   54       protected void doExecute() throws Exception {
   55           log.info("Waiting for Geronimo server...");
   56   
   57           // Setup a callback to time out verification
   58           final ObjectHolder verifyTimedOut = new ObjectHolder();
   59   
   60           TimerTask timeoutTask = new TimerTask() {
   61               public void run() {
   62                   verifyTimedOut.set(Boolean.TRUE);
   63               }
   64           };
   65   
   66           if (timeout > 0) {
   67               log.debug("Starting verify timeout task; triggers in: " + timeout + "s");
   68               timer.schedule(timeoutTask, timeout * 1000);
   69           }
   70   
   71           // Verify server started
   72           ServerProxy server = new ServerProxy(hostname, port, username, password);
   73           boolean started = false;
   74           while (!started) {
   75               if (verifyTimedOut.isSet()) {
   76                   throw new MojoExecutionException("Unable to verify if the server was started in the given time");
   77               }
   78   
   79               started = server.isFullyStarted();
   80   
   81               if (!started) {
   82                   Throwable error = server.getLastError();
   83                   if (error != null) {
   84                       log.debug("Server query failed; ignoring", error);
   85                   }
   86   
   87                   Thread.sleep(1000);
   88               }
   89           }
   90           server.closeConnection();
   91   
   92           // Stop the timer, server should be up now
   93           timeoutTask.cancel();
   94   
   95           log.info("Geronimo server started");
   96       }
   97   
   98       protected String getFullClassName() {
   99           return this.getClass().getName();
  100       } 
  101   }

Save This Page
Home » geronimo-2.2-source-release » org.apache.geronimo.mavenplugins.geronimo.server » [javadoc | source]