View Javadoc

    1   //========================================================================
    2   //Copyright 2004-2008 Mort Bay Consulting Pty. Ltd.
    3   //------------------------------------------------------------------------
    4   //Licensed under the Apache License, Version 2.0 (the "License");
    5   //you may not use this file except in compliance with the License.
    6   //You may obtain a copy of the License at
    7   //http://www.apache.org/licenses/LICENSE-2.0
    8   //Unless required by applicable law or agreed to in writing, software
    9   //distributed under the License is distributed on an "AS IS" BASIS,
    10  //WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    11  //See the License for the specific language governing permissions and
    12  //limitations under the License.
    13  //========================================================================
    14
    15  package org.mortbay.jetty.win32service;
    16
    17  import org.mortbay.jetty.Server;
    18  import org.tanukisoftware.wrapper.WrapperManager;
    19  import org.tanukisoftware.wrapper.WrapperListener;
    20  import java.io.File;
    21  public class JettyServiceWrapperListener implements WrapperListener
    22  {
    23      private static Server __server = null;
    24
    25      public JettyServiceWrapperListener()
    26      {
    27      }
    28
    29      public void controlEvent(int event)
    30      {
    31          if (!WrapperManager.isControlledByNativeWrapper())
    32          {
    33              if ((event == WrapperManager.WRAPPER_CTRL_C_EVENT) || (event == WrapperManager.WRAPPER_CTRL_CLOSE_EVENT) || (event == WrapperManager.WRAPPER_CTRL_SHUTDOWN_EVENT))
    34              {
    35                  WrapperManager.stop(0);
    36              }
    37          }
    38
    39      }
    40
    41      public Integer start(String[] args)
    42      {
    43          for(int i=0; i<args.length; i++)
    44          {
    45              System.out.println("ARG[" + i + "] = " + args[i]);
    46          }
    47          org.mortbay.start.Main.main(args);
    48          return null;
    49      }
    50
    51      public int stop(int code)
    52      {
    53          try
    54          {
    55              System.out.println("JettyServiceWrapperListener: Stopping Jetty 6 Service!!!");
    56              __server.stop();
    57              System.out.println("JettyServiceWrapperListener: Jetty 6 Service Stopped!!!");
    58              return code;
    59          }
    60          catch (Exception e)
    61          {
    62              System.out.println("Stop Server Error");
    63              e.printStackTrace();
    64              return -1;
    65          }
    66
    67      }
    68
    69      public static void setServer(Server server)
    70      {
    71          __server = server;
    72      }
    73
    74      public static Server getServer()
    75      {
    76          return __server;
    77      }
    78
    79      public static void main(String[] args)
    80      {
    81          String newStrArgs[] = new String[args.length + 1];
    82          newStrArgs[0] = System.getProperty("jetty.home") + "etc/jetty-win32-service.xml";
    83          for(int i=0; i<args.length; i++)
    84          {
    85              newStrArgs[i+1] = args[i];
    86          }
    87          WrapperManager.start(new JettyServiceWrapperListener(), newStrArgs);
    88      }
    89
    90  }