You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by re...@apache.org on 2002/02/19 06:57:38 UTC

cvs commit: jakarta-commons-sandbox/daemon/src/test/org/apache/commons/daemon SimpleDaemon.java

remm        02/02/18 21:57:38

  Modified:    daemon/src/test/org/apache/commons/daemon SimpleDaemon.java
  Log:
  - Update SimpleDaemon for the new API.
  - jsvc is now able to run SimpleDaemon as a daemon under Cygwin :)
  
  Revision  Changes    Path
  1.2       +41 -41    jakarta-commons-sandbox/daemon/src/test/org/apache/commons/daemon/SimpleDaemon.java
  
  Index: SimpleDaemon.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/daemon/src/test/org/apache/commons/daemon/SimpleDaemon.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- SimpleDaemon.java	18 Feb 2002 21:15:48 -0000	1.1
  +++ SimpleDaemon.java	19 Feb 2002 05:57:38 -0000	1.2
  @@ -55,7 +55,7 @@
    *                                                                           *
    * ========================================================================= */
   
  -/* @version $Id: SimpleDaemon.java,v 1.1 2002/02/18 21:15:48 remm Exp $ */
  +/* @version $Id: SimpleDaemon.java,v 1.2 2002/02/19 05:57:38 remm Exp $ */
   
   package org.apache.commons.daemon;
   
  @@ -66,8 +66,8 @@
   import java.util.Enumeration;
   import java.util.Vector;
   import org.apache.commons.daemon.Daemon;
  -import org.apache.commons.DaemonController;
  -import org.apache.commons.DaemonContext;
  +import org.apache.commons.daemon.DaemonController;
  +import org.apache.commons.daemon.DaemonContext;
   
   public class SimpleDaemon implements Daemon, Runnable {
   
  @@ -97,46 +97,11 @@
       throws Exception {
           System.err.println("SimpleDaemon: instance "+this.hashCode()+
                              " init");
  -    }
  -    public void destroy() {
  -        System.err.println("SimpleDaemon: instance "+this.hashCode()+
  -                           " destroy");
  -    }
  -
  -    public void run() {
  -        int number=0;
  -
  -        System.err.println("SimpleDaemon: started acceptor loop");
  -        try {
  -            while(!this.stopping) {
  -                Socket socket=this.server.accept();
  -                Handler handler=new Handler(socket,this,this.controller);
  -                handler.setConnectionNumber(number++);
  -                handler.setDirectoryName(this.directory);
  -                new Thread(handler).start();
  -            }
  -        } catch (IOException e) {
  -            /* Don't dump any error message if we are stopping. A IOException
  -               is generated when the ServerSocket is closed in stop() */
  -            if (!this.stopping) e.printStackTrace(System.err);
  -        }
  -
  -        /* Terminate all handlers that at this point are still open */
  -        Enumeration openhandlers=this.handlers.elements();
  -        while (openhandlers.hasMoreElements()) {
  -            Handler handler=(Handler)openhandlers.nextElement();
  -            System.err.println("SimpleDaemon: dropping connection "+
  -                               handler.getConnectionNumber());
  -            handler.close();
  -        }
   
  -        System.err.println("SimpleDaemon: exiting acceptor loop");
  -    }
  -
  -    public void load(DaemonController controller, String a[])
  -    throws IOException {
           int port=1200;
   
  +        String[] a = context.getArguments();
  +
           if (a.length>0) port=Integer.parseInt(a[0]);
           if (a.length>1) this.directory=a[1];
           else this.directory="/tmp";
  @@ -145,7 +110,7 @@
           System.err.println("SimpleDaemon: loading on port "+port);
   
           /* Set up this simple daemon */
  -        this.controller=controller;
  +        this.controller=context.getController();
           this.server=new ServerSocket(port);
           this.thread=new Thread(this);
       }
  @@ -170,6 +135,41 @@
           /* Wait for the main thread to exit and dump a message */
           this.thread.join(5000);
           System.err.println("SimpleDaemon: stopped");
  +    }
  +
  +    public void destroy() {
  +        System.err.println("SimpleDaemon: instance "+this.hashCode()+
  +                           " destroy");
  +    }
  +
  +    public void run() {
  +        int number=0;
  +
  +        System.err.println("SimpleDaemon: started acceptor loop");
  +        try {
  +            while(!this.stopping) {
  +                Socket socket=this.server.accept();
  +                Handler handler=new Handler(socket,this,this.controller);
  +                handler.setConnectionNumber(number++);
  +                handler.setDirectoryName(this.directory);
  +                new Thread(handler).start();
  +            }
  +        } catch (IOException e) {
  +            /* Don't dump any error message if we are stopping. A IOException
  +               is generated when the ServerSocket is closed in stop() */
  +            if (!this.stopping) e.printStackTrace(System.err);
  +        }
  +
  +        /* Terminate all handlers that at this point are still open */
  +        Enumeration openhandlers=this.handlers.elements();
  +        while (openhandlers.hasMoreElements()) {
  +            Handler handler=(Handler)openhandlers.nextElement();
  +            System.err.println("SimpleDaemon: dropping connection "+
  +                               handler.getConnectionNumber());
  +            handler.close();
  +        }
  +
  +        System.err.println("SimpleDaemon: exiting acceptor loop");
       }
   
       protected void addHandler(Handler handler) {
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>