You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by no...@apache.org on 2009/11/24 15:45:05 UTC

svn commit: r883705 - in /james/server/trunk: fetchmail-function/src/main/java/org/apache/james/fetchmail/ fetchmail-function/src/main/resources/org/apache/james/fetchmail/ phoenix-deployment/src/conf/

Author: norman
Date: Tue Nov 24 14:45:05 2009
New Revision: 883705

URL: http://svn.apache.org/viewvc?rev=883705&view=rev
Log:
More decoupling of Avalon to move to Guice (JAMES-893)

Added:
    james/server/trunk/fetchmail-function/src/main/java/org/apache/james/fetchmail/AvalonFetchScheduler.java
    james/server/trunk/fetchmail-function/src/main/resources/org/apache/james/fetchmail/AvalonFetchScheduler.xinfo
      - copied unchanged from r829946, james/server/trunk/fetchmail-function/src/main/resources/org/apache/james/fetchmail/FetchScheduler.xinfo
Removed:
    james/server/trunk/fetchmail-function/src/main/resources/org/apache/james/fetchmail/FetchScheduler.xinfo
Modified:
    james/server/trunk/fetchmail-function/src/main/java/org/apache/james/fetchmail/Account.java
    james/server/trunk/fetchmail-function/src/main/java/org/apache/james/fetchmail/DynamicAccount.java
    james/server/trunk/fetchmail-function/src/main/java/org/apache/james/fetchmail/FetchMail.java
    james/server/trunk/fetchmail-function/src/main/java/org/apache/james/fetchmail/FetchScheduler.java
    james/server/trunk/fetchmail-function/src/main/java/org/apache/james/fetchmail/ParsedConfiguration.java
    james/server/trunk/fetchmail-function/src/main/java/org/apache/james/fetchmail/ProcessorAbstract.java
    james/server/trunk/phoenix-deployment/src/conf/james-assembly.xml

Modified: james/server/trunk/fetchmail-function/src/main/java/org/apache/james/fetchmail/Account.java
URL: http://svn.apache.org/viewvc/james/server/trunk/fetchmail-function/src/main/java/org/apache/james/fetchmail/Account.java?rev=883705&r1=883704&r2=883705&view=diff
==============================================================================
--- james/server/trunk/fetchmail-function/src/main/java/org/apache/james/fetchmail/Account.java (original)
+++ james/server/trunk/fetchmail-function/src/main/java/org/apache/james/fetchmail/Account.java Tue Nov 24 14:45:05 2009
@@ -27,7 +27,7 @@
 import javax.mail.Session;
 import javax.mail.internet.ParseException;
 
-import org.apache.avalon.framework.configuration.ConfigurationException;
+import org.apache.commons.configuration.ConfigurationException;
 import org.apache.mailet.MailAddress;
 
 /**

Added: james/server/trunk/fetchmail-function/src/main/java/org/apache/james/fetchmail/AvalonFetchScheduler.java
URL: http://svn.apache.org/viewvc/james/server/trunk/fetchmail-function/src/main/java/org/apache/james/fetchmail/AvalonFetchScheduler.java?rev=883705&view=auto
==============================================================================
--- james/server/trunk/fetchmail-function/src/main/java/org/apache/james/fetchmail/AvalonFetchScheduler.java (added)
+++ james/server/trunk/fetchmail-function/src/main/java/org/apache/james/fetchmail/AvalonFetchScheduler.java Tue Nov 24 14:45:05 2009
@@ -0,0 +1,102 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+
+package org.apache.james.fetchmail;
+
+import org.apache.avalon.cornerstone.services.scheduler.TimeScheduler;
+import org.apache.avalon.framework.activity.Initializable;
+import org.apache.avalon.framework.configuration.Configurable;
+import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.configuration.ConfigurationException;
+import org.apache.avalon.framework.logger.LogEnabled;
+import org.apache.avalon.framework.logger.Logger;
+import org.apache.avalon.framework.service.ServiceException;
+import org.apache.avalon.framework.service.ServiceManager;
+import org.apache.avalon.framework.service.Serviceable;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.impl.AvalonLogger;
+import org.apache.james.api.dnsservice.DNSService;
+import org.apache.james.api.user.UsersRepository;
+import org.apache.james.bridge.GuiceInjected;
+import org.apache.james.services.MailServer;
+import org.apache.james.util.ConfigurationAdapter;
+import org.guiceyfruit.jsr250.Jsr250Module;
+
+import com.google.inject.AbstractModule;
+import com.google.inject.Guice;
+import com.google.inject.name.Names;
+
+public class AvalonFetchScheduler implements Serviceable, Configurable, Initializable, GuiceInjected, LogEnabled, FetchSchedulerMBean{
+
+    private Log logger;
+    private DNSService dns;
+    private MailServer mailserver;
+    private UsersRepository userRepos;
+    private ConfigurationAdapter config;
+    private FetchScheduler scheduler;
+    private TimeScheduler tscheduler;
+
+    public void service(ServiceManager manager) throws ServiceException {
+        dns = (DNSService) manager.lookup(DNSService.ROLE);
+        mailserver = (MailServer) manager.lookup(MailServer.ROLE);
+        tscheduler = (TimeScheduler) manager.lookup(TimeScheduler.ROLE);
+        userRepos = (UsersRepository) manager.lookup(UsersRepository.ROLE);
+    }
+
+    public void configure(Configuration config) throws ConfigurationException {
+        try {
+            this.config = new ConfigurationAdapter(config);
+        } catch (org.apache.commons.configuration.ConfigurationException e) {
+            throw new ConfigurationException("Unable to convert configuration", e);
+        }
+    }
+
+
+    public void initialize() throws Exception {
+        scheduler = Guice.createInjector(new Jsr250Module(), new AbstractModule() {
+
+            @Override
+            protected void configure() {
+                bind(DNSService.class).annotatedWith(Names.named("org.apache.james.api.dnsservice.DNSService")).toInstance(dns);
+                bind(org.apache.commons.configuration.HierarchicalConfiguration.class).annotatedWith(Names.named("org.apache.commons.configuration.Configuration")).toInstance(config);
+                bind(Log.class).annotatedWith(Names.named("org.apache.commons.logging.Log")).toInstance(logger);
+                bind(TimeScheduler.class).annotatedWith(Names.named("org.apache.avalon.cornerstone.services.scheduler.TimeScheduler")).toInstance(tscheduler);
+                bind(MailServer.class).annotatedWith(Names.named("org.apache.james.services.MailServer")).toInstance(mailserver);
+                bind(UsersRepository.class).annotatedWith(Names.named("org.apache.james.api.user.UsersRepository")).toInstance(userRepos);
+            }
+            
+        }).getInstance(FetchScheduler.class);
+    }
+
+ 
+
+    /**
+     * @see org.apache.avalon.framework.logger.LogEnabled#enableLogging(org.apache.avalon.framework.logger.Logger)
+     */
+    public void enableLogging(Logger logger) {
+        this.logger = new AvalonLogger(logger);
+    }
+
+
+    public boolean isEnabled() {
+        return scheduler.isEnabled();
+    }
+
+}

Modified: james/server/trunk/fetchmail-function/src/main/java/org/apache/james/fetchmail/DynamicAccount.java
URL: http://svn.apache.org/viewvc/james/server/trunk/fetchmail-function/src/main/java/org/apache/james/fetchmail/DynamicAccount.java?rev=883705&r1=883704&r2=883705&view=diff
==============================================================================
--- james/server/trunk/fetchmail-function/src/main/java/org/apache/james/fetchmail/DynamicAccount.java (original)
+++ james/server/trunk/fetchmail-function/src/main/java/org/apache/james/fetchmail/DynamicAccount.java Tue Nov 24 14:45:05 2009
@@ -23,7 +23,7 @@
 
 import javax.mail.Session;
 
-import org.apache.avalon.framework.configuration.ConfigurationException;
+import org.apache.commons.configuration.ConfigurationException;
 
 public class DynamicAccount extends Account
 {

Modified: james/server/trunk/fetchmail-function/src/main/java/org/apache/james/fetchmail/FetchMail.java
URL: http://svn.apache.org/viewvc/james/server/trunk/fetchmail-function/src/main/java/org/apache/james/fetchmail/FetchMail.java?rev=883705&r1=883704&r2=883705&view=diff
==============================================================================
--- james/server/trunk/fetchmail-function/src/main/java/org/apache/james/fetchmail/FetchMail.java (original)
+++ james/server/trunk/fetchmail-function/src/main/java/org/apache/james/fetchmail/FetchMail.java Tue Nov 24 14:45:05 2009
@@ -30,17 +30,15 @@
 import java.util.Map;
 import java.util.Properties;
 
+import javax.annotation.PostConstruct;
+import javax.annotation.Resource;
 import javax.mail.MessagingException;
 import javax.mail.Session;
 
 import org.apache.avalon.cornerstone.services.scheduler.Target;
-import org.apache.avalon.framework.configuration.Configurable;
-import org.apache.avalon.framework.configuration.Configuration;
-import org.apache.avalon.framework.configuration.ConfigurationException;
-import org.apache.avalon.framework.logger.AbstractLogEnabled;
-import org.apache.avalon.framework.service.ServiceException;
-import org.apache.avalon.framework.service.ServiceManager;
-import org.apache.avalon.framework.service.Serviceable;
+import org.apache.commons.configuration.ConfigurationException;
+import org.apache.commons.configuration.HierarchicalConfiguration;
+import org.apache.commons.logging.Log;
 import org.apache.james.api.dnsservice.DNSService;
 import org.apache.james.api.user.UsersRepository;
 import org.apache.james.services.MailServer;
@@ -74,8 +72,7 @@
  * <p>Creation Date: 24-May-03</p>
  * 
  */
-public class FetchMail extends AbstractLogEnabled implements Configurable, Target, Serviceable
-{
+public class FetchMail implements Target {
     /**
      * Key fields for DynamicAccounts.
      */
@@ -197,19 +194,19 @@
          */
         public ParsedDynamicAccountParameters(
             int sequenceNumber,
-            Configuration configuration)
+            org.apache.commons.configuration.Configuration configuration)
             throws ConfigurationException
         {
             this();
             setSequenceNumber(sequenceNumber);
-            setUserPrefix(configuration.getAttribute("userprefix", ""));
-            setUserSuffix(configuration.getAttribute("usersuffix", ""));
-            setRecipientPrefix(configuration.getAttribute("recipientprefix", ""));
-            setRecipientSuffix(configuration.getAttribute("recipientsuffix", ""));
-            setPassword(configuration.getAttribute("password"));
+            setUserPrefix(configuration.getString("[@userprefix]", ""));
+            setUserSuffix(configuration.getString("[@usersuffix]", ""));
+            setRecipientPrefix(configuration.getString("[@recipientprefix]", ""));
+            setRecipientSuffix(configuration.getString("[@recipientsuffix]", ""));
+            setPassword(configuration.getString("[@password]"));
             setIgnoreRecipientHeader(
-                configuration.getAttributeAsBoolean("ignorercpt-header"));
-            setCustomRecipientHeader(configuration.getAttribute("customrcpt-header", ""));
+                configuration.getBoolean("[@ignorercpt-header]"));
+            setCustomRecipientHeader(configuration.getString("[@customrcpt-header]", ""));
         }                       
 
         /**
@@ -403,6 +400,10 @@
      * The DNSService
      */
     private DNSService dnsServer;
+
+    private Log logger;
+
+    private HierarchicalConfiguration config;
     
     /**
      * Constructor for POP3mail.
@@ -420,7 +421,8 @@
      * 
      * @see org.apache.avalon.framework.configuration.Configurable#configure(Configuration)
      */
-    public void configure(Configuration configuration)
+    @SuppressWarnings("unchecked")
+    protected void configure(HierarchicalConfiguration configuration)
         throws ConfigurationException
     {
         // Set any Session parameters passed in the Configuration
@@ -430,30 +432,33 @@
         ParsedConfiguration parsedConfiguration =
             new ParsedConfiguration(
                 configuration,
-                getLogger(),
+                logger,
                 getServer(),
                 getLocalUsers(),
-                getDNSServer());
-        setConfiguration(parsedConfiguration);
+                getDNSService());
+        setParsedConfiguration(parsedConfiguration);
 
         // Setup the Accounts
-        Configuration[] allAccounts = configuration.getChildren("accounts");
-        if (allAccounts.length < 1)
+        List<HierarchicalConfiguration> allAccounts = configuration.configurationsAt("accounts");
+        if (allAccounts.size() < 1)
             throw new ConfigurationException("Missing <accounts> section.");
-        if (allAccounts.length > 1)
+        if (allAccounts.size() > 1)
             throw new ConfigurationException("Too many <accounts> sections, there must be exactly one");
-        Configuration accounts = allAccounts[0];
+        HierarchicalConfiguration accounts = allAccounts.get(0);
 
-        // Create an Account for every configured account
-        Configuration[] accountsChildren = accounts.getChildren();
-        if (accountsChildren.length < 1)
+    
+        if (accounts.getKeys().hasNext() == false)
             throw new ConfigurationException("Missing <account> section.");
 
-        for (int i = 0; i < accountsChildren.length; i++)
-        {
-            Configuration accountsChild = accountsChildren[i];
+        // Create an Account for every configured account
+        Iterator<String> accountsChildren = accounts.getKeys();
+        
+        int i = 0;
+        while (accountsChildren.hasNext()){
+            String accountsChildName = accountsChildren.next();
 
-            if ("alllocal".equals(accountsChild.getName()))
+            HierarchicalConfiguration accountsChild = accounts.configurationAt(accountsChildName);
+            if ("alllocal".equals(accountsChildName))
             {
                 // <allLocal> is dynamic, save the parameters for accounts to
                 // be created when the task is triggered
@@ -462,7 +467,7 @@
                 continue;
             }
 
-            if ("account".equals(accountsChild.getName()))
+            if ("account".equals(accountsChildName))
             {
                 // Create an Account for the named user and
                 // add it to the list of static accounts
@@ -470,21 +475,27 @@
                     new Account(
                         i,
                         parsedConfiguration,
-                        accountsChild.getAttribute("user"),
-                        accountsChild.getAttribute("password"),
-                        accountsChild.getAttribute("recipient"),
-                        accountsChild.getAttributeAsBoolean(
-                            "ignorercpt-header"),
-                        accountsChild.getAttribute("customrcpt-header",""),
+                        accountsChild.getString("[@user]"),
+                        accountsChild.getString("[@password]"),
+                        accountsChild.getString("[@recipient]"),
+                        accountsChild.getBoolean(
+                            "[@ignorercpt-header]"),
+                        accountsChild.getString("[@customrcpt-header]",""),
                         getSession()));
                 continue;
             }
 
             throw new ConfigurationException(
                 "Illegal token: <"
-                    + accountsChild.getName()
+                    + accountsChildName
                     + "> in <accounts>");
         }
+        i++;
+    }
+    
+    @PostConstruct
+    public void init() throws Exception{
+        configure(config);
     }
 
     /**
@@ -497,7 +508,7 @@
         // if we are already fetching then just return
         if (isFetching())
         {
-            getLogger().info(
+            logger.info(
                 "Triggered fetch cancelled. A fetch is already in progress.");
             return;
         }
@@ -506,7 +517,7 @@
         try
         {
             setFetching(true);
-            getLogger().info("Fetcher starting fetches");
+            logger.info("Fetcher starting fetches");
 
             logJavaMailProperties();
 
@@ -528,7 +539,7 @@
             logMessage.append(" static accounts and ");
             logMessage.append(getDynamicAccounts().size());
             logMessage.append(" dynamic accounts.");
-            getLogger().info(logMessage.toString());
+            logger.info(logMessage.toString());
 
             // Fetch each account
             Iterator<Account> accounts = mergedAccounts.iterator();
@@ -540,7 +551,7 @@
                 }
                 catch (MessagingException ex)
                 {
-                    getLogger().error(
+                    logger.error(
                         "A MessagingException has terminated processing of this Account",
                         ex);
                 }
@@ -548,11 +559,11 @@
         }
         catch (Exception ex)
         {
-            getLogger().error("An Exception has terminated this fetch.", ex);
+            logger.error("An Exception has terminated this fetch.", ex);
         }
         finally
         {
-            getLogger().info("Fetcher completed fetches");
+            logger.info("Fetcher completed fetches");
 
             // Exit Fetching State
             setFetching(false);
@@ -563,9 +574,9 @@
     private void logJavaMailProperties() {
         // if debugging, list the JavaMail property key/value pairs
         // for this Session
-        if (getLogger().isDebugEnabled())
+        if (logger.isDebugEnabled())
         {
-            getLogger().debug("Session properties:");
+            logger.debug("Session properties:");
             Properties properties = getSession().getProperties();
             Enumeration e = properties.keys();
             while (e.hasMoreElements())
@@ -576,7 +587,7 @@
                 {
                     val = val.substring(0, 37) + "...";
                 }
-                getLogger().debug(key + "=" + val);
+                logger.debug(key + "=" + val);
 
             }
         }
@@ -591,36 +602,6 @@
         return fieldFetching;
     }
 
-    /**
-     * @see org.apache.avalon.framework.service.Serviceable#service(ServiceManager)
-     */
-    public void service(final ServiceManager manager) throws ServiceException
-    {
-        try
-        {
-            setServer((MailServer) manager.lookup(MailServer.ROLE));
-        }
-        catch (ClassCastException cce)
-        {
-            StringBuilder errorBuffer =
-                new StringBuilder(128).append("Component ").append(
-                    MailServer.ROLE).append(
-                    "does not implement the required interface.");
-            throw new ServiceException("", errorBuffer.toString());
-        }
-        
-        DNSService dnsServer = (DNSService) manager.lookup(DNSService.ROLE);
-        setDNSServer(dnsServer);
-        
-        UsersRepository usersRepository =
-            (UsersRepository) manager.lookup(UsersRepository.ROLE);
-        setLocalUsers(usersRepository);
-    }
-
-
-
-            
-
 
     /**
      * Sets the fetching.
@@ -653,20 +634,12 @@
      * Sets the configuration.
      * @param configuration The configuration to set
      */
-    protected void setConfiguration(ParsedConfiguration configuration)
+    protected void setParsedConfiguration(ParsedConfiguration configuration)
     {
         fieldConfiguration = configuration;
     }
 
-    /**
-     * Sets the server.
-     * @param server The server to set
-     */
-    protected void setServer(MailServer server)
-    {
-        fieldServer = server;
-    }
-    
+   
     /**
      * Returns the localUsers.
      * @return UsersRepository
@@ -676,33 +649,44 @@
         return fieldLocalUsers;
     }
     
-    /**
-     * Sets the localUsers.
-     * @param localUsers The localUsers to set
-     */
-    protected void setLocalUsers(UsersRepository localUsers)
-    {
-        fieldLocalUsers = localUsers;
-    }
+    
     
     /**
      * Returns the DNSService.
      * @return DNSService 
      */
-    protected DNSService getDNSServer()
+    protected DNSService getDNSService()
     {
         return dnsServer;
     }
     
-    /**
-     * Sets the DNSService.
-     * @param dnsServer The DNSService to set
-     */
-    protected void setDNSServer(DNSService dnsServer)
-    {
-        this.dnsServer = dnsServer;
+    
+    @Resource(name="org.apache.james.api.dnsservice.DNSService")
+    public void setDNSService(DNSService dns) {
+        this.dnsServer = dns;
+    }
+
+
+    @Resource(name="org.apache.james.services.MailServer")
+    public void setMailServer(MailServer mailserver) {
+        this.fieldServer = mailserver;
+    }
+   
+    @Resource(name="org.apache.james.api.user.UsersRepository")
+    public void setUsersRepository(UsersRepository urepos) {
+        this.fieldLocalUsers = urepos;
     }
 
+    @Resource(name="org.apache.commons.logging.Log")
+    public final void setLogger(Log logger) {
+        this.logger = logger;
+    }
+    
+
+    @Resource(name="org.apache.commons.configuration.Configuration")
+    public final void setConfiguration(HierarchicalConfiguration config) {
+        this.config = config;
+    }
 
     /**
      * Returns the accounts. Initializes if required.
@@ -986,30 +970,31 @@
      * @param configuration The configuration containing the parameters
      * @throws ConfigurationException
      */
-    protected void setSessionParameters(Configuration configuration)
+    @SuppressWarnings("unchecked")
+    protected void setSessionParameters(HierarchicalConfiguration configuration)
         throws ConfigurationException
     {
-        Configuration javaMailProperties =
-            configuration.getChild("javaMailProperties", false);
-        if (null != javaMailProperties)
+        
+        if (configuration.getKeys("javaMailProperties.property").hasNext())
         {
             Properties properties = getSession().getProperties();
-            Configuration[] allProperties =
-                javaMailProperties.getChildren("property");
-            for (int i = 0; i < allProperties.length; i++)
+            List<HierarchicalConfiguration> allProperties =
+                configuration.configurationsAt("javaMailProperties.property");
+            for (int i = 0; i < allProperties.size(); i++)
             {
+                HierarchicalConfiguration propConf = allProperties.get(i);
                 properties.setProperty(
-                    allProperties[i].getAttribute("name"),
-                    allProperties[i].getAttribute("value"));
-                if (getLogger().isDebugEnabled())
+                        propConf.getString("[@name]"),
+                        propConf.getString("[@value]"));
+                if (logger.isDebugEnabled())
                 {
                     StringBuilder messageBuffer =
                         new StringBuilder("Set property name: ");
-                    messageBuffer.append(allProperties[i].getAttribute("name"));
+                    messageBuffer.append(propConf.getString("[@name]"));
                     messageBuffer.append(" to: ");
                     messageBuffer.append(
-                        allProperties[i].getAttribute("value"));
-                    getLogger().debug(messageBuffer.toString());
+                        propConf.getString("[@value]"));
+                    logger.debug(messageBuffer.toString());
                 }
             }
         }

Modified: james/server/trunk/fetchmail-function/src/main/java/org/apache/james/fetchmail/FetchScheduler.java
URL: http://svn.apache.org/viewvc/james/server/trunk/fetchmail-function/src/main/java/org/apache/james/fetchmail/FetchScheduler.java?rev=883705&r1=883704&r2=883705&view=diff
==============================================================================
--- james/server/trunk/fetchmail-function/src/main/java/org/apache/james/fetchmail/FetchScheduler.java (original)
+++ james/server/trunk/fetchmail-function/src/main/java/org/apache/james/fetchmail/FetchScheduler.java Tue Nov 24 14:45:05 2009
@@ -23,19 +23,19 @@
 
 import java.util.ArrayList;
 import java.util.Iterator;
+import java.util.List;
+
+import javax.annotation.PostConstruct;
+import javax.annotation.PreDestroy;
+import javax.annotation.Resource;
 
 import org.apache.avalon.cornerstone.services.scheduler.PeriodicTimeTrigger;
 import org.apache.avalon.cornerstone.services.scheduler.TimeScheduler;
-import org.apache.avalon.framework.activity.Disposable;
-import org.apache.avalon.framework.activity.Initializable;
-import org.apache.avalon.framework.configuration.Configurable;
-import org.apache.avalon.framework.configuration.Configuration;
-import org.apache.avalon.framework.configuration.ConfigurationException;
-import org.apache.avalon.framework.container.ContainerUtil;
-import org.apache.avalon.framework.logger.AbstractLogEnabled;
-import org.apache.avalon.framework.service.ServiceException;
-import org.apache.avalon.framework.service.ServiceManager;
-import org.apache.avalon.framework.service.Serviceable;
+import org.apache.commons.configuration.HierarchicalConfiguration;
+import org.apache.commons.logging.Log;
+import org.apache.james.api.dnsservice.DNSService;
+import org.apache.james.api.user.UsersRepository;
+import org.apache.james.services.MailServer;
 
 /**
  *  A class to instantiate and schedule a set of mail fetching tasks
@@ -43,19 +43,13 @@
  * $Id$
  *
  */
-public class FetchScheduler
-    extends AbstractLogEnabled
-    implements Serviceable, Configurable, Initializable, Disposable, FetchSchedulerMBean {
+public class FetchScheduler implements FetchSchedulerMBean {
 
     /**
      * Configuration object for this service
      */
-    private Configuration conf;
+    private HierarchicalConfiguration conf;
 
-    /**
-     * The service manager that allows access to the system services
-     */
-    private ServiceManager m_manager;
 
     /**
      * The scheduler service that is used to trigger fetch tasks.
@@ -69,51 +63,70 @@
 
     private ArrayList<String> theFetchTaskNames = new ArrayList<String>();
 
-    public void setScheduler(TimeScheduler scheduler) {
+
+    private DNSService dns;
+
+
+    private MailServer mailserver;
+
+
+    private UsersRepository urepos;
+
+
+    private Log logger;
+
+    @Resource(name="org.apache.avalon.cornerstone.services.scheduler.TimeScheduler")
+    public void setTimeScheduler(TimeScheduler scheduler) {
         this.scheduler = scheduler;
     }
 
-    /**
-     * @see org.apache.avalon.framework.service.Serviceable#service( ServiceManager )
-     */
-    public void service(ServiceManager comp) throws ServiceException
-    {
-        m_manager = comp;
+    
+    @Resource(name="org.apache.james.api.dnsservice.DNSService")
+    public void setDNSService(DNSService dns) {
+        this.dns = dns;
     }
 
-    /**
-     * @see org.apache.avalon.framework.configuration.Configurable#configure(Configuration)
-     */
-    public void configure(Configuration conf) throws ConfigurationException
-    {
-        this.conf = conf;
-    }
 
-    /**
-     * @see org.apache.avalon.framework.activity.Initializable#initialize()
-     */
-    public void initialize() throws Exception
+    @Resource(name="org.apache.james.services.MailServer")
+    public void setMailServer(MailServer mailserver) {
+        this.mailserver = mailserver;
+    }
+   
+    @Resource(name="org.apache.james.api.user.UsersRepository")
+    public void setUsersRepository(UsersRepository urepos) {
+        this.urepos = urepos;
+    }
+    
+    @Resource(name="org.apache.commons.logging.Log")
+    public final void setLogger(Log logger) {
+        this.logger = logger;
+    }
+    
+    @SuppressWarnings("unchecked")
+    @PostConstruct
+    public void init() throws Exception
     {
-        enabled = conf.getAttributeAsBoolean("enabled", false);
+        enabled = conf.getBoolean("[@enabled]", false);
         if (enabled)
         {
-            TimeScheduler scheduler = (TimeScheduler) m_manager.lookup(TimeScheduler.ROLE);
-            setScheduler(scheduler);
 
-            Configuration[] fetchConfs = conf.getChildren("fetch");
-            for (int i = 0; i < fetchConfs.length; i++)
+            List<HierarchicalConfiguration> fetchConfs = conf.configurationsAt("fetch");
+            for (int i = 0; i < fetchConfs.size(); i++)
             {
                 // read configuration
-                Configuration fetchConf = fetchConfs[i];
-                String fetchTaskName = fetchConf.getAttribute("name");
-                Integer interval = new Integer(fetchConf.getChild("interval").getValue());
+                HierarchicalConfiguration fetchConf = fetchConfs.get(i);
+                String fetchTaskName = fetchConf.getString("[@name]");
+                Integer interval = new Integer(fetchConf.getInt("interval"));
 
                 FetchMail fetcher = new FetchMail();
-                
+                fetcher.setConfiguration(fetchConf);
+                fetcher.setDNSService(dns);
+                fetcher.setMailServer(mailserver);
+                fetcher.setUsersRepository(urepos);
+                fetcher.setLogger(logger);
                 // avalon specific initialization
-                ContainerUtil.enableLogging(fetcher,getLogger().getChildLogger(fetchTaskName));
-                ContainerUtil.service(fetcher,m_manager);
-                ContainerUtil.configure(fetcher,fetchConf);
+               // ContainerUtil.enableLogging(fetcher,getLogger().getChildLogger(fetchTaskName));
+
 
                 // initialize scheduling
                 PeriodicTimeTrigger fetchTrigger =
@@ -122,30 +135,28 @@
                 theFetchTaskNames.add(fetchTaskName);
             }
 
-            if (getLogger().isInfoEnabled()) getLogger().info("FetchMail Started");
+            if (logger.isInfoEnabled()) logger.info("FetchMail Started");
             System.out.println("FetchMail Started");
         }
         else
         {
-            if (getLogger().isInfoEnabled()) getLogger().info("FetchMail Disabled");
+            if (logger.isInfoEnabled()) logger.info("FetchMail Disabled");
             System.out.println("FetchMail Disabled");
         }
     }
 
-    /**
-     * @see org.apache.avalon.framework.activity.Disposable#dispose()
-     */
+    @PreDestroy
     public void dispose()
     {
         if (enabled)
         {
-            getLogger().info("FetchMail dispose...");
+            logger.info("FetchMail dispose...");
             Iterator<String> nameIterator = theFetchTaskNames.iterator();
             while (nameIterator.hasNext())
             {
                 scheduler.removeTrigger(nameIterator.next());
             }
-            getLogger().info("FetchMail ...dispose end");
+            logger.info("FetchMail ...dispose end");
         }
     }
     

Modified: james/server/trunk/fetchmail-function/src/main/java/org/apache/james/fetchmail/ParsedConfiguration.java
URL: http://svn.apache.org/viewvc/james/server/trunk/fetchmail-function/src/main/java/org/apache/james/fetchmail/ParsedConfiguration.java?rev=883705&r1=883704&r2=883705&view=diff
==============================================================================
--- james/server/trunk/fetchmail-function/src/main/java/org/apache/james/fetchmail/ParsedConfiguration.java (original)
+++ james/server/trunk/fetchmail-function/src/main/java/org/apache/james/fetchmail/ParsedConfiguration.java Tue Nov 24 14:45:05 2009
@@ -28,9 +28,9 @@
 
 import javax.mail.internet.ParseException;
 
-import org.apache.avalon.framework.configuration.Configuration;
-import org.apache.avalon.framework.configuration.ConfigurationException;
-import org.apache.avalon.framework.logger.Logger;
+import org.apache.commons.configuration.ConfigurationException;
+import org.apache.commons.configuration.HierarchicalConfiguration;
+import org.apache.commons.logging.Log;
 import org.apache.james.api.dnsservice.DNSService;
 import org.apache.james.api.user.UsersRepository;
 import org.apache.james.services.MailServer;
@@ -48,7 +48,7 @@
     /**
      * The logger.
      */
-    private Logger fieldLogger;
+    private Log fieldLogger;
     
     /**
      * The name of the folder to fetch from the javamail provider
@@ -327,7 +327,7 @@
      * @param dnsServer
      * @throws ConfigurationException
      */
-    public ParsedConfiguration(Configuration configuration, Logger logger, MailServer server, UsersRepository localUsers,DNSService dnsServer) throws ConfigurationException
+    public ParsedConfiguration(HierarchicalConfiguration configuration, Log logger, MailServer server, UsersRepository localUsers,DNSService dnsServer) throws ConfigurationException
     {
         this();
         setLogger(logger);
@@ -337,90 +337,87 @@
         configure(configuration);
     }
     
-    /**
-     * @see org.apache.avalon.framework.configuration.Configurable#configure(Configuration)
-     */
-    protected void configure(Configuration conf) throws ConfigurationException
+    
+    protected void configure(HierarchicalConfiguration conf) throws ConfigurationException
     {
-        setHost(conf.getChild("host").getValue());
+        setHost(conf.getString("host"));
 
-        setFetchTaskName(conf.getAttribute("name"));
+        setFetchTaskName(conf.getString("[@name]"));
         setJavaMailProviderName(
-            conf.getChild("javaMailProviderName").getValue());
-        setJavaMailFolderName(conf.getChild("javaMailFolderName").getValue());
-        setRecurse(conf.getChild("recursesubfolders").getValueAsBoolean());
+            conf.getString("javaMailProviderName"));
+        setJavaMailFolderName(conf.getString("javaMailFolderName"));
+        setRecurse(conf.getBoolean("recursesubfolders"));
 
-        Configuration recipientNotFound = conf.getChild("recipientnotfound");
+        HierarchicalConfiguration recipientNotFound = conf.configurationAt("recipientnotfound");
         setDeferRecipientNotFound(
-            recipientNotFound.getAttributeAsBoolean("defer"));
+            recipientNotFound.getBoolean("[@defer]"));
         setRejectRecipientNotFound(
-            recipientNotFound.getAttributeAsBoolean("reject"));
+            recipientNotFound.getBoolean("[@reject]"));
         setLeaveRecipientNotFound(
-            recipientNotFound.getAttributeAsBoolean("leaveonserver"));
+            recipientNotFound.getBoolean("[@leaveonserver]"));
         setMarkRecipientNotFoundSeen(
-            recipientNotFound.getAttributeAsBoolean("markseen"));
+            recipientNotFound.getBoolean("[@markseen]"));
+        setDefaultDomainName(conf.getString("defaultdomain"));
 
-        Configuration defaultDomainName = conf.getChild("defaultdomain", false);
-        if (null != defaultDomainName)
-            setDefaultDomainName(defaultDomainName.getValue());
+        setFetchAll(conf.getBoolean("fetchall"));
 
-        setFetchAll(conf.getChild("fetchall").getValueAsBoolean());
+        HierarchicalConfiguration fetched = conf.configurationAt("fetched");
+        setLeave(fetched.getBoolean("[@leaveonserver]"));
+        setMarkSeen(fetched.getBoolean("[@markseen]"));
 
-        Configuration fetched = conf.getChild("fetched");
-        setLeave(fetched.getAttributeAsBoolean("leaveonserver"));
-        setMarkSeen(fetched.getAttributeAsBoolean("markseen"));
-
-        Configuration remoterecipient = conf.getChild("remoterecipient");
+        HierarchicalConfiguration remoterecipient = conf.configurationAt("remoterecipient");
         setRejectRemoteRecipient(
-            remoterecipient.getAttributeAsBoolean("reject"));
+            remoterecipient.getBoolean("[@reject]"));
         setLeaveRemoteRecipient(
-            remoterecipient.getAttributeAsBoolean("leaveonserver"));
+            remoterecipient.getBoolean("[@leaveonserver]"));
         setMarkRemoteRecipientSeen(
-            remoterecipient.getAttributeAsBoolean("markseen"));
+            remoterecipient.getBoolean("[@markseen]"));
 
-        Configuration blacklist = conf.getChild("blacklist");
-        setBlacklist(blacklist.getValue(""));
-        setRejectBlacklisted(blacklist.getAttributeAsBoolean("reject"));
-        setLeaveBlacklisted(blacklist.getAttributeAsBoolean("leaveonserver"));
-        setMarkBlacklistedSeen(blacklist.getAttributeAsBoolean("markseen"));
+        HierarchicalConfiguration blacklist = conf.configurationAt("blacklist");
+        setBlacklist(conf.getString("blacklist",""));
+        setRejectBlacklisted(blacklist.getBoolean("[@reject]"));
+        setLeaveBlacklisted(blacklist.getBoolean("[@leaveonserver]"));
+        setMarkBlacklistedSeen(blacklist.getBoolean("[@markseen]"));
 
-        Configuration userundefined = conf.getChild("userundefined");
-        setRejectUserUndefined(userundefined.getAttributeAsBoolean("reject"));
+        HierarchicalConfiguration userundefined = conf.configurationAt("userundefined");
+        setRejectUserUndefined(userundefined.getBoolean("[@reject]"));
         setLeaveUserUndefined(
-            userundefined.getAttributeAsBoolean("leaveonserver"));
+            userundefined.getBoolean("[@leaveonserver]"));
         setMarkUserUndefinedSeen(
-            userundefined.getAttributeAsBoolean("markseen"));
+            userundefined.getBoolean("[@markseen]"));
 
-        Configuration undeliverable = conf.getChild("undeliverable");
+        HierarchicalConfiguration undeliverable = conf.configurationAt("undeliverable");
         setLeaveUndeliverable(
-            undeliverable.getAttributeAsBoolean("leaveonserver"));
+            undeliverable.getBoolean("[@leaveonserver]"));
         setMarkUndeliverableSeen(
-            undeliverable.getAttributeAsBoolean("markseen"));
+            undeliverable.getBoolean("[@markseen]"));
 
-        Configuration remotereceivedheader = conf.getChild("remotereceivedheader", false);
-        if (null != remotereceivedheader)
+        if (conf.getKeys("remotereceivedheader").hasNext())
         {
+            HierarchicalConfiguration remotereceivedheader = conf.configurationAt("remotereceivedheader");
+
             setRemoteReceivedHeaderIndex(
-                remotereceivedheader.getAttributeAsInteger("index"));
+                remotereceivedheader.getInt("[@index]"));
             setRejectRemoteReceivedHeaderInvalid(
-                remotereceivedheader.getAttributeAsBoolean("reject"));
+                remotereceivedheader.getBoolean("[@reject]"));
             setLeaveRemoteReceivedHeaderInvalid(
-                remotereceivedheader.getAttributeAsBoolean("leaveonserver"));
+                remotereceivedheader.getBoolean("[@leaveonserver]"));
             setMarkRemoteReceivedHeaderInvalidSeen(
-                remotereceivedheader.getAttributeAsBoolean("markseen"));
+                remotereceivedheader.getBoolean("[@markseen]"));
         }            
 
-        Configuration maxmessagesize = conf.getChild("maxmessagesize", false);
-        if (null != maxmessagesize)
+        if (conf.getKeys("maxmessagesize").hasNext())
         {
+            HierarchicalConfiguration maxmessagesize = conf.configurationAt("maxmessagesize");
+
             setMaxMessageSizeLimit(
-                maxmessagesize.getAttributeAsInteger("limit") * 1024);
+                maxmessagesize.getInt("[@limit]") * 1024);
             setRejectMaxMessageSizeExceeded(
-                maxmessagesize.getAttributeAsBoolean("reject"));
+                maxmessagesize.getBoolean("[@reject]"));
             setLeaveMaxMessageSizeExceeded(
-                maxmessagesize.getAttributeAsBoolean("leaveonserver"));
+                maxmessagesize.getBoolean("[@leaveonserver]"));
             setMarkMaxMessageSizeExceededSeen(
-                maxmessagesize.getAttributeAsBoolean("markseen"));
+                maxmessagesize.getBoolean("[@markseen]"));
         }
 
         if (getLogger().isDebugEnabled())
@@ -589,7 +586,7 @@
      * Returns the logger.
      * @return Logger
      */
-    public Logger getLogger()
+    public Log getLogger()
     {
         return fieldLogger;
     }
@@ -598,7 +595,7 @@
      * Sets the logger.
      * @param logger The logger to set
      */
-    protected void setLogger(Logger logger)
+    protected void setLogger(Log logger)
     {
         fieldLogger = logger;
     }

Modified: james/server/trunk/fetchmail-function/src/main/java/org/apache/james/fetchmail/ProcessorAbstract.java
URL: http://svn.apache.org/viewvc/james/server/trunk/fetchmail-function/src/main/java/org/apache/james/fetchmail/ProcessorAbstract.java?rev=883705&r1=883704&r2=883705&view=diff
==============================================================================
--- james/server/trunk/fetchmail-function/src/main/java/org/apache/james/fetchmail/ProcessorAbstract.java (original)
+++ james/server/trunk/fetchmail-function/src/main/java/org/apache/james/fetchmail/ProcessorAbstract.java Tue Nov 24 14:45:05 2009
@@ -27,7 +27,7 @@
 import javax.mail.MessagingException;
 import javax.mail.Session;
 
-import org.apache.avalon.framework.logger.Logger;
+import org.apache.commons.logging.Log;
 import org.apache.james.api.dnsservice.DNSService;
 import org.apache.james.api.user.UsersRepository;
 import org.apache.james.services.MailServer;
@@ -152,7 +152,7 @@
      * Returns the logger.
      * @return Logger
      */
-    protected Logger getLogger()
+    protected Log getLogger()
     {
         return getConfiguration().getLogger();
     }

Modified: james/server/trunk/phoenix-deployment/src/conf/james-assembly.xml
URL: http://svn.apache.org/viewvc/james/server/trunk/phoenix-deployment/src/conf/james-assembly.xml?rev=883705&r1=883704&r2=883705&view=diff
==============================================================================
--- james/server/trunk/phoenix-deployment/src/conf/james-assembly.xml (original)
+++ james/server/trunk/phoenix-deployment/src/conf/james-assembly.xml Tue Nov 24 14:45:05 2009
@@ -227,7 +227,7 @@
   </block>
 
   <!-- FetchMail Service -->
-  <block name="fetchmail" class="org.apache.james.fetchmail.FetchScheduler" >
+  <block name="fetchmail" class="org.apache.james.fetchmail.AvalonFetchScheduler" >
     <provide name="scheduler"
              role="org.apache.avalon.cornerstone.services.scheduler.TimeScheduler"/> 
     <provide name="James" role="org.apache.james.services.MailServer"/>      



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