james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ber...@apache.org
Subject svn commit: r419500 - in /james/server/trunk/src/java/org/apache/james: core/AbstractJamesService.java core/AvalonMailStore.java core/LocalUsersRepository.java fetchmail/FetchMail.java fetchmail/FetchScheduler.java
Date Thu, 06 Jul 2006 09:29:13 GMT
Author: berndf
Date: Thu Jul  6 02:29:12 2006
New Revision: 419500

URL: http://svn.apache.org/viewvc?rev=419500&view=rev
Log:
- add setters for service components (JAMES-494) (ongoing)
- fix javadoc
- remove unreachable code: instanceof type operand equals variable type
- try to separate initialisation into avalon related and non-avalon related

Modified:
    james/server/trunk/src/java/org/apache/james/core/AbstractJamesService.java
    james/server/trunk/src/java/org/apache/james/core/AvalonMailStore.java
    james/server/trunk/src/java/org/apache/james/core/LocalUsersRepository.java
    james/server/trunk/src/java/org/apache/james/fetchmail/FetchMail.java
    james/server/trunk/src/java/org/apache/james/fetchmail/FetchScheduler.java

Modified: james/server/trunk/src/java/org/apache/james/core/AbstractJamesService.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/core/AbstractJamesService.java?rev=419500&r1=419499&r2=419500&view=diff
==============================================================================
--- james/server/trunk/src/java/org/apache/james/core/AbstractJamesService.java (original)
+++ james/server/trunk/src/java/org/apache/james/core/AbstractJamesService.java Thu Jul  6
02:29:12 2006
@@ -149,7 +149,7 @@
     /**
      * The component manager used by this service.
      */
-    private ServiceManager compMgr;
+    private ServiceManager componentManager;
 
     /**
      * Whether this service is enabled.
@@ -177,14 +177,19 @@
      */
     protected WatchdogFactory theWatchdogFactory = null;
 
+    public void setConnectionManager(JamesConnectionManager connectionManager) {
+        this.connectionManager = connectionManager;
+    }
+
     /**
      * @see org.apache.avalon.framework.service.Serviceable#service(ServiceManager)
      */
     public void service(ServiceManager comp) throws ServiceException {
         super.service( comp );
-        compMgr               = comp;
-        connectionManager =
-            (JamesConnectionManager)compMgr.lookup(JamesConnectionManager.ROLE);
+        componentManager = comp;
+        JamesConnectionManager connectionManager =
+            (JamesConnectionManager)componentManager.lookup(JamesConnectionManager.ROLE);
+        setConnectionManager(connectionManager);
     }
 
     /**
@@ -259,6 +264,50 @@
             throw new ConfigurationException( "Malformed bind parameter in configuration
of service " + getServiceType(), unhe );
         }
 
+        configureHelloName(handlerConfiguration);
+
+        timeout = handlerConfiguration.getChild(TIMEOUT_NAME).getValueAsInteger(DEFAULT_TIMEOUT);
+
+        infoBuffer =
+            new StringBuffer(64)
+                    .append(getServiceType())
+                    .append(" handler connection timeout is: ")
+                    .append(timeout);
+        getLogger().info(infoBuffer.toString());
+
+        backlog = conf.getChild(BACKLOG_NAME).getValueAsInteger(DEFAULT_BACKLOG);
+
+        infoBuffer =
+                    new StringBuffer(64)
+                    .append(getServiceType())
+                    .append(" connection backlog is: ")
+                    .append(backlog);
+        getLogger().info(infoBuffer.toString());
+
+        String connectionLimitString = conf.getChild("connectionLimit").getValue(null);
+        if (connectionLimitString != null) {
+            try {
+                connectionLimit = new Integer(connectionLimitString);
+            } catch (NumberFormatException nfe) {
+                getLogger().error("Connection limit value is not properly formatted.", nfe);
+            }
+            if (connectionLimit.intValue() < 0) {
+                getLogger().error("Connection limit value cannot be less than zero.");
+                throw new ConfigurationException("Connection limit value cannot be less than
zero.");
+            }
+        } else {
+            connectionLimit = new Integer(connectionManager.getMaximumNumberOfOpenConnections());
+        }
+        infoBuffer = new StringBuffer(128)
+            .append(getServiceType())
+            .append(" will allow a maximum of ")
+            .append(connectionLimit.intValue())
+            .append(" connections.");
+        getLogger().info(infoBuffer.toString());
+    }
+
+    private void configureHelloName(Configuration handlerConfiguration) {
+        StringBuffer infoBuffer;
         String hostName = null;
         try {
             hostName = InetAddress.getLocalHost().getHostName();
@@ -286,47 +335,6 @@
                     .append(" handler hello name is: ")
                     .append(helloName);
         getLogger().info(infoBuffer.toString());
-
-        timeout = handlerConfiguration.getChild(TIMEOUT_NAME).getValueAsInteger(DEFAULT_TIMEOUT);
-
-        infoBuffer =
-            new StringBuffer(64)
-                    .append(getServiceType())
-                    .append(" handler connection timeout is: ")
-                    .append(timeout);
-        getLogger().info(infoBuffer.toString());
-
-        backlog = conf.getChild(BACKLOG_NAME).getValueAsInteger(DEFAULT_BACKLOG);
-
-        infoBuffer =
-                    new StringBuffer(64)
-                    .append(getServiceType())
-                    .append(" connection backlog is: ")
-                    .append(backlog);
-        getLogger().info(infoBuffer.toString());
-
-        if (connectionManager instanceof JamesConnectionManager) {
-            String connectionLimitString = conf.getChild("connectionLimit").getValue(null);
-            if (connectionLimitString != null) {
-                try {
-                    connectionLimit = new Integer(connectionLimitString);
-                } catch (NumberFormatException nfe) {
-                    getLogger().error("Connection limit value is not properly formatted.",
nfe);
-                }
-                if (connectionLimit.intValue() < 0) {
-                    getLogger().error("Connection limit value cannot be less than zero.");
-                    throw new ConfigurationException("Connection limit value cannot be less
than zero.");
-                }
-            } else {
-                connectionLimit = new Integer(((JamesConnectionManager)connectionManager).getMaximumNumberOfOpenConnections());
-            }
-            infoBuffer = new StringBuffer(128)
-                .append(getServiceType())
-                .append(" will allow a maximum of ")
-                .append(connectionLimit.intValue())
-                .append(" connections.");
-            getLogger().info(infoBuffer.toString());
-        }
     }
 
     /**
@@ -340,25 +348,44 @@
         }
         getLogger().debug(getServiceType() + " init...");
 
-        SocketManager socketManager = (SocketManager) compMgr.lookup(SocketManager.ROLE);
+        // keeping these looked up services locally, because they are only needed beyond
initialization
+        ThreadManager threadManager = (ThreadManager) componentManager.lookup(ThreadManager.ROLE);
+        SocketManager socketManager = (SocketManager) componentManager.lookup(SocketManager.ROLE);
+        
+        initializeThreadPool(threadManager);
+
+        initializeServerSocket(socketManager);
+
+        getLogger().debug(getServiceType() + " ...init end");
+
+        initializeHandlerPool();
+        
+        // do avalon specific preparations
+        ContainerUtil.enableLogging(theHandlerPool, getLogger());
+        ContainerUtil.initialize(theHandlerPool);
+
+        theWatchdogFactory = getWatchdogFactory();
 
-        ThreadManager threadManager = (ThreadManager) compMgr.lookup(ThreadManager.ROLE);
+    }
 
+    private void initializeThreadPool(ThreadManager threadManager) {
         if (threadGroup != null) {
             threadPool = threadManager.getThreadPool(threadGroup);
         } else {
             threadPool = threadManager.getDefaultThreadPool();
         }
+    }
 
+    private void initializeServerSocket(SocketManager socketManager) throws Exception {
         ServerSocketFactory factory = socketManager.getServerSocketFactory(serverSocketType);
         ServerSocket serverSocket = factory.createServerSocket(port, backlog, bindTo);
-    
+
         if (null == connectionName) {
             final StringBuffer sb = new StringBuffer();
             sb.append(serverSocketType);
             sb.append(':');
             sb.append(port);
-    
+
             if (null != bindTo) {
                 sb.append('/');
                 sb.append(bindTo);
@@ -366,30 +393,27 @@
             connectionName = sb.toString();
         }
 
-        if ((connectionLimit != null) &&
-            (connectionManager instanceof JamesConnectionManager)) {
+        if ((connectionLimit != null)) {
             if (null != threadPool) {
-                ((JamesConnectionManager)connectionManager).connect(connectionName, serverSocket,
this, threadPool, connectionLimit.intValue());
-            }
-            else {
-                ((JamesConnectionManager)connectionManager).connect(connectionName, serverSocket,
this, connectionLimit.intValue()); // default pool
+                connectionManager.connect(connectionName, serverSocket, this, threadPool,
connectionLimit.intValue());
+            } else {
+                connectionManager.connect(connectionName, serverSocket, this, connectionLimit.intValue());
// default pool
             }
         } else {
             if (null != threadPool) {
                 connectionManager.connect(connectionName, serverSocket, this, threadPool);
-            }
-            else {
+            } else {
                 connectionManager.connect(connectionName, serverSocket, this); // default
pool
             }
         }
+    }
 
-        getLogger().debug(getServiceType() + " ...init end");
-
+    private void initializeHandlerPool() throws Exception {
         StringBuffer logBuffer =
-            new StringBuffer(64)
-                .append(getServiceType())
-                .append(" started ")
-                .append(connectionName);
+                new StringBuffer(64)
+                        .append(getServiceType())
+                        .append(" started ")
+                        .append(connectionName);
         String logString = logBuffer.toString();
         System.out.println(logString);
         getLogger().info(logString);
@@ -405,11 +429,6 @@
             theHandlerPool = new DefaultPool(theHandlerFactory, null, 5, 30);
             getLogger().debug("Using an unbounded pool for "+getServiceType()+" handlers.");
         }
-        ContainerUtil.enableLogging(theHandlerPool, getLogger());
-        ContainerUtil.initialize(theHandlerPool);
-
-        theWatchdogFactory = getWatchdogFactory();
-
     }
 
     /**
@@ -455,7 +474,7 @@
             getLogger().warn(warnBuffer.toString(), e);
         }
 
-        compMgr = null;
+        componentManager = null;
 
         connectionManager = null;
         threadPool = null;
@@ -463,7 +482,7 @@
         // This is needed to make sure sockets are promptly closed on Windows 2000
         // TODO: Check this - shouldn't need to explicitly gc to force socket closure
         System.gc();
-    
+
         getLogger().debug(getServiceType() + " ...dispose end");
     }
 

Modified: james/server/trunk/src/java/org/apache/james/core/AvalonMailStore.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/core/AvalonMailStore.java?rev=419500&r1=419499&r2=419500&view=diff
==============================================================================
--- james/server/trunk/src/java/org/apache/james/core/AvalonMailStore.java (original)
+++ james/server/trunk/src/java/org/apache/james/core/AvalonMailStore.java Thu Jul  6 02:29:12
2006
@@ -87,7 +87,7 @@
     }
 
     /**
-     * @see org.apache.avalon.framework.service.Servicable#service(ServiceManager)
+     * @see org.apache.avalon.framework.service.Serviceable#service(ServiceManager)
      */
     public void service( final ServiceManager manager )
         throws ServiceException

Modified: james/server/trunk/src/java/org/apache/james/core/LocalUsersRepository.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/core/LocalUsersRepository.java?rev=419500&r1=419499&r2=419500&view=diff
==============================================================================
--- james/server/trunk/src/java/org/apache/james/core/LocalUsersRepository.java (original)
+++ james/server/trunk/src/java/org/apache/james/core/LocalUsersRepository.java Thu Jul  6
02:29:12 2006
@@ -32,9 +32,14 @@
     private UsersStore usersStore;
     private UsersRepository users;
 
+    public void setUsersStore(UsersStore usersStore) {
+        this.usersStore = usersStore;
+    }
+
     public void service(ServiceManager serviceManager) throws ServiceException {
-        usersStore =
+        UsersStore usersStore =
            (UsersStore) serviceManager.lookup(UsersStore.ROLE);
+        setUsersStore(usersStore);
     }
 
     public void initialize() throws Exception {

Modified: james/server/trunk/src/java/org/apache/james/fetchmail/FetchMail.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/fetchmail/FetchMail.java?rev=419500&r1=419499&r2=419500&view=diff
==============================================================================
--- james/server/trunk/src/java/org/apache/james/fetchmail/FetchMail.java (original)
+++ james/server/trunk/src/java/org/apache/james/fetchmail/FetchMail.java Thu Jul  6 02:29:12
2006
@@ -651,50 +651,50 @@
         fieldConfiguration = configuration;
     }
 
-/**
- * Sets the server.
- * @param server The server to set
- */
-protected void setServer(MailServer server)
-{
-    fieldServer = server;
-}
-
-/**
- * Returns the localUsers.
- * @return UsersRepository
- */
-protected UsersRepository getLocalUsers()
-{
-    return fieldLocalUsers;
-}
-
-/**
- * Sets the localUsers.
- * @param localUsers The localUsers to set
- */
-protected void setLocalUsers(UsersRepository localUsers)
-{
-    fieldLocalUsers = localUsers;
-}
-
-/**
- * Returns the DNSServer.
- * @return DNSServer 
- */
-protected DNSServer getDNSServer()
-{
-    return dnsServer;
-}
-
-/**
- * Sets the DNSServer.
- * @param dnsServer The DNSServer to set
- */
-protected void setDNSServer(DNSServer dnsServer)
-{
-    this.dnsServer = dnsServer;
-}
+    /**
+     * Sets the server.
+     * @param server The server to set
+     */
+    protected void setServer(MailServer server)
+    {
+        fieldServer = server;
+    }
+    
+    /**
+     * Returns the localUsers.
+     * @return UsersRepository
+     */
+    protected UsersRepository getLocalUsers()
+    {
+        return fieldLocalUsers;
+    }
+    
+    /**
+     * Sets the localUsers.
+     * @param localUsers The localUsers to set
+     */
+    protected void setLocalUsers(UsersRepository localUsers)
+    {
+        fieldLocalUsers = localUsers;
+    }
+    
+    /**
+     * Returns the DNSServer.
+     * @return DNSServer 
+     */
+    protected DNSServer getDNSServer()
+    {
+        return dnsServer;
+    }
+    
+    /**
+     * Sets the DNSServer.
+     * @param dnsServer The DNSServer to set
+     */
+    protected void setDNSServer(DNSServer dnsServer)
+    {
+        this.dnsServer = dnsServer;
+    }
 
 
     /**
@@ -916,7 +916,7 @@
 
     /**
      * Sets the ParsedDynamicAccountParameters.
-     * @param ParsedDynamicAccountParameters The ParsedDynamicAccountParametersto set
+     * @param parsedDynamicAccountParameters The ParsedDynamicAccountParameters to set
      */
     protected void setParsedDynamicAccountParameters(List parsedDynamicAccountParameters)
     {

Modified: james/server/trunk/src/java/org/apache/james/fetchmail/FetchScheduler.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/fetchmail/FetchScheduler.java?rev=419500&r1=419499&r2=419500&view=diff
==============================================================================
--- james/server/trunk/src/java/org/apache/james/fetchmail/FetchScheduler.java (original)
+++ james/server/trunk/src/java/org/apache/james/fetchmail/FetchScheduler.java Thu Jul  6
02:29:12 2006
@@ -67,6 +67,10 @@
 
     private ArrayList theFetchTaskNames = new ArrayList();
 
+    public void setScheduler(TimeScheduler scheduler) {
+        this.scheduler = scheduler;
+    }
+
     /**
      * @see org.apache.avalon.framework.service.Serviceable#service( ServiceManager )
      */
@@ -91,33 +95,37 @@
         enabled = conf.getAttributeAsBoolean("enabled", false);
         if (enabled)
         {
-            scheduler = (TimeScheduler) m_manager.lookup(TimeScheduler.ROLE);
+            TimeScheduler scheduler = (TimeScheduler) m_manager.lookup(TimeScheduler.ROLE);
+            setScheduler(scheduler);
+
             Configuration[] fetchConfs = conf.getChildren("fetch");
             for (int i = 0; i < fetchConfs.length; i++)
             {
-                FetchMail fetcher = new FetchMail();
+                // read configuration
                 Configuration fetchConf = fetchConfs[i];
                 String fetchTaskName = fetchConf.getAttribute("name");
+                Integer interval = new Integer(fetchConf.getChild("interval").getValue());
+
+                FetchMail fetcher = new FetchMail();
+                
+                // avalon specific initialization
                 ContainerUtil.enableLogging(fetcher,getLogger().getChildLogger(fetchTaskName));
                 ContainerUtil.service(fetcher,m_manager);
                 ContainerUtil.configure(fetcher,fetchConf);
-                Integer interval =
-                    new Integer(fetchConf.getChild("interval").getValue());
-                PeriodicTimeTrigger fetchTrigger =
-                    new PeriodicTimeTrigger(0, interval.intValue());
 
+                // initialize scheduling
+                PeriodicTimeTrigger fetchTrigger =
+                        new PeriodicTimeTrigger(0, interval.intValue());
                 scheduler.addTrigger(fetchTaskName, fetchTrigger, fetcher);
                 theFetchTaskNames.add(fetchTaskName);
             }
 
-            if (getLogger().isInfoEnabled())
-                getLogger().info("FetchMail Started");
+            if (getLogger().isInfoEnabled()) getLogger().info("FetchMail Started");
             System.out.println("FetchMail Started");
         }
         else
         {
-            if (getLogger().isInfoEnabled())
-                getLogger().info("FetchMail Disabled");
+            if (getLogger().isInfoEnabled()) getLogger().info("FetchMail Disabled");
             System.out.println("FetchMail Disabled");
         }
     }



---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


Mime
View raw message