Author: berndf
Date: Sun Oct 29 02:56:32 2006
New Revision: 468878

URL: http://svn.apache.org/viewvc?view=rev&rev=468878
Log:
prepare the management features for JAMES-635

Added:
    james/server/trunk/src/java/org/apache/james/services/SpoolManager.java
    james/server/trunk/src/java/org/apache/james/transport/MailetContainer.java
    james/server/trunk/src/java/org/apache/james/transport/ProcessorList.java
Modified:
    
james/server/trunk/src/java/org/apache/james/transport/JamesSpoolManager.java
    james/server/trunk/src/java/org/apache/james/transport/LinearProcessor.java
    
james/server/trunk/src/java/org/apache/james/transport/StateAwareProcessorList.java

Added: james/server/trunk/src/java/org/apache/james/services/SpoolManager.java
URL: 
http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/services/SpoolManager.java?view=auto&rev=468878
==============================================================================
--- james/server/trunk/src/java/org/apache/james/services/SpoolManager.java 
(added)
+++ james/server/trunk/src/java/org/apache/james/services/SpoolManager.java Sun 
Oct 29 02:56:32 2006
@@ -0,0 +1,47 @@
+/****************************************************************
+ * 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.services;
+
+import java.util.List;
+
+/**
+ * provide all the data needed to manage spool processors, mailets and matchers
+ */
+public interface SpoolManager {
+    String ROLE = "org.apache.james.services.SpoolManager";
+
+    /**
+     * @return names of all configured processors
+     */
+    String[] getProcessorNames();
+
+    /**
+     * retrieve all mailets for given processor
+     * @param processorName - name of the processor who's mailets should be 
retrieved
+     * @return List<MailetConfig>
+     */
+    List getMailetConfigs(String processorName);
+    
+    /**
+     * retrieve all matchers for given processor
+     * @param processorName - name of the processor who's matchers should be 
retrieved
+     * @return List<MatcherConfig>
+     */
+    List getMatcherConfigs(String processorName);
+}

Modified: 
james/server/trunk/src/java/org/apache/james/transport/JamesSpoolManager.java
URL: 
http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/transport/JamesSpoolManager.java?view=diff&rev=468878&r1=468877&r2=468878
==============================================================================
--- 
james/server/trunk/src/java/org/apache/james/transport/JamesSpoolManager.java 
(original)
+++ 
james/server/trunk/src/java/org/apache/james/transport/JamesSpoolManager.java 
Sun Oct 29 02:56:32 2006
@@ -33,10 +33,13 @@
 import org.apache.avalon.framework.service.Serviceable;
 import org.apache.james.services.MailProcessor;
 import org.apache.james.services.SpoolRepository;
+import org.apache.james.services.SpoolManager;
 import org.apache.mailet.Mail;
 
 import java.util.Collection;
 import java.util.Iterator;
+import java.util.List;
+import java.util.ArrayList;
 
 /**
  * Manages the mail spool.  This class is responsible for retrieving
@@ -48,7 +51,7 @@
  */
 public class JamesSpoolManager
     extends AbstractLogEnabled
-    implements Serviceable, Configurable, Initializable, Runnable, Disposable {
+    implements Serviceable, Configurable, Initializable, Runnable, Disposable, 
SpoolManager {
 
     /**
      * System component manager
@@ -124,7 +127,7 @@
      */
     public void configure(Configuration conf) throws ConfigurationException {
         numThreads = conf.getChild("threads").getValueAsInteger(1);
-        
+
         String processorClass = 
conf.getChild("processorClass").getValue("org.apache.james.transport.StateAwareProcessorList");
         try {
             processorList = (MailProcessor) 
Thread.currentThread().getContextClassLoader().loadClass(processorClass).newInstance();
@@ -132,7 +135,7 @@
             getLogger().error("Unable to instantiate spoolmanager processor: 
"+processorClass, e1);
             throw new ConfigurationException("Instantiation exception: 
"+processorClass, e1);
         }
-        
+
         try {
             ContainerUtil.enableLogging(processorList, getLogger());
             ContainerUtil.service(processorList, compMgr);
@@ -140,7 +143,7 @@
             getLogger().error(e.getMessage(), e);
             throw new ConfigurationException("Servicing failed with error: 
"+e.getMessage(),e);
         }
-        
+
         ContainerUtil.configure(processorList, conf);
     }
 
@@ -150,9 +153,9 @@
     public void initialize() throws Exception {
 
         getLogger().info("JamesSpoolManager init...");
-        
+
         ContainerUtil.initialize(processorList);
-        
+
         if (getLogger().isInfoEnabled()) {
             StringBuffer infoBuffer =
                 new StringBuffer(64)
@@ -284,8 +287,37 @@
             } catch (Exception ignored) {}
         }
         getLogger().info("JamesSpoolManager thread shutdown completed.");
-        
+
         ContainerUtil.dispose(processorList);
     }
 
+    public String[] getProcessorNames() {
+        if (!(processorList instanceof ProcessorList)) {
+            return new String[0];  
+        }
+        String[] processorNames = ((ProcessorList) 
processorList).getProcessorNames();
+        return processorNames;
+    }
+
+    public List getMailetConfigs(String processorName) {
+        MailetContainer mailetContainer = 
getMailetContainerByName(processorName);
+        if (mailetContainer == null) return new ArrayList();
+        return mailetContainer.getMailetConfigs();
+    }
+
+    public List getMatcherConfigs(String processorName) {
+        MailetContainer mailetContainer = 
getMailetContainerByName(processorName);
+        if (mailetContainer == null) return new ArrayList();
+        return mailetContainer.getMatcherConfigs();
+    }
+
+    private MailetContainer getMailetContainerByName(String processorName) {
+        if (!(processorList instanceof ProcessorList)) return null;
+        
+        MailProcessor processor = ((ProcessorList) 
processorList).getProcessor(processorName);
+        if (!(processor instanceof MailetContainer)) return null;
+        // TODO: decide, if we have to visit all sub-processors for being 
ProcessorLists 
+        // on their very own and collecting the processor names deeply.
+        return (MailetContainer)processor;
+    }
 }

Modified: 
james/server/trunk/src/java/org/apache/james/transport/LinearProcessor.java
URL: 
http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/transport/LinearProcessor.java?view=diff&rev=468878&r1=468877&r2=468878
==============================================================================
--- james/server/trunk/src/java/org/apache/james/transport/LinearProcessor.java 
(original)
+++ james/server/trunk/src/java/org/apache/james/transport/LinearProcessor.java 
Sun Oct 29 02:56:32 2006
@@ -32,6 +32,7 @@
 import org.apache.avalon.framework.service.Serviceable;
 import org.apache.james.core.MailImpl;
 import org.apache.james.core.MailetConfigImpl;
+import org.apache.james.core.MatcherConfigImpl;
 import org.apache.james.services.MailProcessor;
 import org.apache.james.services.MailetLoader;
 import org.apache.james.services.MatcherLoader;
@@ -45,6 +46,7 @@
 import org.apache.mailet.MailetConfig;
 import org.apache.mailet.MailetException;
 import org.apache.mailet.Matcher;
+import org.apache.mailet.MatcherConfig;
 
 import javax.mail.MessagingException;
 
@@ -93,7 +95,7 @@
  */
 public class LinearProcessor 
     extends AbstractLogEnabled
-    implements Disposable, Configurable, Serviceable, MailProcessor {
+    implements Disposable, Configurable, Serviceable, MailProcessor, 
MailetContainer {
 
     private static final Random random = new Random();  // Used to generate 
new mail names
 
@@ -693,5 +695,29 @@
         setMailetLoader((MailetLoader) comp.lookup(MailetLoader.ROLE));
         setMatchLoader((MatcherLoader) comp.lookup(MatcherLoader.ROLE));
         setSpool( (SpoolRepository) comp.lookup(SpoolRepository.ROLE));
+    }
+
+    public List getMailetConfigs() {
+        List mailetConfigs = new ArrayList();
+        Iterator iterator = mailets.iterator();
+        while (iterator.hasNext()) {
+            Mailet mailet = (Mailet) iterator.next();
+            MailetConfig mailetConfig = mailet.getMailetConfig();
+            if (mailetConfig == null) mailetConfigs.add(new 
MailetConfigImpl()); // placeholder
+            else mailetConfigs.add(mailetConfig);
+        }
+        return mailetConfigs;
+    }
+
+    public List getMatcherConfigs() {
+        List matcherConfigs = new ArrayList();
+        Iterator iterator = matchers.iterator();
+        while (iterator.hasNext()) {
+            Matcher matcher = (Matcher) iterator.next();
+            MatcherConfig matcherConfig = matcher.getMatcherConfig();
+            if (matcherConfig == null) matcherConfigs.add(new 
MatcherConfigImpl()); // placeholder
+            else matcherConfigs.add(matcherConfig);
+        }
+        return matcherConfigs;
     }
 }

Added: 
james/server/trunk/src/java/org/apache/james/transport/MailetContainer.java
URL: 
http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/transport/MailetContainer.java?view=auto&rev=468878
==============================================================================
--- james/server/trunk/src/java/org/apache/james/transport/MailetContainer.java 
(added)
+++ james/server/trunk/src/java/org/apache/james/transport/MailetContainer.java 
Sun Oct 29 02:56:32 2006
@@ -0,0 +1,57 @@
+/****************************************************************
+ * 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.transport;
+
+import java.util.List;
+
+import org.apache.james.services.MailetLoader;
+import org.apache.james.services.MatcherLoader;
+
+/**
+ * interface for mailet/matcher-containing processors.
+ */
+public interface MailetContainer {
+
+    /**
+     * Set the MailetLoader
+     * 
+     * @param mailetLoader the MailetLoader
+     */
+    void setMailetLoader(MailetLoader mailetLoader);
+
+    /**
+     * Set the MatcherLoader
+     * 
+     * @param matchLoader the MatcherLoader
+     */
+    void setMatchLoader(MatcherLoader matchLoader);
+
+    /**
+     * retrieve mailet configuration data for introspection
+     * @return List<MailetConfig>
+     */
+    List getMailetConfigs();
+
+    /**
+     * retrieve matcher configuration data for introspection
+     * @return List<MatcherConfig>
+     */
+    List getMatcherConfigs();
+
+}

Added: james/server/trunk/src/java/org/apache/james/transport/ProcessorList.java
URL: 
http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/transport/ProcessorList.java?view=auto&rev=468878
==============================================================================
--- james/server/trunk/src/java/org/apache/james/transport/ProcessorList.java 
(added)
+++ james/server/trunk/src/java/org/apache/james/transport/ProcessorList.java 
Sun Oct 29 02:56:32 2006
@@ -0,0 +1,38 @@
+/****************************************************************
+ * 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.transport;
+
+import org.apache.james.services.MailProcessor;
+
+/**
+ * provide access on child processor
+ */
+public interface ProcessorList {
+
+    /**
+     * @return names of all configured processor
+     */
+    String[] getProcessorNames();
+
+    /**
+     * @return access the child processor
+     */
+    MailProcessor getProcessor(String name);
+
+}

Modified: 
james/server/trunk/src/java/org/apache/james/transport/StateAwareProcessorList.java
URL: 
http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/transport/StateAwareProcessorList.java?view=diff&rev=468878&r1=468877&r2=468878
==============================================================================
--- 
james/server/trunk/src/java/org/apache/james/transport/StateAwareProcessorList.java
 (original)
+++ 
james/server/trunk/src/java/org/apache/james/transport/StateAwareProcessorList.java
 Sun Oct 29 02:56:32 2006
@@ -47,7 +47,7 @@
  */
 public class StateAwareProcessorList
     extends AbstractLogEnabled
-    implements Serviceable, Configurable, Initializable, Disposable, 
MailProcessor {
+    implements Serviceable, Configurable, Initializable, Disposable, 
MailProcessor, ProcessorList {
 
     /**
      * System component manager
@@ -234,6 +234,17 @@
             ContainerUtil.dispose(processor);
             processors.remove(processor);
         }
+    }
+
+    /**
+     * @return names of all configured processors
+     */
+    public String[] getProcessorNames() {
+        return (String[]) processors.keySet().toArray(new String[]{});
+    }
+
+    public MailProcessor getProcessor(String name) {
+        return (MailProcessor) processors.get(name);
     }
 
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to