geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From djen...@apache.org
Subject cvs commit: incubator-geronimo/modules/core/src/java/org/apache/geronimo/core/logging/log4j Log4jService.java Log4jSocketServer.java
Date Thu, 22 Jan 2004 04:24:57 GMT
djencks     2004/01/21 20:24:57

  Modified:    modules/core/src/java/org/apache/geronimo/core/logging
                        AbstractLoggingService.java
               modules/core/src/java/org/apache/geronimo/core/logging/log4j
                        Log4jService.java Log4jSocketServer.java
  Added:       modules/core/src/test/org/apache/geronimo/core/logging/log4j
                        Log4jServiceTest.java
  Log:
  Gbeanized and added simple deployability test
  
  Revision  Changes    Path
  1.1                  incubator-geronimo/modules/core/src/test/org/apache/geronimo/core/logging/log4j/Log4jServiceTest.java
  
  Index: Log4jServiceTest.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 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 end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Geronimo" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Geronimo", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``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 APACHE SOFTWARE FOUNDATION 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.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * ====================================================================
   */
  
  package org.apache.geronimo.core.logging.log4j;
  
  import java.io.File;
  import java.net.InetAddress;
  
  import javax.management.ObjectName;
  
  import junit.framework.TestCase;
  import org.apache.geronimo.gbean.jmx.GBeanMBean;
  import org.apache.geronimo.kernel.Kernel;
  
  /**
   *
   *
   * @version $Revision: 1.1 $ $Date: 2004/01/22 04:24:57 $
   *
   * */
  public class Log4jServiceTest extends TestCase {
  
      private ObjectName log4jServiceName;
      private GBeanMBean log4jService;
      private ObjectName log4jSocketServerName;
      private GBeanMBean log4jSocketServer;
      private Kernel kernel;
  
      protected void setUp() throws Exception {
          log4jServiceName = new ObjectName("test:name=Log4jService");
          log4jService = new GBeanMBean(Log4jService.getGBeanInfo());
          log4jService.setAttribute("ConfigurationURL", new File(new File("."), "src/test-data/xml/log4j-config.xml").toURL());
          log4jService.setAttribute("RefreshPeriod", new Integer(10));
          log4jSocketServerName = new ObjectName("test:name=Log4jSocketServer");
          log4jSocketServer = new GBeanMBean(Log4jSocketServer.getGBeanInfo());
          log4jSocketServer.setAttribute("BindAddress", InetAddress.getLocalHost());
          log4jSocketServer.setAttribute("Port", new Integer(8090));
          log4jSocketServer.setAttribute("Backlog", new Integer(50));
          log4jSocketServer.setAttribute("ListenerEnabled", Boolean.TRUE);
          log4jSocketServer.setAttribute("LoggerRepositoryFactoryType", Log4jSocketServer.DefaultLoggerRepositoryFactory.class);
          kernel = new Kernel("test");
          kernel.boot();
      }
  
      protected void tearDown() throws Exception {
          kernel.shutdown();
       }
  
      public void testLog4jService() throws Exception {
          kernel.loadGBean(log4jServiceName, log4jService);
          kernel.startGBean(log4jServiceName);
          kernel.stopGBean(log4jServiceName);
          kernel.unloadGBean(log4jServiceName);
      }
  
     public void testLog4jSocketServer() throws Exception {
          kernel.loadGBean(log4jSocketServerName, log4jSocketServer);
          kernel.startGBean(log4jSocketServerName);
          kernel.stopGBean(log4jSocketServerName);
          kernel.unloadGBean(log4jSocketServerName);
      }
  }
  
  
  
  1.5       +34 -45    incubator-geronimo/modules/core/src/java/org/apache/geronimo/core/logging/AbstractLoggingService.java
  
  Index: AbstractLoggingService.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/core/src/java/org/apache/geronimo/core/logging/AbstractLoggingService.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- AbstractLoggingService.java	30 Dec 2003 21:17:14 -0000	1.4
  +++ AbstractLoggingService.java	22 Jan 2004 04:24:57 -0000	1.5
  @@ -61,12 +61,13 @@
   
   import org.apache.geronimo.common.NullArgumentException;
   import org.apache.geronimo.common.task.URLMonitorTask;
  -import org.apache.geronimo.kernel.service.GeronimoMBeanTarget;
  -import org.apache.geronimo.kernel.service.GeronimoMBeanContext;
  -import org.apache.geronimo.kernel.service.GeronimoMBeanInfo;
  -import org.apache.geronimo.kernel.service.GeronimoAttributeInfo;
  -import org.apache.geronimo.kernel.service.GeronimoOperationInfo;
  -import org.apache.geronimo.kernel.service.GeronimoParameterInfo;
  +import org.apache.geronimo.gbean.GAttributeInfo;
  +import org.apache.geronimo.gbean.GBean;
  +import org.apache.geronimo.gbean.GBeanContext;
  +import org.apache.geronimo.gbean.GBeanInfo;
  +import org.apache.geronimo.gbean.GBeanInfoFactory;
  +import org.apache.geronimo.gbean.GConstructorInfo;
  +import org.apache.geronimo.gbean.GOperationInfo;
   
   /**
    * An abstract logging service.
  @@ -76,8 +77,10 @@
    * @version $Revision$ $Date$
    */
   public abstract class AbstractLoggingService
  -    implements LoggingService, GeronimoMBeanTarget
  -{
  +        implements LoggingService, GBean {
  +
  +    private static final GBeanInfo GBEAN_INFO;
  +
       /** The default refresh period (60 seconds) */
       public static final int DEFAULT_REFRESH_PERIOD = 60;
   
  @@ -99,8 +102,7 @@
        * @param url       The configuration URL.
        * @param period    The refresh period (in seconds).
        */
  -    protected AbstractLoggingService(final URL url, final int period)
  -    {
  +    protected AbstractLoggingService(final URL url, final int period) {
           setRefreshPeriod(period);
           setConfigurationURL(url);
       }
  @@ -111,18 +113,15 @@
        *
        * @param url   The configuration URL.
        */
  -    protected AbstractLoggingService(final URL url)
  -    {
  +    protected AbstractLoggingService(final URL url) {
           this(url, DEFAULT_REFRESH_PERIOD);
       }
   
  -    public int getRefreshPeriod()
  -    {
  +    public int getRefreshPeriod() {
           return refreshPeriod;
       }
   
  -    public void setRefreshPeriod(final int period)
  -    {
  +    public void setRefreshPeriod(final int period) {
           if (period < 1) {
               throw new IllegalArgumentException("Refresh period must be > 0");
           }
  @@ -130,13 +129,11 @@
           this.refreshPeriod = period;
       }
   
  -    public URL getConfigurationURL()
  -    {
  +    public URL getConfigurationURL() {
           return configURL;
       }
   
  -    public void setConfigurationURL(final URL url)
  -    {
  +    public void setConfigurationURL(final URL url) {
           if (url == null) {
               throw new NullArgumentException("url");
           }
  @@ -144,22 +141,15 @@
           this.configURL = url;
       }
   
  -    public void reconfigure()
  -    {
  +    public void reconfigure() {
           configure(configURL);
       }
   
   
  -    //GeronimoMBeanTarget
  -    public void setMBeanContext(GeronimoMBeanContext context) {
  -    }
  -
  -    public boolean canStart() {
  -        return true;
  +    public void setGBeanContext(GBeanContext context) {
       }
   
  -    public void doStart()
  -    {
  +    public void doStart() {
           monitor = new URLMonitorTask(configURL);
           monitor.addListener(new URLMonitorTask.Listener() {
               public void doURLChanged(final URLMonitorTask.Event event) {
  @@ -170,28 +160,27 @@
           timer.schedule(monitor, 1000 * refreshPeriod, 1000 * refreshPeriod);
       }
   
  -    public void doStop()
  -    {
  +    public void doStop() {
           monitor.cancel();
           monitor = null;
       }
   
  -    public boolean canStop() {
  -        return true;
  +    public void doFail() {
       }
   
  -    public void doFail() {
  +    static {
  +        GBeanInfoFactory infoFactory = new GBeanInfoFactory(AbstractLoggingService.class.getName());
  +        infoFactory.addAttribute(new GAttributeInfo("RefreshPeriod", true));
  +        infoFactory.addAttribute(new GAttributeInfo("ConfigurationURL", true));
  +        infoFactory.addOperation(new GOperationInfo("reconfigure"));
  +        infoFactory.setConstructor(new GConstructorInfo(
  +                new String[]{"ConfigurationURL", "RefreshPeriod"},
  +                new Class[]{URL.class, int.class}));
  +        GBEAN_INFO = infoFactory.getBeanInfo();
       }
   
  -    public static GeronimoMBeanInfo getGeronimoMBeanInfo() {
  -        GeronimoMBeanInfo mbeanInfo = new GeronimoMBeanInfo();
  -        //set class in caller
  -        mbeanInfo.addAttributeInfo(new GeronimoAttributeInfo("RefreshPeriod", true, true,
"Period in seconds at which configuration refreshes"));
  -        mbeanInfo.addAttributeInfo(new GeronimoAttributeInfo("ConfigurationURL", true,
true, "Location of the logging configuration"));
  -        mbeanInfo.addOperationInfo(new GeronimoOperationInfo("reconfigure", new GeronimoParameterInfo[]
{}, GeronimoOperationInfo.ACTION, "reconfigure now from previously set url"));
  -        mbeanInfo.addOperationInfo(new GeronimoOperationInfo("configure",
  -                new GeronimoParameterInfo[] {new GeronimoParameterInfo("url", URL.class,
"URL to read configuration from")}, GeronimoOperationInfo.ACTION, "configure now from supplied
url"));
  -        return mbeanInfo;
  +    public static GBeanInfo getGBeanInfo() {
  +        return GBEAN_INFO;
       }
   
   }
  
  
  
  1.5       +30 -41    incubator-geronimo/modules/core/src/java/org/apache/geronimo/core/logging/log4j/Log4jService.java
  
  Index: Log4jService.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/core/src/java/org/apache/geronimo/core/logging/log4j/Log4jService.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- Log4jService.java	30 Dec 2003 21:17:14 -0000	1.4
  +++ Log4jService.java	22 Jan 2004 04:24:57 -0000	1.5
  @@ -65,10 +65,10 @@
   import org.apache.geronimo.common.propertyeditor.PropertyEditors;
   import org.apache.geronimo.common.propertyeditor.TextPropertyEditorSupport;
   import org.apache.geronimo.core.logging.AbstractLoggingService;
  +import org.apache.geronimo.gbean.GBeanInfo;
  +import org.apache.geronimo.gbean.GBeanInfoFactory;
  +import org.apache.geronimo.gbean.GOperationInfo;
   import org.apache.geronimo.kernel.log.XLevel;
  -import org.apache.geronimo.kernel.service.GeronimoMBeanInfo;
  -import org.apache.geronimo.kernel.service.GeronimoOperationInfo;
  -import org.apache.geronimo.kernel.service.GeronimoParameterInfo;
   import org.apache.log4j.Level;
   import org.apache.log4j.Logger;
   
  @@ -78,9 +78,10 @@
    *
    * @version $Revision$ $Date$
    */
  -public class Log4jService
  -    extends AbstractLoggingService
  -{
  +public class Log4jService extends AbstractLoggingService {
  +
  +    private static final GBeanInfo GBEAN_INFO;
  +
       private static final Log log = LogFactory.getLog(Log4jService.class);
   
       /**
  @@ -90,8 +91,7 @@
        * @param period    The refresh period (in seconds).
        *
        */
  -    public Log4jService(final URL url, final int period)
  -    {
  +    public Log4jService(final URL url, final int period) {
           super(url, period);
       }
   
  @@ -101,8 +101,7 @@
        * @param url   The configuration URL.
        *
        */
  -    public Log4jService(final URL url)
  -    {
  +    public Log4jService(final URL url) {
           super(url);
       }
   
  @@ -111,8 +110,7 @@
        *
        * @param url   The URL to configure from.
        */
  -    public void configure(final URL url)
  -    {
  +    public void configure(final URL url) {
           if (url == null) {
               throw new NullArgumentException("url");
           }
  @@ -129,10 +127,8 @@
        * A property editor for Log4j Levels.
        */
       public static class LevelEditor
  -        extends TextPropertyEditorSupport
  -    {
  -        public Object getValue()
  -        {
  +        extends TextPropertyEditorSupport {
  +        public Object getValue() {
               return XLevel.toLevel(getAsText().trim());
           }
       }
  @@ -141,17 +137,14 @@
        * A property editor for Log4j Loggers.
        */
       public static class LoggerEditor
  -        extends TextPropertyEditorSupport
  -    {
  -        public Object getValue()
  -        {
  +        extends TextPropertyEditorSupport {
  +        public Object getValue() {
               return Logger.getLogger(getAsText().trim());
           }
       }
   
       /** Install property editors for Logger and Level. */
  -    static
  -    {
  +    static {
           PropertyEditors.registerEditor(Logger.class, LoggerEditor.class);
           PropertyEditors.registerEditor(Level.class, LevelEditor.class);
       }
  @@ -163,8 +156,7 @@
        * @param level     The level to change the logger to.
        *
        */
  -    public void setLoggerLevel(final Logger logger, final Level level)
  -    {
  +    public void setLoggerLevel(final Logger logger, final Level level) {
           if (logger == null) {
               throw new NullArgumentException("logger");
           }
  @@ -182,8 +174,7 @@
        * @param logger    The logger to inspect.
        *
        */
  -    public String getLoggerLevel(final Logger logger)
  -    {
  +    public String getLoggerLevel(final Logger logger) {
           if (logger == null) {
               throw new NullArgumentException("logger");
           }
  @@ -198,25 +189,23 @@
       }
   
   
  -    //GeronimoMBeanTarget
  -    public void doStart()
  -    {
  +    //GBean
  +    public void doStart() {
           super.doStart();
   
           // Make sure the root Logger has loaded
           Logger.getRootLogger();
       }
   
  -    public static GeronimoMBeanInfo getGeronimoMBeanInfo() {
  -        GeronimoMBeanInfo mbeanInfo = AbstractLoggingService.getGeronimoMBeanInfo();
  -        mbeanInfo.setTargetClass(Log4jService.class.getName());
  -        mbeanInfo.addOperationInfo(new GeronimoOperationInfo("setLoggerLevel", new GeronimoParameterInfo[]
{
  -            new GeronimoParameterInfo("logger", Logger.class, "Logger to configure"),
  -            new GeronimoParameterInfo("level", Level.class, "Level to set the Logger to")},
  -                GeronimoOperationInfo.ACTION, "Configure the logger to the level"));
  -        mbeanInfo.addOperationInfo(new GeronimoOperationInfo("getLoggerLevel", new GeronimoParameterInfo[]
{
  -            new GeronimoParameterInfo("logger", Logger.class, "Logger to configure")},
  -                GeronimoOperationInfo.INFO, "Get the level the logger is configured to"));
  -        return mbeanInfo;
  +    static {
  +        GBeanInfoFactory infoFactory = new GBeanInfoFactory(Log4jService.class.getName(),
AbstractLoggingService.getGBeanInfo());
  +        infoFactory.addOperation(new GOperationInfo("setLoggerLevel", new String[] {Logger.class.getName(),
Level.class.getName()}));
  +        infoFactory.addOperation(new GOperationInfo("getLoggerLevel", new String[] {Logger.class.getName()}));
  +        GBEAN_INFO = infoFactory.getBeanInfo();
       }
  +
  +    public static GBeanInfo getGBeanInfo() {
  +        return GBEAN_INFO;
  +    }
  +
   }
  
  
  
  1.4       +65 -96    incubator-geronimo/modules/core/src/java/org/apache/geronimo/core/logging/log4j/Log4jSocketServer.java
  
  Index: Log4jSocketServer.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/core/src/java/org/apache/geronimo/core/logging/log4j/Log4jSocketServer.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- Log4jSocketServer.java	30 Dec 2003 21:17:14 -0000	1.3
  +++ Log4jSocketServer.java	22 Jan 2004 04:24:57 -0000	1.4
  @@ -63,12 +63,13 @@
   
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
  -import org.apache.geronimo.kernel.service.GeronimoAttributeInfo;
  -import org.apache.geronimo.kernel.service.GeronimoMBeanContext;
  -import org.apache.geronimo.kernel.service.GeronimoMBeanInfo;
  -import org.apache.geronimo.kernel.service.GeronimoMBeanTarget;
  -import org.apache.geronimo.kernel.service.GeronimoOperationInfo;
  -import org.apache.geronimo.kernel.service.GeronimoParameterInfo;
  +import org.apache.geronimo.gbean.GAttributeInfo;
  +import org.apache.geronimo.gbean.GBean;
  +import org.apache.geronimo.gbean.GBeanContext;
  +import org.apache.geronimo.gbean.GBeanInfo;
  +import org.apache.geronimo.gbean.GBeanInfoFactory;
  +import org.apache.geronimo.gbean.GConstructorInfo;
  +import org.apache.geronimo.gbean.GOperationInfo;
   import org.apache.log4j.LogManager;
   import org.apache.log4j.net.SocketNode;
   import org.apache.log4j.spi.LoggerRepository;
  @@ -86,7 +87,10 @@
    *
    * @version $Revision$ $Date$
    */
  -public class Log4jSocketServer implements GeronimoMBeanTarget {
  +public class Log4jSocketServer implements GBean {
  +
  +    private static final GBeanInfo GBEAN_INFO;
  +
       /** The port number where the server listens. */
       protected int port = -1;
   
  @@ -108,64 +112,59 @@
       /** The factory to create LoggerRepository's for client connections. */
       protected LoggerRepositoryFactory loggerRepositoryFactory;
   
  +    public Log4jSocketServer(InetAddress bindAddr, int port, int backlog, boolean listenerEnabled,
Class loggerRepositoryFactoryType) throws InstantiationException, IllegalAccessException {
  +        this.bindAddress = bindAddr;
  +        this.port = port;
  +        this.backlog = backlog;
  +        this.listenerEnabled = listenerEnabled;
  +        setLoggerRepositoryFactoryType(loggerRepositoryFactoryType);
  +    }
   
  -    public void setPort(final int port)
  -    {
  +    public void setPort(final int port) {
           this.port = port;
       }
   
  -    public int getPort()
  -    {
  +    public int getPort() {
           return port;
       }
   
  -    public void setBacklog(final int backlog)
  -    {
  +    public void setBacklog(final int backlog) {
           this.backlog = backlog;
       }
   
  -    public int getBacklog()
  -    {
  +    public int getBacklog() {
           return backlog;
       }
   
  -    public void setBindAddress(final InetAddress addr)
  -    {
  +    public void setBindAddress(final InetAddress addr) {
           this.bindAddress = addr;
       }
   
  -    public InetAddress getBindAddress()
  -    {
  +    public InetAddress getBindAddress() {
           return bindAddress;
       }
   
  -    public void setListenerEnabled(final boolean enabled)
  -    {
  +    public void setListenerEnabled(final boolean enabled) {
           listenerEnabled = enabled;
       }
   
  -    public boolean getListenerEnabled()
  -    {
  +    public boolean getListenerEnabled() {
           return listenerEnabled;
       }
   
       public void setLoggerRepositoryFactoryType(final Class type)
  -        throws InstantiationException, IllegalAccessException, ClassCastException
  -    {
  -        this.loggerRepositoryFactory = (LoggerRepositoryFactory)type.newInstance();
  +            throws InstantiationException, IllegalAccessException, ClassCastException {
  +        this.loggerRepositoryFactory = type == null ? null : (LoggerRepositoryFactory)
type.newInstance();
       }
   
  -    public Class getLoggerRepositoryFactoryType()
  -    {
  +    public Class getLoggerRepositoryFactoryType() {
           if (loggerRepositoryFactory == null) {
               return null;
           }
  -
           return loggerRepositoryFactory.getClass();
       }
   
  -    public LoggerRepository getLoggerRepository(final InetAddress addr)
  -    {
  +    public LoggerRepository getLoggerRepository(final InetAddress addr) {
           return loggerRepositoryFactory.create(addr);
       }
   
  @@ -175,77 +174,63 @@
       ///////////////////////////////////////////////////////////////////////////
   
       protected class SocketListenerThread
  -        extends Thread
  -    {
  +            extends Thread {
           protected Log log = LogFactory.getLog(SocketListenerThread.class);
           protected boolean enabled;
           protected boolean shuttingDown;
           protected Object lock = new Object();
   
  -        public SocketListenerThread(final boolean enabled)
  -        {
  +        public SocketListenerThread(final boolean enabled) {
               super("SocketListenerThread");
  -
               this.enabled = enabled;
           }
   
  -        public void setEnabled(boolean enabled)
  -        {
  +        public void setEnabled(boolean enabled) {
               this.enabled = enabled;
  -
               synchronized (lock) {
                   lock.notifyAll();
               }
  -
               if (log.isDebugEnabled()) {
                   log.debug("Notified that enabled: " + enabled);
               }
           }
   
  -        public void shutdown()
  -        {
  +        public void shutdown() {
               enabled = false;
               shuttingDown = true;
   
               synchronized (lock) {
                   lock.notifyAll();
               }
  -
  -            if (log.isDebugEnabled()) {
  -                log.debug("Notified to shutdown");
  -            }
  +            log.debug("Notified to shutdown");
           }
   
  -        public void run()
  -        {
  +        public void run() {
               while (!shuttingDown) {
  -
                   if (!enabled) {
                       try {
                           log.debug("Disabled, waiting for notification");
                           synchronized (lock) {
                               lock.wait();
                           }
  +                    } catch (InterruptedException ignore) {
                       }
  -                    catch (InterruptedException ignore) {}
                   }
   
                   try {
                       doRun();
  -                }
  -                catch (Exception e) {
  +                } catch (Exception e) {
                       log.error("Exception caught from main loop; ignoring", e);
                   }
               }
           }
   
  -        protected void doRun() throws Exception
  -        {
  +        protected void doRun() throws Exception {
               while (enabled) {
                   boolean debug = log.isDebugEnabled();
   
                   Socket socket = serverSocket.accept();
  -                InetAddress addr =  socket.getInetAddress();
  +                InetAddress addr = socket.getInetAddress();
                   if (debug) {
                       log.debug("Connected to client: " + addr);
                   }
  @@ -273,8 +258,7 @@
       //                         LoggerRepositoryFactory                       //
       ///////////////////////////////////////////////////////////////////////////
   
  -    public static interface LoggerRepositoryFactory
  -    {
  +    public static interface LoggerRepositoryFactory {
           public LoggerRepository create(InetAddress addr);
       }
   
  @@ -283,12 +267,10 @@
        * the current repository from the LogManager.
        */
       public static class DefaultLoggerRepositoryFactory
  -        implements LoggerRepositoryFactory
  -    {
  +            implements LoggerRepositoryFactory {
           private LoggerRepository repo;
   
  -        public LoggerRepository create(final InetAddress addr)
  -        {
  +        public LoggerRepository create(final InetAddress addr) {
               if (repo == null) {
                   repo = LogManager.getLoggerRepository();
               }
  @@ -297,26 +279,14 @@
       }
   
   
  -    ///////////////////////////////////////////////////////////////////////////
  -    //                    AbstractManagedObject Overrides                    //
  -    ///////////////////////////////////////////////////////////////////////////
  -
  -    public void setMBeanContext(GeronimoMBeanContext context) {
  +    public void setGBeanContext(GBeanContext context) {
       }
   
  -    public boolean canStart() {
  -        return true;
  -    }
  -
  -    public void doStart()
  -    {
  +    public void doStart() {
           listenerThread = new SocketListenerThread(false);
           listenerThread.setDaemon(true);
           listenerThread.start();
  -        //log.debug("Socket listener thread started");
  -
           if (loggerRepositoryFactory == null) {
  -            //log.debug("Using default logger repository factory");
               loggerRepositoryFactory = new DefaultLoggerRepositoryFactory();
           }
   
  @@ -324,8 +294,7 @@
           try {
               if (bindAddress == null) {
                   serverSocket = new ServerSocket(port, backlog);
  -            }
  -            else {
  +            } else {
                   serverSocket = new ServerSocket(port, backlog, bindAddress);
               }
           } catch (IOException e) {
  @@ -336,12 +305,7 @@
           listenerThread.setEnabled(listenerEnabled);
       }
   
  -    public boolean canStop() {
  -        return true;
  -    }
  -
  -    public void doStop()
  -    {
  +    public void doStop() {
           listenerThread.shutdown();
           listenerThread = null;
           serverSocket = null;
  @@ -350,17 +314,22 @@
       public void doFail() {
       }
   
  -    public static GeronimoMBeanInfo getGeronimoMBeanInfo() {
  -        GeronimoMBeanInfo mbeanInfo = new GeronimoMBeanInfo();
  -        mbeanInfo.setTargetClass(Log4jSocketServer.class.getName());
  -        mbeanInfo.addAttributeInfo(new GeronimoAttributeInfo("Port", true, true, "Port
to listen on"));
  -        mbeanInfo.addAttributeInfo(new GeronimoAttributeInfo("Backlog", true, true, "Backlog"));
  -        mbeanInfo.addAttributeInfo(new GeronimoAttributeInfo("BindAddress", true, true,
"BindAddress to listen on"));
  -        mbeanInfo.addAttributeInfo(new GeronimoAttributeInfo("ListenerEnabled", true, true,
"whether Listener is enabled"));
  -        mbeanInfo.addAttributeInfo(new GeronimoAttributeInfo("LoggerRepositoryFactoryType",
true, true, "Class for constructing LoggerRepository instances"));
  -        mbeanInfo.addOperationInfo(new GeronimoOperationInfo("getLoggerRepository", new
GeronimoParameterInfo[] {
  -            new GeronimoParameterInfo("address", InetAddress.class, "address to get the
repository for")},
  -                GeronimoOperationInfo.INFO, "Get the logger repository for the supplied
address"));
  -        return mbeanInfo;
  +    static {
  +        GBeanInfoFactory infoFactory = new GBeanInfoFactory(Log4jSocketServer.class.getName());
  +        infoFactory.addAttribute(new GAttributeInfo("Port", true));
  +        infoFactory.addAttribute(new GAttributeInfo("Backlog", true));
  +        infoFactory.addAttribute(new GAttributeInfo("BindAddress", true));
  +        infoFactory.addAttribute(new GAttributeInfo("ListenerEnabled", true));
  +        infoFactory.addAttribute(new GAttributeInfo("LoggerRepositoryFactoryType", true));
  +        infoFactory.addOperation(new GOperationInfo("getLoggerRepository", new String[]{InetAddress.class.getName()}));
  +        infoFactory.setConstructor(new GConstructorInfo(
  +                new String[]{"BindAddress", "Port", "Backlog", "ListenerEnabled", "LoggerRepositoryFactoryType"},
  +                new Class[]{InetAddress.class, int.class, int.class, boolean.class, Class.class}));
  +        GBEAN_INFO = infoFactory.getBeanInfo();
       }
  +
  +    public static GBeanInfo getGBeanInfo() {
  +        return GBEAN_INFO;
  +    }
  +
   }
  
  
  

Mime
View raw message