Class FileMailQueue

  extended bySK.gnome.dwarf.GenericService
      extended bySK.gnome.dwarf.thread.ThreadService
          extended bySK.gnome.dwarf.mail.smtp.FileMailQueue
All Implemented Interfaces:
MailQueue, java.lang.Runnable, SK.gnome.dwarf.Service

public class FileMailQueue
extends SK.gnome.dwarf.thread.ThreadService
implements MailQueue

Provides filesystem-based mail queue.

The queue is stored in a special directory which must be set via the setQueueDir(File) method. It contains two subdirectories "msgs" and "nodes". The first one stores messages and the second one node queues. Each message is represented by a subdirectory with name equal to the message's SMTP identification string. (Subdirectories starting with dot are regarded temporary and deleted automatically after some time.) Each subdirectory contains serialized form of the SMTP envelope data in file named ".control" and the raw message data in file named ".message". In addition, there are one or more files with the serialized form of each message recipient named "", where xxxx is hexadecimal value of the hashed recipient's address.

The "nodes" subdirectory contains the scheduling information for all nodes, which are in fact domain names of all recipients of all messages in the queue. Each node is represented by a single subdirectory containing references to all messages enqueued for this particular node. A reference is a zero-length file with name "xxxxx-yyyyy-zzzzz", where the first part is message's SMTP identification string, the second part is Node identification used for enqueueing the message, and the third one is a time in milliseconds for which the message had been enqueued. Zero time means that the message should be dequeued as soon as possible, probably in the very next queue run.

If a message with SMTP id 123671263817_32398 is enqueued for delivery to "" by a Node with 1242482349_09312 id, for example, the "nodes/" subdirectory must contain a file named "123671263817_32398-1232482349_09312-1233074634323", where the last number is time after which message may be dequeued for further processing.

Note: since the serialized queue objects contains also paths to files, it is not safe to move the queue content to another location.

Field Summary
Fields inherited from class SK.gnome.dwarf.thread.ThreadService
daemon, thread
Fields inherited from class SK.gnome.dwarf.GenericService
initParameters, parent
Fields inherited from interface SK.gnome.dwarf.Service
Constructor Summary
FileMailQueue(java.lang.String name)
Method Summary
 SMTPMessage dequeueMessage(Node node)
          Dequeues a message for the given node.
protected  boolean enableThread()
 void enqueueMessage(SMTPMessage message, Node node, long time)
          Enqueues the message for the given node and time.
 SMTPMessage getMessageInstance()
          Returns a new SMTPMessage instance.
 void init(SK.gnome.dwarf.Server parent)
 void listMessages(boolean details, out)
          Lists all messages in the queue.
 java.util.Iterator listNodes()
          Lists all active nodes.
protected  void loop()
 void setDeleteFinished(boolean enable)
 void setCheckpoint(int time)
 void setQueueDir( dir)
Methods inherited from class SK.gnome.dwarf.thread.ThreadService
finish, run, setDaemon, shutdown, start, stop
Methods inherited from class SK.gnome.dwarf.GenericService
getAuthenticator, getAuthFacility, getFullName, getInitParameter, getInitParameterNames, getLogFacility, getLogger, getName, getParameters, getPrincipal, getShutdownTimeout, getState, log, log, login, logout, setAuthFacility, setInitParameters, setLogFacility, toString
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait

Constructor Detail


public FileMailQueue(java.lang.String name)
Method Detail


public void setQueueDir( dir)


public void setCheckpoint(int time)


public void setDeleteFinished(boolean enable)


public void init(SK.gnome.dwarf.Server parent)
          throws SK.gnome.dwarf.ServiceException
Specified by:
init in interface SK.gnome.dwarf.Service


public SMTPMessage getMessageInstance()
                               throws MailException
Description copied from interface: MailQueue
Returns a new SMTPMessage instance.

Specified by:
getMessageInstance in interface MailQueue
the new message instance
MailException - if an error occured


public void listMessages(boolean details,
                  throws MailException
Description copied from interface: MailQueue
Lists all messages in the queue.

A short or detailed information is printed out about each message waiting in the queue.

Specified by:
listMessages in interface MailQueue
details - true to print message details, false otherwise
out - the output stream
MailException - if an error occured


public void enqueueMessage(SMTPMessage message,
                           Node node,
                           long time)
                    throws MailException
Description copied from interface: MailQueue
Enqueues the message for the given node and time.

The message as well as its recipient collection are stored to the mail queue and may be returned later via the MailQueue.dequeueMessage(Node) method, if the recipients are targeted for the given node and other conditions are met, too. In other words, the message is scheduled to be processed for the given node at the specified time.

Specified by:
enqueueMessage in interface MailQueue
message - the message
node - the node to enqueue the message for
time - the time for next processing or delivery attempt
MailException - if an error occured


public SMTPMessage dequeueMessage(Node node)
                           throws MailException
Description copied from interface: MailQueue
Dequeues a message for the given node.

Only those messages may be returned which had been enqueued for the given node and time less or equal the current system time, unless the node's Node.getForceDelivery() returns true. Furthemore, messages which had been already processed for the same Node object previously must not be returned. A returned message's SMTPMessage.getRecipients() method may return only those recipients which are targeted for the given node. After dequeueing the recipients are removed from the queue processing and may be included in it again only by calling MailQueue.enqueueMessage(SMTPMessage, Node, long) on the same message object.

Specified by:
dequeueMessage in interface MailQueue
node - the node to dequeue a message for
the message or null if no message waits for the processing
MailException - if an error occured


public java.util.Iterator listNodes()
Description copied from interface: MailQueue
Lists all active nodes.

A node is active only if it contains any messages for processing. The returned iteration contains java.lang.String objects with the node names.

Specified by:
listNodes in interface MailQueue
the iteration of active nodes


protected boolean enableThread()


protected void loop()

Copyright (c) 2004-2005, Gnome Ltd. All rights reserved.