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 pg...@apache.org on 2002/08/18 09:23:55 UTC

cvs commit: jakarta-james/src/java/org/apache/james/mailrepository package.html AvalonMailRepository.java AvalonSpoolRepository.java JDBCMailRepository.java MimeMessageAvalonSource.java MimeMessageJDBCSource.java

pgoldstein    2002/08/18 00:23:55

  Modified:    src/java/org/apache/james/mailrepository
                        AvalonMailRepository.java
                        AvalonSpoolRepository.java JDBCMailRepository.java
                        MimeMessageAvalonSource.java
                        MimeMessageJDBCSource.java
  Added:       src/java/org/apache/james/mailrepository package.html
  Log:
  Added extensive commenting.
  Adding DEEP_DEBUG log entries to lock/unlock - thanks to Noel Bergman
  
  Revision  Changes    Path
  1.17      +92 -4     jakarta-james/src/java/org/apache/james/mailrepository/AvalonMailRepository.java
  
  Index: AvalonMailRepository.java
  ===================================================================
  RCS file: /home/cvs/jakarta-james/src/java/org/apache/james/mailrepository/AvalonMailRepository.java,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- AvalonMailRepository.java	7 Aug 2002 23:32:14 -0000	1.16
  +++ AvalonMailRepository.java	18 Aug 2002 07:23:55 -0000	1.17
  @@ -46,9 +46,10 @@
       extends AbstractLogEnabled
       implements MailRepository, Component, Configurable, Composable, Initializable {
   
  -    private Lock lock;
       protected final static boolean DEEP_DEBUG = false;
       private static final String TYPE = "MAIL";
  +
  +    private Lock lock;
       private Store store;
       private StreamRepository sr;
       private ObjectRepository or;
  @@ -56,6 +57,12 @@
       private String destination;
       private Set keys;
   
  +    /**
  +     * Pass the <code>Configuration</code> to the instance.
  +     *
  +     * @param configuration the class configurations.
  +     * @throws ConfigurationException if an error occurs
  +     */
       public void configure(Configuration conf) throws ConfigurationException {
           destination = conf.getAttribute("destinationURL");
           if (getLogger().isDebugEnabled()) {
  @@ -73,12 +80,28 @@
           // ignore model
       }
   
  +    /**
  +     * Pass the <code>ComponentManager</code> to the <code>composer</code>.
  +     * The instance uses the specified <code>ComponentManager</code> to 
  +     * acquire the components it needs for execution.
  +     *
  +     * @param componentManager The <code>ComponentManager</code> which this
  +     *                <code>Composable</code> uses.
  +     * @throws ComponentException if an error occurs
  +     */
       public void compose( final ComponentManager componentManager )
               throws ComponentException {
           store = (Store)componentManager.
  -            lookup( "org.apache.avalon.cornerstone.services.store.Store" );
  +        lookup( "org.apache.avalon.cornerstone.services.store.Store" );
       }
   
  +    /**
  +     * Initialize the component. Initialization includes
  +     * allocating any resources required throughout the
  +     * components lifecycle.
  +     *
  +     * @throws Exception if an error occurs
  +     */
       public void initialize()
               throws Exception {
           try {
  @@ -150,8 +173,26 @@
           }
       }
   
  +    /**
  +     * Releases a lock on a message identified the key
  +     *
  +     * @param key the key of the message to be unlocked
  +     *
  +     * @return true if successfully released the lock, false otherwise
  +     */
       public boolean unlock(String key) {
           if (lock.unlock(key)) {
  +            if ((DEEP_DEBUG) && (getLogger().isDebugEnabled())) {
  +                StringBuffer debugBuffer =
  +                    new StringBuffer(256)
  +                            .append("Unlocked ")
  +                            .append(key)
  +                            .append(" for ")
  +                            .append(Thread.currentThread().getName())
  +                            .append(" @ ")
  +                            .append(new java.util.Date(System.currentTimeMillis()));
  +                getLogger().debug(debugBuffer.toString());
  +            }
               synchronized (this) {
                   notifyAll();
               }
  @@ -161,8 +202,26 @@
           }
       }
   
  +    /**
  +     * Obtains a lock on a message identified by key
  +     *
  +     * @param key the key of the message to be locked
  +     *
  +     * @return true if successfully obtained the lock, false otherwise
  +     */
       public boolean lock(String key) {
           if (lock.lock(key)) {
  +            if ((DEEP_DEBUG) && (getLogger().isDebugEnabled())) {
  +                StringBuffer debugBuffer =
  +                    new StringBuffer(256)
  +                            .append("Locked ")
  +                            .append(key)
  +                            .append(" for ")
  +                            .append(Thread.currentThread().getName())
  +                            .append(" @ ")
  +                            .append(new java.util.Date(System.currentTimeMillis()));
  +                getLogger().debug(debugBuffer.toString());
  +            }
               synchronized (this) {
                   notifyAll();
               }
  @@ -172,6 +231,12 @@
           }
       }
   
  +    /**
  +     * Stores a message in this repository. Shouldn't this return the key
  +     * under which it is stored?
  +     *
  +     * @param mc the mail message to store
  +     */
       public void store(MailImpl mc) {
           try {
               String key = mc.getName();
  @@ -250,6 +315,13 @@
           }
       }
   
  +    /**
  +     * Retrieves a message given a key. At the moment, keys can be obtained
  +     * from list() in superinterface Store.Repository
  +     *
  +     * @param key the key of the message to retrieve
  +     * @return the mail corresponding to this key, null if none exists
  +     */
       public MailImpl retrieve(String key) {
           if ((DEEP_DEBUG) && (getLogger().isDebugEnabled())) {
               getLogger().debug("Retrieving mail: " + key);
  @@ -278,10 +350,20 @@
           }
       }
   
  +    /**
  +     * Removes a specified message
  +     *
  +     * @param mail the message to be removed from the repository
  +     */
       public void remove(MailImpl mail) {
           remove(mail.getName());
       }
   
  +    /**
  +     * Removes a message identified by key.
  +     *
  +     * @param key the key of the message to be removed from the repository
  +     */
       public void remove(String key) {
           if (lock(key)) {
               try {
  @@ -301,9 +383,15 @@
           }
       }
   
  +    /**
  +     * List string keys of messages in repository.
  +     *
  +     * @return an <code>Iterator</code> over the list of keys in the repository
  +     *
  +     */
       public Iterator list() {
  -//  Fix ConcurrentModificationException by cloning the keyset before getting an iterator
  -//        return keys.iterator();
  +        // Fix ConcurrentModificationException by cloning 
  +        // the keyset before getting an iterator
           final HashSet clone = new HashSet();
           clone.addAll( keys );
           return clone.iterator();
  
  
  
  1.7       +27 -1     jakarta-james/src/java/org/apache/james/mailrepository/AvalonSpoolRepository.java
  
  Index: AvalonSpoolRepository.java
  ===================================================================
  RCS file: /home/cvs/jakarta-james/src/java/org/apache/james/mailrepository/AvalonSpoolRepository.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- AvalonSpoolRepository.java	7 Aug 2002 23:32:14 -0000	1.6
  +++ AvalonSpoolRepository.java	18 Aug 2002 07:23:55 -0000	1.7
  @@ -31,6 +31,15 @@
       extends AvalonMailRepository
       implements SpoolRepository {
   
  +    /**
  +     * <p>Returns the key for an arbitrarily selected mail deposited in this Repository.
  +     * Usage: SpoolManager calls accept() to see if there are any unprocessed 
  +     * mails in the spool repository.</p>
  +     *
  +     * <p>Synchronized to ensure thread safe access to the underlying spool.</p>
  +     *
  +     * @return the key for the mail
  +     */
       public synchronized String accept() {
           if ((DEEP_DEBUG) && (getLogger().isDebugEnabled())) {
               getLogger().debug("Method accept() called");
  @@ -64,6 +73,17 @@
           }
       }
   
  +    /**
  +     * <p>Returns the key for an arbitrarily selected mail deposited in this Repository that
  +     * is either ready immediately for delivery, or is younger than it's last_updated plus
  +     * the number of failed attempts times the delay time.
  +     * Usage: RemoteDeliverySpool calls accept() with some delay and should block until an
  +     * unprocessed mail is available.</p>
  +     *
  +     * <p>Synchronized to ensure thread safe access to the underlying spool.</p>
  +     *
  +     * @return the key for the mail
  +     */
       public synchronized String accept(long delay) {
           if ((DEEP_DEBUG) && (getLogger().isDebugEnabled())) {
               getLogger().debug("Method accept(delay) called");
  @@ -86,7 +106,13 @@
                       }
                       //We have a lock on this object... let's grab the message
                       //  and see if it's a valid time.
  +
  +                    // Retrieve can return null if the mail is no longer in the store.
  +                    // In this case we simply continue to the next key
                       MailImpl mail = retrieve(s);
  +                    if (mail == null) {
  +                        continue;
  +                    }
                       if (mail.getState().equals(Mail.ERROR)) {
                           //Test the time...
                           long timeToProcess = delay + mail.getLastUpdated().getTime();
  @@ -117,6 +143,6 @@
               } catch (ConcurrentModificationException ignoredAlso) {
                  // Should never get here now that list methods clones keyset for iterator
               }
  -}
  +        }
       }
   }
  
  
  
  1.23      +56 -3     jakarta-james/src/java/org/apache/james/mailrepository/JDBCMailRepository.java
  
  Index: JDBCMailRepository.java
  ===================================================================
  RCS file: /home/cvs/jakarta-james/src/java/org/apache/james/mailrepository/JDBCMailRepository.java,v
  retrieving revision 1.22
  retrieving revision 1.23
  diff -u -r1.22 -r1.23
  --- JDBCMailRepository.java	14 Aug 2002 02:11:00 -0000	1.22
  +++ JDBCMailRepository.java	18 Aug 2002 07:23:55 -0000	1.23
  @@ -66,7 +66,11 @@
       private static final boolean DEEP_DEBUG = false;
   
   
  +    /**
  +     * The Avalon context used by the instance
  +     */
       protected Context context;
  +
       private Lock lock;
   
       // Configuration elements
  @@ -83,17 +87,35 @@
       protected DataSourceComponent datasource;
       protected String datasourceName;
   
  -    // Contains all of the sql strings for this component.
  +    /**
  +     * Contains all of the sql strings for this component.
  +     */
       protected SqlResources sqlQueries;
   
  -    // The JDBCUtil helper class
  +    /**
  +     * The JDBCUtil helper class
  +     */
       protected JDBCUtil theJDBCUtil;
   
  +    /**
  +     * Pass the Context to the component.
  +     * This method is called after the setLogger()
  +     * method and before any other method.
  +     *
  +     * @param context the context
  +     * @throws ContextException if context is invalid
  +     */
       public void contextualize(final Context context)
               throws ContextException {
           this.context = context;
       }
   
  +    /**
  +     * Pass the <code>Configuration</code> to the instance.
  +     *
  +     * @param configuration the class configurations.
  +     * @throws ConfigurationException if an error occurs
  +     */
       public void configure(Configuration conf) throws ConfigurationException {
           if (getLogger().isDebugEnabled()) {
               getLogger().debug(this.getClass().getName() + ".configure()");
  @@ -164,6 +186,15 @@
           }
       }
   
  +    /**
  +     * Pass the <code>ComponentManager</code> to the <code>composer</code>.
  +     * The instance uses the specified <code>ComponentManager</code> to 
  +     * acquire the components it needs for execution.
  +     *
  +     * @param componentManager The <code>ComponentManager</code> which this
  +     *                <code>Composable</code> uses.
  +     * @throws ComponentException if an error occurs
  +     */
       public void compose( final ComponentManager componentManager )
           throws ComponentException {
           StringBuffer logBuffer = null;
  @@ -222,6 +253,7 @@
        *     and performing paramter substitution,
        * 3) Initialises the database with the required tables, if necessary.
        *
  +     * @throws Exception if an error occurs
        */
       public void initialize() throws Exception {
           StringBuffer logBuffer = null;
  @@ -321,6 +353,17 @@
   
       public synchronized boolean unlock(String key) {
           if (lock.unlock(key)) {
  +            if ((DEEP_DEBUG) && (getLogger().isDebugEnabled())) {
  +                StringBuffer debugBuffer =
  +                    new StringBuffer(256)
  +                            .append("Unlocked ")
  +                            .append(key)
  +                            .append(" for ")
  +                            .append(Thread.currentThread().getName())
  +                            .append(" @ ")
  +                            .append(new java.util.Date(System.currentTimeMillis()));
  +                getLogger().debug(debugBuffer.toString());
  +            }
               notifyAll();
               return true;
           } else {
  @@ -330,7 +373,17 @@
   
       public synchronized boolean lock(String key) {
           if (lock.lock(key)) {
  -            //notifyAll();
  +            if ((DEEP_DEBUG) && (getLogger().isDebugEnabled())) {
  +                StringBuffer debugBuffer =
  +                    new StringBuffer(256)
  +                            .append("Locked ")
  +                            .append(key)
  +                            .append(" for ")
  +                            .append(Thread.currentThread().getName())
  +                            .append(" @ ")
  +                            .append(new java.util.Date(System.currentTimeMillis()));
  +                getLogger().debug(debugBuffer.toString());
  +            }
               return true;
           } else {
               return false;
  
  
  
  1.5       +20 -0     jakarta-james/src/java/org/apache/james/mailrepository/MimeMessageAvalonSource.java
  
  Index: MimeMessageAvalonSource.java
  ===================================================================
  RCS file: /home/cvs/jakarta-james/src/java/org/apache/james/mailrepository/MimeMessageAvalonSource.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- MimeMessageAvalonSource.java	7 Aug 2002 23:32:14 -0000	1.4
  +++ MimeMessageAvalonSource.java	18 Aug 2002 07:23:55 -0000	1.5
  @@ -16,8 +16,21 @@
   public class MimeMessageAvalonSource extends MimeMessageSource {
   
       //Define how to get to the data
  +    
  +    /**
  +     * The stream repository used by this data source.
  +     */
       StreamRepository sr = null;
  +
  +    /**
  +     * The name of the repository
  +     */
       String repositoryName = null;
  +
  +    /**
  +     * The key for the particular stream in the stream repository
  +     * to be used by this data source.
  +     */
       String key = null;
   
       public MimeMessageAvalonSource(StreamRepository sr, String repositoryName, String key) {
  @@ -26,6 +39,13 @@
           this.key = key;
       }
   
  +    /**
  +     * Returns a unique String ID that represents the location from where 
  +     * this source is loaded.  This will be used to identify where the data 
  +     * is, primarily to avoid situations where this data would get overwritten.
  +     *
  +     * @return the String ID
  +     */
       public String getSourceId() {
           StringBuffer sourceIdBuffer =
               new StringBuffer(128)
  
  
  
  1.9       +17 -1     jakarta-james/src/java/org/apache/james/mailrepository/MimeMessageJDBCSource.java
  
  Index: MimeMessageJDBCSource.java
  ===================================================================
  RCS file: /home/cvs/jakarta-james/src/java/org/apache/james/mailrepository/MimeMessageJDBCSource.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- MimeMessageJDBCSource.java	12 Aug 2002 07:41:36 -0000	1.8
  +++ MimeMessageJDBCSource.java	18 Aug 2002 07:23:55 -0000	1.9
  @@ -33,10 +33,19 @@
       String key = null;
       StreamRepository sr = null;
   
  +    /**
  +     * SQL used to retrieve the message body
  +     */
       String retrieveMessageBodySQL = null;
  +
  +    /**
  +     * SQL used to retrieve the size of the message body
  +     */
       String retrieveMessageBodySizeSQL = null;
   
  -    // The JDBCUtil helper class
  +    /**
  +     * The JDBCUtil helper class
  +     */
       private static final JDBCUtil theJDBCUtil =
               new JDBCUtil() {
                   protected void delegatedLog(String logString) {
  @@ -68,6 +77,13 @@
               repository.sqlQueries.getSqlString("retrieveMessageBodySizeSQL");
       }
   
  +    /**
  +     * Returns a unique String ID that represents the location from where 
  +     * this source is loaded.  This will be used to identify where the data 
  +     * is, primarily to avoid situations where this data would get overwritten.
  +     *
  +     * @return the String ID
  +     */
       public String getSourceId() {
           StringBuffer sourceIdBuffer =
               new StringBuffer(128)
  
  
  
  1.1                  jakarta-james/src/java/org/apache/james/mailrepository/package.html
  
  Index: package.html
  ===================================================================
  <body>
  <p>Implementations of mail repositories for use in James.</p>
  </body>
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>