Home » openejb-3.1.2-src » org.apache » openejb » server » admin » [javadoc | source]

    1   /**
    2    * Licensed to the Apache Software Foundation (ASF) under one or more
    3    * contributor license agreements.  See the NOTICE file distributed with
    4    * this work for additional information regarding copyright ownership.
    5    * The ASF licenses this file to You under the Apache License, Version 2.0
    6    * (the "License"); you may not use this file except in compliance with
    7    * the License.  You may obtain a copy of the License at
    8    *
    9    *     http://www.apache.org/licenses/LICENSE-2.0
   10    *
   11    * Unless required by applicable law or agreed to in writing, software
   12    * distributed under the License is distributed on an "AS IS" BASIS,
   13    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   14    * See the License for the specific language governing permissions and
   15    * limitations under the License.
   16    */
   17   package org.apache.openejb.server.admin;
   18   
   19   import java.io.InputStream;
   20   import java.io.OutputStream;
   21   import java.net.ConnectException;
   22   import java.net.Socket;
   23   import java.net.URL;
   24   import java.util.Properties;
   25   
   26   import org.apache.openejb.client.RequestMethodConstants;
   27   
   28   
   29   public class Stop {
   30   
   31       private static final String helpBase = "META-INF/org.apache.openejb.cli/";
   32   
   33       public static void stop(String host, int port) {
   34           try {
   35   
   36               Socket socket = new Socket(host, port);
   37               OutputStream out = socket.getOutputStream();
   38   
   39               out.write(RequestMethodConstants.STOP_REQUEST_Stop);
   40   
   41           } catch (ConnectException e) {
   42               System.out.println(":: server not running ::");
   43           } catch (Exception e) {
   44               e.printStackTrace();
   45           }
   46       }
   47   
   48       public void stop() {
   49           stop("localhost", 4200);
   50       }
   51   
   52       public static void main(String [] args) {
   53           try {
   54   
   55               String host = "localhost";
   56   
   57               int port = 4200;
   58   
   59               for (int i = 0; i < args.length; i++) {
   60                   if (args[i].equals("-h")) {
   61                       if (args.length > i + 1) {
   62                           host = args[++i];
   63                       }
   64                   } else if (args[i].equals("-p")) {
   65                       if (args.length > i + 1) {
   66                           port = Integer.parseInt(args[++i]);
   67                       }
   68                   } else if (args[i].equals("--help")) {
   69                       printHelp();
   70                       return;
   71                   } else if (args[i].equals("-examples")) {
   72                       printExamples();
   73                       return;
   74                   }
   75               }
   76   
   77               stop(host, port);
   78           } catch (Exception re) {
   79               System.err.println("[EJB Server] FATAL ERROR: " + re.getMessage());
   80               re.printStackTrace();
   81           }
   82       }
   83   
   84       private static void printHelp() {
   85           String header = "OpenEJB Remote Server ";
   86           try {
   87               Properties versionInfo = new Properties();
   88               versionInfo.load(new URL("resource:/openejb-version.properties").openConnection().getInputStream());
   89               header += versionInfo.get("version");
   90           } catch (java.io.IOException e) {
   91           }
   92   
   93           System.out.println(header);
   94   
   95           try {
   96               InputStream in = Thread.currentThread().getContextClassLoader().getResource(helpBase + "stop.help").openConnection().getInputStream();
   97   
   98               int b = in.read();
   99               while (b != -1) {
  100                   System.out.write(b);
  101                   b = in.read();
  102               }
  103           } catch (java.io.IOException e) {
  104           }
  105       }
  106   
  107       private static void printExamples() {
  108           String header = "OpenEJB Remote Server ";
  109           try {
  110               Properties versionInfo = new Properties();
  111               versionInfo.load(new URL("resource:/openejb-version.properties").openConnection().getInputStream());
  112               header += versionInfo.get("version");
  113           } catch (java.io.IOException e) {
  114           }
  115   
  116           System.out.println(header);
  117   
  118           try {
  119               InputStream in = Thread.currentThread().getContextClassLoader().getResource(helpBase + "stop.examples").openConnection().getInputStream();
  120   
  121               int b = in.read();
  122               while (b != -1) {
  123                   System.out.write(b);
  124                   b = in.read();
  125               }
  126           } catch (java.io.IOException e) {
  127           }
  128       }
  129   }

Home » openejb-3.1.2-src » org.apache » openejb » server » admin » [javadoc | source]