org.apache.geronimo.javamail.store.imap.connection
Class IMAPConnectionPool

java.lang.Object
  extended by org.apache.geronimo.javamail.store.imap.connection.IMAPConnectionPool

public class IMAPConnectionPool
extends Object


Field Summary
protected  String authid
           
protected  List availableConnections
           
protected  Map capabilities
           
protected  boolean closed
           
protected  boolean debug
           
protected  boolean dedicatedStoreConnection
           
protected static String DEFAULT_MAIL_HOST
           
protected static int DEFAULT_POOL_TIMEOUT
           
protected  String host
           
protected static String MAIL_AUTHORIZATIONID
           
protected static String MAIL_POOL_SIZE
           
protected static String MAIL_POOL_TIMEOUT
           
protected static String MAIL_PORT
           
protected static String MAIL_SASL_REALM
           
protected static String MAIL_SEPARATE_STORE_CONNECTION
           
protected static int MAX_CONNECTION_RETRIES
           
protected static int MAX_POOL_WAIT
           
protected  String password
           
protected  List poolConnections
           
protected  int poolSize
           
protected  long poolTimeout
           
protected  int port
           
protected  ProtocolProperties props
           
protected  String realm
           
protected  IMAPStore store
           
protected  IMAPConnection storeConnection
           
protected  String username
           
 
Constructor Summary
IMAPConnectionPool(IMAPStore store, ProtocolProperties props)
          Create a connection pool associated with a give IMAPStore instance.
 
Method Summary
 void close()
          Close the entire connection pool.
protected  void closeStaleConnections()
          Flush any connections from the pool that have not been used for at least the connection pool timeout interval.
protected  IMAPConnection createPoolConnection()
          Creates an authenticated pool connection and adds it to the connection pool.
protected  void freeAllConnections()
          Cleanup time.
protected  IMAPConnection getConnection()
          Get a connection from the pool.
 IMAPConnection getFolderConnection()
          Get a connection for Folder.
protected  IMAPConnection getPoolConnection()
          Obtain a connection from the existing connection pool.
 IMAPConnection getStoreConnection()
          Get a connection for the Store.
 boolean hasCapability(String capability)
          Test if this connection has a given capability.
 boolean protocolConnect(String host, int port, String username, String password)
          Manage the initial connection to the IMAP server.
protected  void releaseConnection(IMAPConnection connection)
          Return a connection back to the connection pool.
 void releaseFolderConnection(IMAPConnection connection)
          Return a Folder connection to the connection pool.
protected  void releasePoolConnection(IMAPConnection connection)
          Release a closed connection.
 void releaseStoreConnection(IMAPConnection connection)
          Return the Store connection to the connection pool.
protected  void returnPoolConnection(IMAPConnection connection)
          Return a connection to the connection pool.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MAIL_PORT

protected static final String MAIL_PORT
See Also:
Constant Field Values

MAIL_POOL_SIZE

protected static final String MAIL_POOL_SIZE
See Also:
Constant Field Values

MAIL_POOL_TIMEOUT

protected static final String MAIL_POOL_TIMEOUT
See Also:
Constant Field Values

MAIL_SEPARATE_STORE_CONNECTION

protected static final String MAIL_SEPARATE_STORE_CONNECTION
See Also:
Constant Field Values

MAIL_SASL_REALM

protected static final String MAIL_SASL_REALM
See Also:
Constant Field Values

MAIL_AUTHORIZATIONID

protected static final String MAIL_AUTHORIZATIONID
See Also:
Constant Field Values

DEFAULT_POOL_TIMEOUT

protected static final int DEFAULT_POOL_TIMEOUT
See Also:
Constant Field Values

DEFAULT_MAIL_HOST

protected static final String DEFAULT_MAIL_HOST
See Also:
Constant Field Values

MAX_CONNECTION_RETRIES

protected static final int MAX_CONNECTION_RETRIES
See Also:
Constant Field Values

MAX_POOL_WAIT

protected static final int MAX_POOL_WAIT
See Also:
Constant Field Values

store

protected IMAPStore store

props

protected ProtocolProperties props

poolConnections

protected List poolConnections

availableConnections

protected List availableConnections

storeConnection

protected IMAPConnection storeConnection

dedicatedStoreConnection

protected boolean dedicatedStoreConnection

poolSize

protected int poolSize

poolTimeout

protected long poolTimeout

debug

protected boolean debug

host

protected String host

port

protected int port

username

protected String username

password

protected String password

realm

protected String realm

authid

protected String authid

closed

protected boolean closed

capabilities

protected Map capabilities
Constructor Detail

IMAPConnectionPool

public IMAPConnectionPool(IMAPStore store,
                          ProtocolProperties props)
Create a connection pool associated with a give IMAPStore instance. The connection pool manages handing out connections for both the Store and Folder and Message usage. Depending on the session properties, the Store may be given a dedicated connection, or will share connections with the Folders. Connections may be requested from either the Store or Folders. Messages must request their connections from their hosting Folder, and only one connection is allowed per folder.

Parameters:
store - The Store we're creating the pool for.
props - The property bundle that defines protocol properties that alter the connection behavior.
Method Detail

protocolConnect

public boolean protocolConnect(String host,
                               int port,
                               String username,
                               String password)
                        throws MessagingException
Manage the initial connection to the IMAP server. This is the first point where we obtain the information needed to make an actual server connection. Like the Store protocolConnect method, we return false if there's any sort of authentication difficulties.

Parameters:
host - The host of the IMAP server.
port - The IMAP server connection port.
user - The connection user name.
password - The connection password.
Returns:
True if we were able to connect and authenticate correctly.
Throws:
MessagingException

createPoolConnection

protected IMAPConnection createPoolConnection()
                                       throws MessagingException
Creates an authenticated pool connection and adds it to the connection pool. If there is an existing connection already in the pool, this returns without creating a new connection.

Throws:
MessagingException

getConnection

protected IMAPConnection getConnection()
                                throws MessagingException
Get a connection from the pool. We try to retrieve a live connection, but we test the connection's liveness before returning one. If we don't have a viable connection in the pool, we'll create a new one. The returned connection will be in the authenticated state already.

Returns:
An IMAPConnection object that is connected to the server.
Throws:
MessagingException

getPoolConnection

protected IMAPConnection getPoolConnection()
                                    throws MessagingException
Obtain a connection from the existing connection pool. If none are available, and we've reached the connection pool limit, we'll wait for some other thread to return one. It generally doesn't take too long, as they're usually only held for the time required to execute a single command. If we're not at the pool limit, return null, which will signal the caller to go ahead and create a new connection outside of the lock.

Returns:
Either an active connection instance, or null if the caller should go ahead and try to create a new connection.
Throws:
MessagingException

returnPoolConnection

protected void returnPoolConnection(IMAPConnection connection)
                             throws MessagingException
Return a connection to the connection pool.

Parameters:
connection - The connection getting returned.
Throws:
MessagingException

releasePoolConnection

protected void releasePoolConnection(IMAPConnection connection)
                              throws MessagingException
Release a closed connection.

Parameters:
connection - The connection getting released.
Throws:
MessagingException

getStoreConnection

public IMAPConnection getStoreConnection()
                                  throws MessagingException
Get a connection for the Store. This will be either a dedicated connection object, or one from the pool, depending on the mail.imap.separatestoreconnection property.

Returns:
An authenticated connection object.
Throws:
MessagingException

releaseStoreConnection

public void releaseStoreConnection(IMAPConnection connection)
                            throws MessagingException
Return the Store connection to the connection pool. If we have a dedicated store connection, this is simple. Otherwise, the connection goes back into the general connection pool.

Parameters:
connection - The connection getting returned.
Throws:
MessagingException

getFolderConnection

public IMAPConnection getFolderConnection()
                                   throws MessagingException
Get a connection for Folder.

Returns:
An authenticated connection object.
Throws:
MessagingException

releaseFolderConnection

public void releaseFolderConnection(IMAPConnection connection)
                             throws MessagingException
Return a Folder connection to the connection pool.

Parameters:
connection - The connection getting returned.
Throws:
MessagingException

close

public void close()
           throws MessagingException
Close the entire connection pool.

Throws:
MessagingException

closeStaleConnections

protected void closeStaleConnections()
Flush any connections from the pool that have not been used for at least the connection pool timeout interval.


releaseConnection

protected void releaseConnection(IMAPConnection connection)
Return a connection back to the connection pool. If we're not over our limit, the connection is kept around. Otherwise, it's given a nice burial.

Parameters:
connection - The returned connection.

freeAllConnections

protected void freeAllConnections()
Cleanup time. Sever and cleanup all of the pool connection objects, including the special Store connection, if we have one.


hasCapability

public boolean hasCapability(String capability)
Test if this connection has a given capability.

Parameters:
capability - The capability name.
Returns:
true if this capability is in the list, false for a mismatch.


Copyright © 2003-2009 The Apache Software Foundation. All Rights Reserved.