james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nor...@apache.org
Subject svn commit: r833892 - in /james/server/trunk: imapserver-function/ imapserver-function/src/main/java/org/apache/james/imapserver/ imapserver-function/src/main/resources/org/apache/james/imapserver/ nntpserver-function/src/main/java/org/apache/james/nnt...
Date Sun, 08 Nov 2009 17:06:13 GMT
Author: norman
Date: Sun Nov  8 17:06:13 2009
New Revision: 833892

URL: http://svn.apache.org/viewvc?rev=833892&view=rev
Log:
More work on using guice for injection (JAMES-893)

Added:
    james/server/trunk/imapserver-function/src/main/java/org/apache/james/imapserver/AvalonImapServer.java
    james/server/trunk/imapserver-function/src/main/resources/org/apache/james/imapserver/AvalonImapServer.xinfo
      - copied unchanged from r829946, james/server/trunk/imapserver-function/src/main/resources/org/apache/james/imapserver/ImapServer.xinfo
    james/server/trunk/phoenix-deployment/phoenix-bin/lib/commons-logging-1.1.jar   (with
props)
Removed:
    james/server/trunk/imapserver-function/src/main/resources/org/apache/james/imapserver/ImapServer.xinfo
Modified:
    james/server/trunk/imapserver-function/pom.xml
    james/server/trunk/imapserver-function/src/main/java/org/apache/james/imapserver/ImapServer.java
    james/server/trunk/nntpserver-function/src/main/java/org/apache/james/nntpserver/repository/NNTPRepositoryImpl.java
    james/server/trunk/nntpserver-function/src/main/java/org/apache/james/nntpserver/repository/NNTPSpooler.java
    james/server/trunk/phoenix-deployment/src/conf/james-assembly.xml

Modified: james/server/trunk/imapserver-function/pom.xml
URL: http://svn.apache.org/viewvc/james/server/trunk/imapserver-function/pom.xml?rev=833892&r1=833891&r2=833892&view=diff
==============================================================================
--- james/server/trunk/imapserver-function/pom.xml (original)
+++ james/server/trunk/imapserver-function/pom.xml Sun Nov  8 17:06:13 2009
@@ -103,7 +103,23 @@
       <groupId>org.apache.james</groupId>
       <artifactId>apache-james-imap-seda</artifactId>
     </dependency>
-
+    <dependency>
+      <groupId>org.apache.james</groupId>
+      <artifactId>james-server-avalon-guice-bridge-api</artifactId>
+    </dependency>
+     <dependency>
+      <groupId>com.google.code.guice</groupId>
+      <artifactId>guice</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.guiceyfruit</groupId>
+      <artifactId>guiceyfruit-core</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>spring-aopalliance</groupId>
+      <artifactId>spring-aopalliance</artifactId>
+      <scope>runtime</scope>
+    </dependency>
     <dependency>
       <groupId>org.apache.avalon.framework</groupId>
       <artifactId>avalon-framework-api</artifactId>

Added: james/server/trunk/imapserver-function/src/main/java/org/apache/james/imapserver/AvalonImapServer.java
URL: http://svn.apache.org/viewvc/james/server/trunk/imapserver-function/src/main/java/org/apache/james/imapserver/AvalonImapServer.java?rev=833892&view=auto
==============================================================================
--- james/server/trunk/imapserver-function/src/main/java/org/apache/james/imapserver/AvalonImapServer.java
(added)
+++ james/server/trunk/imapserver-function/src/main/java/org/apache/james/imapserver/AvalonImapServer.java
Sun Nov  8 17:06:13 2009
@@ -0,0 +1,121 @@
+package org.apache.james.imapserver;
+
+import javax.mail.MessagingException;
+import javax.mail.internet.MimeMessage;
+
+import org.apache.avalon.cornerstone.services.sockets.SocketManager;
+import org.apache.avalon.cornerstone.services.threads.ThreadManager;
+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.kernel.LoaderService;
+import org.apache.james.api.user.UsersRepository;
+import org.apache.james.services.FileSystem;
+import org.apache.james.services.MailServer;
+import org.apache.james.socket.JamesConnectionManager;
+import org.apache.james.socket.api.ProtocolHandlerFactory;
+import org.apache.james.util.ConfigurationAdapter;
+import org.apache.james.bridge.GuiceInjected;
+import org.apache.jsieve.mailet.Poster;
+
+import org.guiceyfruit.jsr250.Jsr250Module;
+
+import com.google.inject.AbstractModule;
+import com.google.inject.Guice;
+import com.google.inject.Injector;
+import com.google.inject.Provider;
+import com.google.inject.name.Names;
+
+public class AvalonImapServer implements GuiceInjected, Poster, Initializable, Serviceable,
Configurable, LogEnabled {
+    private FileSystem filesystem;
+    private MailServer mailserver;
+    private DNSService dns;
+    private Log logger;
+    private org.apache.commons.configuration.HierarchicalConfiguration config;
+    private Injector injector;
+    private UsersRepository userRepos;
+    private JamesConnectionManager connectionManager;
+    private SocketManager socketManager;
+    private ImapServer imapserver = new ImapServer();
+    private ThreadManager threadManager;
+
+
+    /**
+     * @see org.apache.avalon.framework.configuration.Configurable#configure(org.apache.avalon.framework.configuration.Configuration)
+     */
+    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);
+        }
+    }
+
+    /**
+     * @see org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager)
+     */
+    public void service(ServiceManager manager) throws ServiceException {
+        dns = (DNSService) manager.lookup(DNSService.ROLE);
+        mailserver = (MailServer) manager.lookup(MailServer.ROLE);
+        filesystem = (FileSystem) manager.lookup(FileSystem.ROLE);
+        userRepos = (UsersRepository) manager.lookup(UsersRepository.ROLE);
+        socketManager = (SocketManager) manager.lookup(SocketManager.ROLE);
+        connectionManager = (JamesConnectionManager) manager.lookup(JamesConnectionManager.ROLE);
    
+        threadManager = (ThreadManager) manager.lookup(ThreadManager.ROLE);
+        // thats needed because of used excalibur socket components
+        imapserver.service(manager);
+    }
+
+    /**
+     * @see org.apache.avalon.framework.activity.Initializable#initialize()
+     */
+    public void initialize() throws Exception {
+        injector = Guice.createInjector(new IMAPServerModule(), new Jsr250Module());
+        injector.injectMembers(imapserver);
+    }
+                 
+    /**
+     * @see org.apache.avalon.framework.logger.LogEnabled#enableLogging(org.apache.avalon.framework.logger.Logger)
+     */
+    public void enableLogging(Logger logger) {
+        this.logger = new AvalonLogger(logger);
+    }
+    
+    private final class IMAPServerModule extends AbstractModule {
+
+        @Override
+        protected void configure() {
+            bind(DNSService.class).annotatedWith(Names.named("org.apache.james.api.dnsservice.DNSService")).toInstance(dns);
+            bind(MailServer.class).annotatedWith(Names.named("org.apache.james.services.MailServer")).toInstance(mailserver);
+            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(FileSystem.class).annotatedWith(Names.named("org.apache.james.services.FileSystem")).toInstance(filesystem);
+            bind(UsersRepository.class).annotatedWith(Names.named("org.apache.james.api.user.UsersRepository")).toInstance(userRepos);
+            bind(ProtocolHandlerFactory.class).annotatedWith(Names.named("org.apache.james.socket.api.ProtocolHandlerFactory")).toProvider(new
Provider<ProtocolHandlerFactory>() {
+
+                public ProtocolHandlerFactory get() {
+                    return imapserver;
+                }
+                
+            });
+            bind(SocketManager.class).annotatedWith(Names.named("org.apache.avalon.cornerstone.services.sockets.SocketManager")).toInstance(socketManager);
+            bind(JamesConnectionManager.class).annotatedWith(Names.named("org.apache.james.socket.JamesConnectionManager")).toInstance(connectionManager);
+            bind(ThreadManager.class).annotatedWith(Names.named("org.apache.avalon.cornerstone.services.threads.ThreadManager")).toInstance(threadManager);
+
+        }
+    }
+
+    public void post(String url, MimeMessage mail) throws MessagingException {
+        imapserver.post(url, mail);
+    }
+
+}

Modified: james/server/trunk/imapserver-function/src/main/java/org/apache/james/imapserver/ImapServer.java
URL: http://svn.apache.org/viewvc/james/server/trunk/imapserver-function/src/main/java/org/apache/james/imapserver/ImapServer.java?rev=833892&r1=833891&r2=833892&view=diff
==============================================================================
--- james/server/trunk/imapserver-function/src/main/java/org/apache/james/imapserver/ImapServer.java
(original)
+++ james/server/trunk/imapserver-function/src/main/java/org/apache/james/imapserver/ImapServer.java
Sun Nov  8 17:06:13 2009
@@ -23,6 +23,7 @@
 import java.io.IOException;
 import java.util.Date;
 
+import javax.annotation.PostConstruct;
 import javax.annotation.Resource;
 import javax.mail.MessagingException;
 import javax.mail.internet.MimeMessage;
@@ -57,25 +58,34 @@
     private String hello = softwaretype;
 
     private UsersRepository usersRepos;
+    private HierarchicalConfiguration configuration;
 
     @Resource(name="org.apache.james.api.user.UsersRepository")
     public void setUsersRepository(UsersRepository usersRepos) {
         this.usersRepos = usersRepos;
     }
-    
+
+    @PostConstruct
+    @Override
+    public void init() throws Exception {
+        super.init();
+    }
 
     @Override
     public  void doInit() throws Exception {
         getLog().debug("Initialising...");
-        factory = new DefaultImapFactory(getFileSystem(),usersRepos , getLog());
+        factory = new DefaultImapFactory(getFileSystem(), usersRepos, getLog());
+        factory.configure(configuration);
+
         factory.init();
     }
 
 
 
+    @Override
     public void onConfigure( final HierarchicalConfiguration configuration ) throws ConfigurationException
{
-        factory.configure(configuration);
         hello  = softwaretype + " Server " + getHelloName() + " is ready.";
+        this.configuration = configuration;
     }
     
     /**
@@ -100,10 +110,13 @@
     {  
         final ImapRequestHandler handler = factory.createHandler();
         final ImapHandler imapHandler = new ImapHandler(handler, hello); 
-        getLogger().debug("Create handler instance");
+        getLog().debug("Create handler instance");
         return imapHandler;
     }
     
+    /**
+     * @see org.apache.jsieve.mailet.Poster#post(java.lang.String, javax.mail.internet.MimeMessage)
+     */
     public void post(String url, MimeMessage mail)throws MessagingException {
         final int endOfScheme = url.indexOf(':');
         if (endOfScheme < 0) {

Modified: james/server/trunk/nntpserver-function/src/main/java/org/apache/james/nntpserver/repository/NNTPRepositoryImpl.java
URL: http://svn.apache.org/viewvc/james/server/trunk/nntpserver-function/src/main/java/org/apache/james/nntpserver/repository/NNTPRepositoryImpl.java?rev=833892&r1=833891&r2=833892&view=diff
==============================================================================
--- james/server/trunk/nntpserver-function/src/main/java/org/apache/james/nntpserver/repository/NNTPRepositoryImpl.java
(original)
+++ james/server/trunk/nntpserver-function/src/main/java/org/apache/james/nntpserver/repository/NNTPRepositoryImpl.java
Sun Nov  8 17:06:13 2009
@@ -24,15 +24,17 @@
 import org.apache.commons.configuration.ConfigurationException;
 import org.apache.commons.configuration.HierarchicalConfiguration;
 import org.apache.commons.logging.Log;
-import org.apache.james.api.kernel.LoaderService;
-import org.apache.james.api.protocol.Configurable;
-import org.apache.james.api.protocol.LogEnabled;
 import org.apache.james.nntpserver.DateSinceFileFilter;
 import org.apache.james.nntpserver.NNTPException;
 import org.apache.james.services.FileSystem;
 import org.apache.james.util.io.AndFileFilter;
 import org.apache.james.util.io.DirectoryFileFilter;
 import org.apache.oro.io.GlobFilenameFilter;
+import org.guiceyfruit.jsr250.Jsr250Module;
+
+import com.google.inject.AbstractModule;
+import com.google.inject.Guice;
+import com.google.inject.name.Names;
 
 import java.io.File;
 import java.io.FileOutputStream;
@@ -140,8 +142,6 @@
 
     private Log logger;
 
-    private LoaderService loader;
-
     @Resource(name="org.apache.commons.configuration.Configuration")
     public void setConfiguration(HierarchicalConfiguration configuration) {
         this.configuration = configuration;
@@ -162,11 +162,6 @@
         this.fileSystem = system;
     }
     
-    @Resource(name="org.apache.james.LoaderService")
-    public void setLoaderService(LoaderService loader) {
-        this.loader = loader;
-    }
-    
     /**
      * @see org.apache.avalon.framework.configuration.Configurable#configure(Configuration)
      */
@@ -232,8 +227,6 @@
 
         articleIDRepo = new ArticleIDRepository(articleIDPath, articleIDDomainSuffix);
         spool = createSpooler();
-        spool.setRepository(this);
-        spool.setArticleIDRepository(articleIDRepo);
         if (logger.isDebugEnabled()) {
             logger.debug("repository:readOnly=" + readOnly);
             logger.debug("repository:rootPath=" + rootPath.getAbsolutePath());
@@ -469,7 +462,7 @@
     private NNTPSpooler createSpooler() 
             throws ConfigurationException {
         String className = NNTPSpooler.class.getName();
-        HierarchicalConfiguration spoolerConfiguration = configuration.configurationAt("spool");
+        final HierarchicalConfiguration spoolerConfiguration = configuration.configurationAt("spool");
         // Must be a subclass of org.apache.james.nntpserver.repository.NNTPSpooler
         className = spoolerConfiguration.getString("[@class]");
         if (className == null) {
@@ -477,14 +470,52 @@
         }
         try {
             Class<?> myClass = Thread.currentThread().getContextClassLoader().loadClass(className);
-            Object obj = loader.load(myClass);
-            if (obj instanceof LogEnabled) {
-                ((LogEnabled) obj).setLog(logger);
-            }
-            
-            if (obj instanceof Configurable) {
-                ((Configurable) obj).configure(spoolerConfiguration.configurationAt("configuration"));
-            }
+            Object obj = Guice.createInjector(new Jsr250Module(), new AbstractModule() {
+
+                @Override
+                protected void configure() {
+                    bind(HierarchicalConfiguration.class).annotatedWith(Names.named("org.apache.commons.configuration.Configuration")).toInstance(spoolerConfiguration.configurationAt("configuration"));
+                    bind(Log.class).annotatedWith(Names.named("org.apache.commons.logging.Log")).toInstance(logger);
+                    bind(FileSystem.class).annotatedWith(Names.named("org.apache.james.services.FileSystem")).toInstance(fileSystem);
+                    bind(ArticleIDRepository.class).annotatedWith(Names.named("org.apache.james.nntpserver.repository.ArticleIDRepository")).toInstance(articleIDRepo);
+                    bind(NNTPRepository.class).annotatedWith(Names.named("org.apache.james.nntpserver.repository.NNTPRepository")).toInstance(new
NNTPRepository() {
+
+                        public void createArticle(InputStream in) {
+                            NNTPRepositoryImpl.this.createArticle(in);
+                        }
+
+                        public NNTPArticle getArticleFromID(String id) {
+                            return NNTPRepositoryImpl.this.getArticleFromID(id);
+                        }
+
+                        public Iterator<NNTPArticle> getArticlesSince(Date dt) {
+                            return NNTPRepositoryImpl.this.getArticlesSince(dt);
+                        }
+
+                        public NNTPGroup getGroup(String groupName) {
+                            return NNTPRepositoryImpl.this.getGroup(groupName);
+                        }
+
+                        public Iterator<NNTPGroup> getGroupsSince(Date dt) {
+                            return NNTPRepositoryImpl.this.getGroupsSince(dt);
+                        }
+
+                        public Iterator<NNTPGroup> getMatchedGroups(String wildmat)
{
+                            return NNTPRepositoryImpl.this.getMatchedGroups(wildmat);
+                        }
+
+                        public String[] getOverviewFormat() {
+                            return NNTPRepositoryImpl.this.getOverviewFormat();
+                        }
+
+                        public boolean isReadOnly() {
+                            return NNTPRepositoryImpl.this.isReadOnly();
+                        }
+                        
+                    });
+                }
+                
+            }).getInstance(myClass);
             return (NNTPSpooler)obj;
         } catch(ClassCastException cce) {
             StringBuffer errorBuffer =

Modified: james/server/trunk/nntpserver-function/src/main/java/org/apache/james/nntpserver/repository/NNTPSpooler.java
URL: http://svn.apache.org/viewvc/james/server/trunk/nntpserver-function/src/main/java/org/apache/james/nntpserver/repository/NNTPSpooler.java?rev=833892&r1=833891&r2=833892&view=diff
==============================================================================
--- james/server/trunk/nntpserver-function/src/main/java/org/apache/james/nntpserver/repository/NNTPSpooler.java
(original)
+++ james/server/trunk/nntpserver-function/src/main/java/org/apache/james/nntpserver/repository/NNTPSpooler.java
Sun Nov  8 17:06:13 2009
@@ -21,11 +21,9 @@
 
 package org.apache.james.nntpserver.repository;
 
-import org.apache.commons.configuration.Configuration;
 import org.apache.commons.configuration.ConfigurationException;
+import org.apache.commons.configuration.HierarchicalConfiguration;
 import org.apache.commons.logging.Log;
-import org.apache.james.api.protocol.Configurable;
-import org.apache.james.api.protocol.LogEnabled;
 import org.apache.james.services.FileSystem;
 import org.apache.james.util.Lock;
 import org.apache.james.util.io.IOUtil;
@@ -47,8 +45,12 @@
  * Eats up inappropriate entries.
  *
  */
-public class NNTPSpooler implements Configurable, LogEnabled{
+public class NNTPSpooler {
 
+    private ArticleIDRepository idRepos;
+    
+    private NNTPRepository nntpRepos;
+    
     /**
      * The array of spooler runnables, each associated with a Worker thread
      */
@@ -76,8 +78,16 @@
 
     private Log logger;
 
+    private HierarchicalConfiguration config;
+
     @PostConstruct
     public void init() throws Exception {
+        int threadCount = config.getInt("threadCount", 1);
+        threadIdleTime = config.getInt("threadIdleTime", 60 * 1000);
+        spoolPathString = config.getString("spoolPath");
+        worker = new SpoolerRunnable[threadCount];
+        
+        
         try {
             spoolPath = fileSystem.getFile(spoolPathString);
             if ( spoolPath.exists() == false ) {
@@ -97,7 +107,10 @@
 
         for ( int i = 0 ; i < worker.length ; i++ ) {
             worker[i] = new SpoolerRunnable(threadIdleTime,spoolPath, logger);
+            worker[i].setRepository(nntpRepos);
+            worker[i].setArticleIDRepository(idRepos);
         }
+        
 
         // TODO: Replace this with a standard Avalon thread pool
         for ( int i = 0 ; i < worker.length ; i++ ) {
@@ -110,10 +123,9 @@
      *
      * @param repo the repository to be used
      */
-    void setRepository(NNTPRepository repo) {
-        for ( int i = 0 ; i < worker.length ; i++ ) {
-            worker[i].setRepository(repo);
-        }
+    @Resource(name="org.apache.james.nntpserver.repository.NNTPRepository")
+    void setNNTPRepository(NNTPRepository nntpRepos) {
+        this.nntpRepos = nntpRepos;
     }
 
     /**
@@ -121,10 +133,9 @@
      *
      * @param articleIDRepo the article id repository to be used
      */
-    void setArticleIDRepository(ArticleIDRepository articleIDRepo) {
-        for ( int i = 0 ; i < worker.length ; i++ ) {
-            worker[i].setArticleIDRepository(articleIDRepo);
-        }
+    @Resource(name="org.apache.james.nntpserver.repository.ArticleIDRepository")
+    void setArticleIDRepository(ArticleIDRepository idRepos) {
+        this.idRepos = idRepos;
     }
 
     /**
@@ -333,19 +344,14 @@
         this.fileSystem = fileSystem;
     }
 
-    /**
-     * @see org.apache.james.api.protocol.Configurable#configure(org.apache.commons.configuration.Configuration)
-     */
-    public void configure(Configuration config) throws ConfigurationException {
-        int threadCount = config.getInt("threadCount", 1);
-        threadIdleTime = config.getInt("threadIdleTime", 60 * 1000);
-        spoolPathString = config.getString("spoolPath");
-        worker = new SpoolerRunnable[threadCount];
+    
+    
+    @Resource(name="org.apache.commons.configuration.Configuration")
+    public void configure(HierarchicalConfiguration config) {
+        this.config = config;
     }
 
-    /**
-     * @see org.apache.james.api.protocol.LogEnabled#setLog(org.apache.commons.logging.Log)
-     */
+    @Resource(name="org.apache.commons.logging.Log")
     public void setLog(Log log) {
         this.logger = log;
     }

Added: james/server/trunk/phoenix-deployment/phoenix-bin/lib/commons-logging-1.1.jar
URL: http://svn.apache.org/viewvc/james/server/trunk/phoenix-deployment/phoenix-bin/lib/commons-logging-1.1.jar?rev=833892&view=auto
==============================================================================
Binary file - no diff available.

Propchange: james/server/trunk/phoenix-deployment/phoenix-bin/lib/commons-logging-1.1.jar
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

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=833892&r1=833891&r2=833892&view=diff
==============================================================================
--- james/server/trunk/phoenix-deployment/src/conf/james-assembly.xml (original)
+++ james/server/trunk/phoenix-deployment/src/conf/james-assembly.xml Sun Nov  8 17:06:13
2009
@@ -326,7 +326,7 @@
   
     
   <!-- IMAP server -->
-  <block name="imapserver" class="org.apache.james.imapserver.ImapServer">
+  <block name="imapserver" class="org.apache.james.imapserver.AvalonImapServer">
     <provide name="localusersrepository" role="org.apache.james.api.user.UsersRepository"/>
     <provide name="sockets"
              role="org.apache.avalon.cornerstone.services.sockets.SocketManager"/>



---------------------------------------------------------------------
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