Excellent, Gianny!

That's been on my todo list for quite some time.  If you want another little 
chunk to do, you can rework the ServiceAccessController to make it implement 
actual bit masking of IP addresses rather than a straight equals.

-David

On Fri, Mar 25, 2005 at 11:23:39AM -0000, [EMAIL PROTECTED] wrote:
> gdamour     2005/03/25 06:23:39
> 
>   Modified:    modules/core/src/java/org/openejb/server ServicePool.java
>                         SimpleSocketService.java StandardServiceStack.java
>                         StandardServiceStackGBean.java
>   Log:
> 
>   ServicePool uses now a Thread pool under the cover. This pool is either
>   created or provided.
>   
>   Use the default Geronimo Thread pool under the cover of 
> StandardServiceStack.
>   
>   Revision  Changes    Path
>   1.6       +58 -30    
> 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.5
>   retrieving revision 1.6
>   diff -u -r1.5 -r1.6
>   --- ServicePool.java        19 Dec 2004 06:17:15 -0000      1.5
>   +++ ServicePool.java        25 Mar 2005 11:23:38 -0000      1.6
>   @@ -44,12 +44,17 @@
>     */
>    package org.openejb.server;
>    
>   -import java.io.*;
>   -import java.net.*;
>   -import java.util.*;
>   -import org.openejb.*;
>   -import org.apache.commons.logging.LogFactory;
>   +import java.io.IOException;
>   +import java.net.Socket;
>   +import java.util.Properties;
>   +
>    import org.apache.commons.logging.Log;
>   +import org.apache.commons.logging.LogFactory;
>   +
>   +import EDU.oswego.cs.dl.util.concurrent.Executor;
>   +import EDU.oswego.cs.dl.util.concurrent.LinkedQueue;
>   +import EDU.oswego.cs.dl.util.concurrent.PooledExecutor;
>   +import EDU.oswego.cs.dl.util.concurrent.ThreadFactory;
>    
>    /**
>     *  The Server will call the following methods.
>   @@ -64,52 +69,75 @@
>     * 
>     */
>    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;
>   +    private final Executor executor;
>    
>   -    public ServicePool(String name, ServerService next, int threads, int 
> priority){
>   +    public ServicePool(ServerService next, final String name, final int 
> threads, final long keepAliveTime){
>            this.next = next;
>   -        this.threads = threads;
>   -        this.priority = priority;
>   +
>   +        PooledExecutor p = new PooledExecutor(new LinkedQueue(), threads);
>   +        p.setKeepAliveTime(keepAliveTime);
>   +        p.setMinimumPoolSize(threads);
>   +        p.setThreadFactory(new ThreadFactory() {
>   +            private volatile int id = 0;
>   +            public Thread newThread(Runnable arg0) {
>   +                Thread thread = new Thread(arg0, name + " " + getNextID());
>   +                return thread;
>   +            }
>   +            private int getNextID() {
>   +                return id++;
>   +            }
>   +
>   +        });
>   +        executor = p;
>        }
>    
>   +    public ServicePool(ServerService next, Executor executor){
>   +        this.next = next;
>   +        this.executor = executor;
>   +    }
>    
>        public void service(final Socket socket) throws ServiceException, 
> IOException{
>   -        // This isn't a pool now, but will be someday
>   -        Thread d = new Thread(new Runnable() {
>   +        final Runnable service = new Runnable() {
>                public void run() {
>                    try {
>                        next.service(socket);
>                    } catch (SecurityException e) {
>   -                    log.error( "Security error: "+ e.getMessage() );
>   +                    log.error( "Security error: "+ e.getMessage(), e);
>                    } catch (Throwable e) {
>   -                    log.error( "Unexpected error", e );
>   -
>   +                    log.error( "Unexpected error", e);
>                    } finally {
>                        try {
>   -                        if (socket != null)
>   +                        if (socket != null) {
>                                socket.close();
>   +                        }
>                        } catch (Throwable t) {
>   -                        //logger.error("Encountered problem while closing
>   -                        // connection with client: "+t.getMessage());
>   +                        log.warn("Error while closing connection with 
> client", t);
>                        }
>                    }
>                }
>   -        });
>   -        d.setDaemon(true);
>   -        d.start();
>   -    }
>   -
>   -    public int getThreads() {
>   -        return threads;
>   -    }
>   +        };
>    
>   -    public int getPriority() {
>   -        return priority;
>   +        final ClassLoader tccl = 
> Thread.currentThread().getContextClassLoader();
>   +        Runnable ctxCL = new Runnable() {
>   +            public void run() {
>   +                ClassLoader cl = 
> Thread.currentThread().getContextClassLoader();
>   +                Thread.currentThread().setContextClassLoader(tccl);
>   +                try {
>   +                    service.run();
>   +                } finally {
>   +                    Thread.currentThread().setContextClassLoader(cl);
>   +                }
>   +            }
>   +        };
>   +        
>   +        try {
>   +            executor.execute(ctxCL);
>   +        } catch (InterruptedException e) {
>   +            log.error("Error while executing service", e);
>   +        }
>        }
>    
>        /**
>   
>   
>   
>   1.14      +2 -2      
> openejb/modules/core/src/java/org/openejb/server/SimpleSocketService.java
>   
>   Index: SimpleSocketService.java
>   ===================================================================
>   RCS file: 
> /home/projects/openejb/scm/openejb/modules/core/src/java/org/openejb/server/SimpleSocketService.java,v
>   retrieving revision 1.13
>   retrieving revision 1.14
>   diff -u -r1.13 -r1.14
>   --- SimpleSocketService.java        6 Mar 2005 02:49:39 -0000       1.13
>   +++ SimpleSocketService.java        25 Mar 2005 11:23:39 -0000      1.14
>   @@ -89,7 +89,7 @@
>            String[] logOnSuccess = new 
> String[]{"HOST","NAME","THREADID","USERID"};
>            String[] logOnFailure = new String[]{"HOST","NAME"};
>    
>   -        service = new ServicePool(name, service, threads, priority);
>   +        service = new ServicePool(service, name, threads, priority);
>            service = new ServiceAccessController(name, service, onlyFrom);
>            service = new ServiceLogger(name, service, logOnSuccess, 
> logOnFailure);
>            server = service;
>   
>   
>   
>   1.4       +5 -11     
> 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.3
>   retrieving revision 1.4
>   diff -u -r1.3 -r1.4
>   --- StandardServiceStack.java       3 Feb 2005 03:09:53 -0000       1.3
>   +++ StandardServiceStack.java       25 Mar 2005 11:23:39 -0000      1.4
>   @@ -50,6 +50,8 @@
>    
>    import org.apache.geronimo.gbean.GBeanLifecycle;
>    
>   +import EDU.oswego.cs.dl.util.concurrent.Executor;
>   +
>    public class StandardServiceStack implements GBeanLifecycle {
>    
>        private String name;
>   @@ -60,10 +62,10 @@
>        private ServicePool pool;
>        private ServerService server;
>    
>   -    public StandardServiceStack(String name, int port, InetAddress 
> address, InetAddress[] allowHosts, int threads, int priority, String[] 
> logOnSuccess, String[] logOnFailure, ServerService server) {
>   +    public StandardServiceStack(String name, int port, InetAddress 
> address, InetAddress[] allowHosts, String[] logOnSuccess, String[] 
> logOnFailure, Executor executor, ServerService server) {
>            this.server = server;
>            this.name = name;
>   -        this.pool = new ServicePool(name, server, threads, priority);
>   +        this.pool = new ServicePool(server, executor);
>            this.hba = new ServiceAccessController(name, pool, allowHosts);
>            this.logger = new ServiceLogger(name, hba, logOnSuccess, 
> logOnFailure);
>            this.daemon = new ServiceDaemon(name, logger, address, port);
>   @@ -104,14 +106,6 @@
>    
>        public void setAllowHosts(InetAddress[] allowHosts) {
>            hba.setAllowHosts(allowHosts);
>   -    }
>   -
>   -    public int getThreads() {
>   -        return pool.getThreads();
>   -    }
>   -
>   -    public int getPriority() {
>   -        return pool.getPriority();
>        }
>    
>        public void doStart() throws Exception {
>   
>   
>   
>   1.3       +10 -8     
> openejb/modules/core/src/java/org/openejb/server/StandardServiceStackGBean.java
>   
>   Index: StandardServiceStackGBean.java
>   ===================================================================
>   RCS file: 
> /home/projects/openejb/scm/openejb/modules/core/src/java/org/openejb/server/StandardServiceStackGBean.java,v
>   retrieving revision 1.2
>   retrieving revision 1.3
>   diff -u -r1.2 -r1.3
>   --- StandardServiceStackGBean.java  6 Mar 2005 02:49:39 -0000       1.2
>   +++ StandardServiceStackGBean.java  25 Mar 2005 11:23:39 -0000      1.3
>   @@ -57,6 +57,8 @@
>    import org.apache.geronimo.kernel.jmx.JMXUtil;
>    import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
>    
>   +import EDU.oswego.cs.dl.util.concurrent.Executor;
>   +
>    public class StandardServiceStackGBean {
>    
>        public static final GBeanInfo GBEAN_INFO;
>   @@ -69,10 +71,10 @@
>            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("Executor", Executor.class, 
> NameFactory.GERONIMO_SERVICE);
>            infoFactory.addReference("Server", ServerService.class, 
> NameFactory.GERONIMO_SERVICE);
>    
>            infoFactory.setConstructor(new String[]{
>   @@ -80,10 +82,9 @@
>                "port",
>                "address",
>                "allowHosts",
>   -            "threads",
>   -            "priority",
>                "logOnSuccess",
>                "logOnFailure",
>   +            "Executor",
>                "Server"});
>    
>            GBEAN_INFO = infoFactory.getBeanInfo();
>   @@ -93,19 +94,20 @@
>            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 {
>   +    public static ObjectName addGBean(Kernel kernel, String name, int 
> port, InetAddress address, InetAddress[] allowHosts, String[] logOnSuccess, 
> String[] logOnFailure, ObjectName executor, 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("Executor", executor);
>            gbean.setReferencePattern("Server", server);
>    
>            kernel.loadGBean(gbean, classLoader);
>   
>   
>   

Reply via email to