Hi,

I think the stat() method in the POP3Server.java can be made to work
faster by storing the message names in the userMailbox Vector instead of
the MailImpl; you don't have to do a retrieve() from the mail
repository, which means that there would be lesser number of database
connections used (of course, this implies that there would be a quite lot 
of modification in the rest of the code).

    private void stat() {
        userMailbox = new Vector();
        userMailbox.add(DELETED);
        Iterator i = userInbox.list();
        if (i != null) {
            for (;i.hasNext();) {
                String key = (String) i.next();
                userMailbox.addElement(key);
            }
        }
        backupUserMailbox = (Vector) userMailbox.clone();
    }

Adding some methods in the MailRepository interface would be nicer too. In
the following, I implemented getMessageSize(Vector) method to get the
total size of messages in a particular user's mailbox. The SQL statement
would be: select sum(length(message_body)) from Message where ...

   private void doSTAT(String command,String argument,String argument1) {
        if (state == TRANSACTION) {
            long size = 0;
            int count = 0;
            String key;
            Vector keys = new Vector();
            for (Iterator i = userMailbox.iterator(); i.hasNext();) {
                if (!(key = (String) i.next()).equals(DELETED)) {
                    keys.add(key);
                    count++;
                } 
            }
            try {
                size = userInbox.getMessageSize(keys);
                out.println(OK_RESPONSE + " " + count + " " + size);

The following are some of the methods I added in MailRepository interface:
    // Returns message size; the total size of a particular mailbox
    int getMessageSize(Vector keys) throws MessagingException;

    // Return message size; the size of an individual message
    int getMessageSize(String key) throws MessagingException;

    // Returns message name and its size pairs; it's implementation
    // made faster by opening a connection once, and then doing a loop
    // for getting each size of the message (using length(message_body)).
    Hashtable getMessageSizeList(Vector keys) throws MessagingException;

Those are useful to speedup the performance of the POP server by
implementing specific calls to the database directly. The modified
interface would mean a lot for other repositories though (eg: the file
repository); ie: lots of modifications.

Just some ideas of improvement,
Oki




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

Reply via email to