dblevins    2004/12/19 01:17:15

  Modified:    modules/core/src/java/org/openejb/server ServiceDaemon.java
                        ServiceLogger.java ServicePool.java
                        StandardServiceStack.java
  Added:       modules/core/src/java/org/openejb/server
                        StandardServiceStackGBean.java
  Log:

  Added GBean wrappers for HttpServer and StandardServiceStack.  The wrappers 
have an addGbean static method which is great for keeping Gbean code out of 
tests.
  Added a test that tests the HttpServer as a GBean with a POJO stack and 
another test that does the entire stack as GBeans.
  Revamped the services in the stack to make better use of logging.
  
  Revision  Changes    Path
  1.14      +17 -6     
openejb/modules/core/src/java/org/openejb/server/ServiceDaemon.java
  
  Index: ServiceDaemon.java
  ===================================================================
  RCS file: 
/home/projects/openejb/scm/openejb/modules/core/src/java/org/openejb/server/ServiceDaemon.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- ServiceDaemon.java        18 Dec 2004 01:42:15 -0000      1.13
  +++ ServiceDaemon.java        19 Dec 2004 06:17:15 -0000      1.14
  @@ -45,10 +45,7 @@
   package org.openejb.server;
   
   import java.io.IOException;
  -import java.net.InetAddress;
  -import java.net.ServerSocket;
  -import java.net.Socket;
  -import java.net.SocketException;
  +import java.net.*;
   
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
  @@ -65,11 +62,13 @@
   
       private SocketListener socketListener;
       private int timeout;
  +    private String name;
   
       public ServiceDaemon(SocketService socketService, InetAddress address, 
int port) {
           this(null, socketService, address, port);
       }
       public ServiceDaemon(String name, SocketService socketService, 
InetAddress address, int port) {
  +        this.name = name;
           if (socketService == null) {
               throw new IllegalArgumentException("socketService is null");
           }
  @@ -95,7 +94,7 @@
   
           socketListener = new SocketListener(socketService, serverSocket);
           Thread thread = new Thread(socketListener);
  -        thread.setName("service." + getServiceName() + "@" + 
socketListener.hashCode());
  +        thread.setName("service." + name + "@" + socketListener.hashCode());
           thread.setDaemon(true);
           thread.start();
       }
  @@ -118,6 +117,11 @@
           }
       }
   
  +    public int getSoTimeout() throws IOException {
  +        if (socketListener == null) return 0;
  +        return socketListener.getSoTimeout();
  +    }
  +
       public String getServiceName() {
           return socketService.getName();
       }
  @@ -167,6 +171,9 @@
                           // for closing the socket.
                           serverService.service(socket);
                       }
  +                } catch (SocketTimeoutException e) {
  +                    // we don't really care
  +                    log.debug("Socket timed-out",e);
                   } catch (Throwable e) {
                       log.error("Unexpected error", e);
                   }
  @@ -185,6 +192,10 @@
   
           public void setSoTimeout(int timeout) throws SocketException {
               serverSocket.setSoTimeout(timeout);
  +        }
  +
  +        public int getSoTimeout() throws IOException {
  +            return serverSocket.getSoTimeout();
           }
       }
   
  
  
  
  1.6       +3 -3      
openejb/modules/core/src/java/org/openejb/server/ServiceLogger.java
  
  Index: ServiceLogger.java
  ===================================================================
  RCS file: 
/home/projects/openejb/scm/openejb/modules/core/src/java/org/openejb/server/ServiceLogger.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- ServiceLogger.java        17 Dec 2004 05:54:22 -0000      1.5
  +++ ServiceLogger.java        19 Dec 2004 06:17:15 -0000      1.6
  @@ -107,8 +107,8 @@
       public void service(Socket socket) throws ServiceException, IOException {
           // Fill this in more deeply later.
           InetAddress client = socket.getInetAddress();
  -        MDC.put("HOST", client.getHostName());
  -        MDC.put("SERVER", getName());
  +//        MDC.put("HOST", client.getHostName());
  +//        MDC.put("SERVER", getName());
   
           try {
               logIncoming();
  
  
  
  1.5       +8 -4      
openejb/modules/core/src/java/org/openejb/server/ServicePool.java
  
  Index: ServicePool.java
  ===================================================================
  RCS file: 
/home/projects/openejb/scm/openejb/modules/core/src/java/org/openejb/server/ServicePool.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- ServicePool.java  17 Dec 2004 06:12:27 -0000      1.4
  +++ ServicePool.java  19 Dec 2004 06:17:15 -0000      1.5
  @@ -48,6 +48,8 @@
   import java.net.*;
   import java.util.*;
   import org.openejb.*;
  +import org.apache.commons.logging.LogFactory;
  +import org.apache.commons.logging.Log;
   
   /**
    *  The Server will call the following methods.
  @@ -62,7 +64,9 @@
    * 
    */
   public class ServicePool implements ServerService {
  -    
  +
  +    private static final Log log = LogFactory.getLog(ServicePool.class);
  +
       private final ServerService next;
       private final int threads;
       private final int priority;
  @@ -81,9 +85,9 @@
                   try {
                       next.service(socket);
                   } catch (SecurityException e) {
  -                    //logger.error( "Security error: "+ e.getMessage() );
  +                    log.error( "Security error: "+ e.getMessage() );
                   } catch (Throwable e) {
  -                    //logger.error( "Unexpected error", e );
  +                    log.error( "Unexpected error", e );
   
                   } finally {
                       try {
  
  
  
  1.2       +16 -4     
openejb/modules/core/src/java/org/openejb/server/StandardServiceStack.java
  
  Index: StandardServiceStack.java
  ===================================================================
  RCS file: 
/home/projects/openejb/scm/openejb/modules/core/src/java/org/openejb/server/StandardServiceStack.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- StandardServiceStack.java 18 Dec 2004 01:55:43 -0000      1.1
  +++ StandardServiceStack.java 19 Dec 2004 06:17:15 -0000      1.2
  @@ -45,6 +45,8 @@
   package org.openejb.server;
   
   import java.net.InetAddress;
  +import java.net.SocketException;
  +import java.io.IOException;
   
   import org.apache.geronimo.gbean.GBeanLifecycle;
   import org.apache.geronimo.gbean.WaitingException;
  @@ -60,13 +62,17 @@
       private ServerService server;
   
       public StandardServiceStack(String name, int port, InetAddress address, 
InetAddress[] allowHosts, int threads, int priority, String[] logOnSuccess, 
String[] logOnFailure, ServerService server) {
  -        this.name = name;
           this.server = server;
  -
  +        this.name = name;
           this.pool = new ServicePool(name, server, threads, priority);
           this.hba = new ServiceAccessController(name, pool, allowHosts);
           this.logger = new ServiceLogger(name, hba, logOnSuccess, 
logOnFailure);
           this.daemon = new ServiceDaemon(name, logger, address, port);
  +
  +    }
  +
  +    public String getName() {
  +        return name;
       }
   
       public InetAddress getAddress() {
  @@ -77,6 +83,14 @@
           return daemon.getPort();
       }
   
  +    public int getSoTimeout() throws IOException {
  +        return daemon.getSoTimeout();
  +    }
  +
  +    public void setSoTimeout(int timeout) throws SocketException {
  +        daemon.setSoTimeout(timeout);
  +    }
  +
       public String[] getLogOnSuccess() {
           return logger.getLogOnSuccess();
       }
  @@ -112,6 +126,4 @@
       public void doFail() {
           daemon.doFail();
       }
  -
  -
   }
  
  
  
  1.1                  
openejb/modules/core/src/java/org/openejb/server/StandardServiceStackGBean.java
  
  Index: StandardServiceStackGBean.java
  ===================================================================
  /**
   * Redistribution and use of this software and associated documentation
   * ("Software"), with or without modification, are permitted provided
   * that the following conditions are met:
   *
   * 1. Redistributions of source code must retain copyright
   *    statements and notices.  Redistributions must also contain a
   *    copy of this document.
   *
   * 2. Redistributions in binary form must reproduce the
   *    above copyright notice, this list of conditions and the
   *    following disclaimer in the documentation and/or other
   *    materials provided with the distribution.
   *
   * 3. The name "OpenEJB" must not be used to endorse or promote
   *    products derived from this Software without prior written
   *    permission of The OpenEJB Group.  For written permission,
   *    please contact [EMAIL PROTECTED]
   *
   * 4. Products derived from this Software may not be called "OpenEJB"
   *    nor may "OpenEJB" appear in their names without prior written
   *    permission of The OpenEJB Group. OpenEJB is a registered
   *    trademark of The OpenEJB Group.
   *
   * 5. Due credit should be given to the OpenEJB Project
   *    (http://openejb.org/).
   *
   * THIS SOFTWARE IS PROVIDED BY THE OPENEJB GROUP AND CONTRIBUTORS
   * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
   * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
   * THE OPENEJB GROUP OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
   * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
   * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
   * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
   * OF THE POSSIBILITY OF SUCH DAMAGE.
   *
   * Copyright 2001 (C) The OpenEJB Group. All Rights Reserved.
   *
   * $Id: StandardServiceStackGBean.java,v 1.1 2004/12/19 06:17:15 dblevins Exp 
$
   */
  
  package org.openejb.server;
  
  import java.net.InetAddress;
  import javax.management.ObjectName;
  
  import org.apache.geronimo.gbean.GBeanData;
  import org.apache.geronimo.gbean.GBeanInfo;
  import org.apache.geronimo.gbean.GBeanInfoBuilder;
  import org.apache.geronimo.kernel.GBeanAlreadyExistsException;
  import org.apache.geronimo.kernel.GBeanNotFoundException;
  import org.apache.geronimo.kernel.Kernel;
  import org.apache.geronimo.kernel.jmx.JMXUtil;
  
  public class StandardServiceStackGBean {
  
      public static final GBeanInfo GBEAN_INFO;
  
      static {
          GBeanInfoBuilder infoFactory = new 
GBeanInfoBuilder(StandardServiceStack.class);
  
          infoFactory.addAttribute("name", String.class, true);
          infoFactory.addAttribute("port", int.class, true);
          infoFactory.addAttribute("soTimeout", int.class, true);
          infoFactory.addAttribute("address", InetAddress.class, true);
          infoFactory.addAttribute("allowHosts", InetAddress[].class, true);
          infoFactory.addAttribute("threads", int.class, true);
          infoFactory.addAttribute("priority", int.class, true);
          infoFactory.addAttribute("logOnSuccess", String[].class, true);
          infoFactory.addAttribute("logOnFailure", String[].class, true);
          infoFactory.addReference("Server", ServerService.class);
  
          infoFactory.setConstructor(new String[]{
              "name",
              "port",
              "address",
              "allowHosts",
              "threads",
              "priority",
              "logOnSuccess",
              "logOnFailure",
              "Server"});
  
          GBEAN_INFO = infoFactory.getBeanInfo();
      }
  
      public static GBeanInfo getGBeanInfo() {
          return GBEAN_INFO;
      }
  
      public static ObjectName addGBean(Kernel kernel, String name, int port, 
InetAddress address, InetAddress[] allowHosts, int threads, int priority, 
String[] logOnSuccess, String[] logOnFailure, ObjectName server) throws 
GBeanAlreadyExistsException, GBeanNotFoundException {
          ClassLoader classLoader = StandardServiceStack.class.getClassLoader();
          ObjectName SERVICE_NAME = 
JMXUtil.getObjectName("openejb:type=StandardServiceStack,name=" + name);
  
          GBeanData gbean = new GBeanData(SERVICE_NAME, 
StandardServiceStackGBean.GBEAN_INFO);
          gbean.setAttribute("name", name);
          gbean.setAttribute("port", new Integer(port));
          gbean.setAttribute("address", address);
          gbean.setAttribute("allowHosts", allowHosts);
          gbean.setAttribute("threads", new Integer(threads));
          gbean.setAttribute("priority", new Integer(priority));
          gbean.setAttribute("logOnSuccess", logOnSuccess);
          gbean.setAttribute("logOnFailure", logOnFailure);
          gbean.setReferencePattern("Server", server);
  
          kernel.loadGBean(gbean, classLoader);
          kernel.startGBean(SERVICE_NAME);
          return SERVICE_NAME;
      }
  }
  
  
  

Reply via email to