james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From se...@apache.org
Subject cvs commit: jakarta-james/proposals/noparse-mimemessage/java/org/apache/james/mailrepository MimeMessageJDBCSource.java JDBCSpoolRepository.java JDBCMailRepository.java
Date Sun, 01 Jul 2001 12:58:15 GMT
serge       01/07/01 05:58:15

  Modified:    proposals/noparse-mimemessage/java/org/apache/james/mailrepository
                        MimeMessageJDBCSource.java JDBCSpoolRepository.java
                        JDBCMailRepository.java
  Log:
  Reimplemented spooling code to be more optimized (hopefully doesn't return entire list of
messages... does so iteratively).  Also commented out various debug code.
  
  Revision  Changes    Path
  1.2       +6 -4      jakarta-james/proposals/noparse-mimemessage/java/org/apache/james/mailrepository/MimeMessageJDBCSource.java
  
  Index: MimeMessageJDBCSource.java
  ===================================================================
  RCS file: /home/cvs/jakarta-james/proposals/noparse-mimemessage/java/org/apache/james/mailrepository/MimeMessageJDBCSource.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- MimeMessageJDBCSource.java	2001/06/27 04:34:23	1.1
  +++ MimeMessageJDBCSource.java	2001/07/01 12:58:15	1.2
  @@ -57,10 +57,6 @@
               PreparedStatement retrieveMessageStream = conn.prepareStatement(retrieveMessageStreamSQL);
               retrieveMessageStream.setString(1, key);
               retrieveMessageStream.setString(2, repository.repositoryName);
  -            //System.err.println(retrieveMessageStream);
  -            //System.err.println(retrieveMessageStreamSQL);
  -            //System.err.println("'" + key + "'");
  -            //System.err.println("'" + repository.repositoryName + "'");
               ResultSet rsRetrieveMessageStream = retrieveMessageStream.executeQuery();
   
               if (!rsRetrieveMessageStream.next()) {
  @@ -83,6 +79,12 @@
               */
           }
       }
  +    /*
  +    public synchronized long getSize() throws IOException {
  +        //Would like to implement using BLOBs
  +
  +    }
  +    */
   
       public boolean equals(Object obj) {
           if (obj instanceof MimeMessageJDBCSource) {
  
  
  
  1.2       +55 -27    jakarta-james/proposals/noparse-mimemessage/java/org/apache/james/mailrepository/JDBCSpoolRepository.java
  
  Index: JDBCSpoolRepository.java
  ===================================================================
  RCS file: /home/cvs/jakarta-james/proposals/noparse-mimemessage/java/org/apache/james/mailrepository/JDBCSpoolRepository.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- JDBCSpoolRepository.java	2001/06/27 04:34:23	1.1
  +++ JDBCSpoolRepository.java	2001/07/01 12:58:15	1.2
  @@ -64,15 +64,30 @@
   
       public synchronized String accept() {
           while (true) {
  -            System.err.println("calling accept");
  -            for(Iterator it = list(); it.hasNext(); ) {
  -                Object o = it.next();
  -                if (lock.lock(o)) {
  -                    return o.toString();
  +            try {
  +                Connection conn = getConnection();
  +                PreparedStatement listMessages = conn.prepareStatement(listMessagesSQL);
  +                listMessages.setString(1, repositoryName);
  +                ResultSet rsListMessages = listMessages.executeQuery();
  +
  +                while (rsListMessages.next()) {
  +                    String message = rsListMessages.getString(1);
  +
  +                    if (lock.lock(message)) {
  +                        rsListMessages.close();
  +                        listMessages.close();
  +                        conn.close();
  +                        return message;
  +                    }
                   }
  +                rsListMessages.close();
  +                listMessages.close();
  +                conn.close();
  +            } catch (Exception me) {
  +                me.printStackTrace();
  +                throw new RuntimeException("Exception while listing mail: " + me.getMessage());
               }
               try {
  -                System.out.println("waiting for " + this);
                   wait();
               } catch (InterruptedException ignored) {
               }
  @@ -81,43 +96,56 @@
   
       public synchronized String accept(long delay) {
           while (true) {
  -            long youngest = 0;
  -            //Really unoptimized query here... should be much smart about this...
  -            for (Iterator it = list(); it.hasNext(); ) {
  -                String s = it.next().toString();
  -                if (lock.lock(s)) {
  -                    //We have a lock on this object... let's grab the message
  -                    //  and see if it's a valid time.
  -                    MailImpl mail = retrieve(s);
  -                    if (mail.getState().equals(Mail.ERROR)) {
  -                        //Test the time...
  -                        long timeToProcess = delay + mail.getLastUpdated().getTime();
  +            long next = 0;
  +            try {
  +                Connection conn = getConnection();
  +                PreparedStatement listMessages = conn.prepareStatement(listMessagesSQL);
  +                listMessages.setString(1, repositoryName);
  +                ResultSet rsListMessages = listMessages.executeQuery();
  +
  +                while (rsListMessages.next()) {
  +                    String message = rsListMessages.getString(1);
  +                    String state = rsListMessages.getString(2);
  +                    boolean process = false;
  +                    if (state.equals(Mail.ERROR)) {
  +                        //Test the time
  +                        long timeToProcess = delay + rsListMessages.getDate(3).getTime();
                           if (System.currentTimeMillis() > timeToProcess) {
  -                            //We're ready to process this again
  -                            return s;
  +                            process = true;
                           } else {
  -                            //We're not ready to process this.
  -                            if (youngest == 0 || youngest > timeToProcess) {
  +                            if (next == 0 || next > timeToProcess) {
                                   //Mark this as the next most likely possible mail to process
  -                                youngest = timeToProcess;
  +                                next = timeToProcess;
                               }
                           }
                       } else {
  -                        //This guy is good to go... return him
  -                        return s;
  +                        process = true;
  +                    }
  +
  +                    if (process && lock.lock(message)) {
  +                        rsListMessages.close();
  +                        listMessages.close();
  +                        conn.close();
  +                        return message;
                       }
                   }
  +                rsListMessages.close();
  +                listMessages.close();
  +                conn.close();
  +            } catch (Exception me) {
  +                me.printStackTrace();
  +                throw new RuntimeException("Exception while listing mail: " + me.getMessage());
               }
  +
               //We did not find any... let's wait for a certain amount of time
               try {
  -                if (youngest == 0) {
  +                if (next == 0) {
                       wait();
                   } else {
  -                    wait(youngest - System.currentTimeMillis());
  +                    wait(next - System.currentTimeMillis());
                   }
               } catch (InterruptedException ignored) {
               }
  -            System.err.println("done waiting in long accept");
           }
       }
   }
  
  
  
  1.2       +24 -29    jakarta-james/proposals/noparse-mimemessage/java/org/apache/james/mailrepository/JDBCMailRepository.java
  
  Index: JDBCMailRepository.java
  ===================================================================
  RCS file: /home/cvs/jakarta-james/proposals/noparse-mimemessage/java/org/apache/james/mailrepository/JDBCMailRepository.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- JDBCMailRepository.java	2001/06/27 04:34:23	1.1
  +++ JDBCMailRepository.java	2001/07/01 12:58:15	1.2
  @@ -45,18 +45,13 @@
    * Implementation of a MailRepository on a database.
    *
    * <p>Requires a configuration element in the .conf.xml file of the form:
  - *  <br><repository destinationURL="town://path"
  + *  <br><repository destinationURL="db://<datasource>/<repository_name>"
    *  <br>            type="MAIL"
    *  <br>            model="SYNCHRONOUS"/>
  - *  <br>            <driver>sun.jdbc.odbc.JdbcOdbcDriver</conn>
  - *  <br>            <conn>jdbc:odbc:LocalDB</conn>
  - *  <br>            <table>Message</table>
    *  <br></repository>
    * <p>destinationURL specifies..(Serge??)
    * <br>Type can be SPOOL or MAIL
    * <br>Model is currently not used and may be dropped
  - * <br>conn is the location of the ...(Serge)
  - * <br>table is the name of the table in the Database to be used
    *
    * <p>Requires a logger called MailRepository.
    *
  @@ -67,7 +62,7 @@
       extends AbstractLoggable
       implements MailRepository, Component, Configurable, Composable {
   
  -    private SimpleDateFormat sqlFormat = new SimpleDateFormat("yyyy MMM dd h:mm:ss a");
  +    //private SimpleDateFormat sqlFormat = new SimpleDateFormat("yyyy MMM dd h:mm:ss a");
   
       protected Lock lock;
       protected String destination;
  @@ -77,35 +72,36 @@
       //The table where this is stored
       private String driverClassName = "com.inet.tds.TdsDriver";
       protected String jdbcURL = "jdbc:inetdae7:127.0.0.1?database=James";
  -    protected String jdbcUsername = "sa";   //optional
  -    protected String jdbcPassword = "rufus4811";    //optional
  +    protected String jdbcUsername = "sa_james";   //optional
  +    protected String jdbcPassword = "blahblah";    //optional
   
   
  -    private String checkMessageExistsSQL =
  +    protected String checkMessageExistsSQL =
               "SELECT count(*) FROM " + tableName + " WHERE message_name = ? AND repository_name
= ?";
   
  -    private String updateMessageSQL =
  +    protected String updateMessageSQL =
               "UPDATE " + tableName + " SET message_state = ?, error_message = ?, sender
= ?, recipients = ?, "
               + "remote_host = ?, remote_addr = ?, last_updated = ? "
               + "WHERE message_name = ? AND repository_name = ?";
   
  -    private String updateMessageBodySQL =
  +    protected String updateMessageBodySQL =
               "UPDATE " + tableName + " SET message_body = ? WHERE message_name = ? AND repository_name
= ?";
   
  -    private String insertMessageSQL =
  +    protected String insertMessageSQL =
               "INSERT INTO " + tableName + " (message_name, repository_name, message_state,
"
               + "error_message, sender, recipients, remote_host, remote_addr, last_updated,
message_body) "
               + "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
   
  -    private String retrieveMessageSQL =
  +    protected String retrieveMessageSQL =
               "SELECT message_state, error_message, sender, recipients, remote_host, remote_addr,
last_updated "
               + "FROM " + tableName + " WHERE message_name = ? AND repository_name = ?";
   
  -    private String removeMessageSQL =
  +    protected String removeMessageSQL =
               "DELETE FROM " + tableName + " WHERE message_name = ? AND repository_name =
?";
   
  -    private String listMessagesSQL =
  -            "SELECT message_name FROM " + tableName + " WHERE repository_name = ? ORDER
BY last_updated ASC";
  +    protected String listMessagesSQL =
  +            "SELECT message_name, message_state, last_updated FROM " + tableName
  +            + " WHERE repository_name = ? ORDER BY last_updated ASC";
   
       public void configure(Configuration conf) throws ConfigurationException {
           destination = conf.getAttribute("destinationURL");
  @@ -131,8 +127,6 @@
               getLogger().error(message);
               throw new ConfigurationException(message);
           }
  -        //lock = new Lock();
  -        System.err.println("jdbc spool initialized for " + repositoryName);
       }
   
       public void compose( final ComponentManager componentManager )
  @@ -186,7 +180,7 @@
       }
   
       public void store(MailImpl mc) {
  -        System.err.println("storing " + mc.getName());
  +        //System.err.println("storing " + mc.getName());
           try {
               Connection conn = getConnection();
   
  @@ -239,7 +233,8 @@
                   if (saveBody) {
                       updateMessage = conn.prepareStatement(updateMessageBodySQL);
                       int size = (int)messageBody.getSize();
  -                    updateMessage.setBinaryStream(1, new DebugInputStream(messageBody.getInputStream()),
size);
  +                    updateMessage.setBinaryStream(1, messageBody.getInputStream(), size);
  +                    //updateMessage.setBinaryStream(1, new DebugInputStream(messageBody.getInputStream()),
size);
                       updateMessage.setString(2, mc.getName());
                       updateMessage.setString(3, repositoryName);
                       updateMessage.execute();
  @@ -263,13 +258,14 @@
                   insertMessage.setString(6, recipients.toString());
                   insertMessage.setString(7, mc.getRemoteHost());
                   insertMessage.setString(8, mc.getRemoteAddr());
  -                //java.sql.Date lastUpdated = new java.sql.Date(mc.getLastUpdated().getTime());
  +                java.sql.Date lastUpdated = new java.sql.Date(mc.getLastUpdated().getTime());
                   //System.err.println(lastUpdated);
  -                //insertMessage.setDate(9, lastUpdated);
  -                insertMessage.setString(9, sqlFormat.format(mc.getLastUpdated()));
  +                insertMessage.setDate(9, lastUpdated);
  +                //insertMessage.setString(9, sqlFormat.format(mc.getLastUpdated()));
                   MimeMessage messageBody = mc.getMessage();
                   int size = messageBody.getSize();
  -                insertMessage.setBinaryStream(10, new DebugInputStream(messageBody.getInputStream()),
size);
  +                insertMessage.setBinaryStream(10, messageBody.getInputStream(), size);
  +                //insertMessage.setBinaryStream(10, new DebugInputStream(messageBody.getInputStream()),
size);
                   insertMessage.execute();
                   insertMessage.close();
               }
  @@ -279,7 +275,6 @@
               conn.close();
   
               synchronized (this) {
  -                System.err.println("everything is notified on " + this);
                   notifyAll();
               }
           } catch (Exception e) {
  @@ -289,7 +284,7 @@
       }
   
       public MailImpl retrieve(String key) {
  -        System.err.println("retrieving " + key);
  +        //System.err.println("retrieving " + key);
           try {
               Connection conn = getConnection();
   
  @@ -345,7 +340,7 @@
       }
   
       public void remove(String key) {
  -        System.err.println("removing " + key);
  +        //System.err.println("removing " + key);
           try {
               lock(key);
   
  @@ -364,7 +359,7 @@
       }
   
       public Iterator list() {
  -        System.err.println("listing messages");
  +        //System.err.println("listing messages");
           try {
               Connection conn = getConnection();
               PreparedStatement listMessages = conn.prepareStatement(listMessagesSQL);
  
  
  

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


Mime
View raw message