com.twitter.common.net.pool
Interface ConnectionFactory<S extends Connection<?,?>>

All Known Implementing Classes:
ThriftConnectionFactory

public interface ConnectionFactory<S extends Connection<?,?>>

A factory for connections that also dictates policy for the size of the connection population.

TODO(John Sirois): separate concerns - mixing in willCreate/null protocol is already tangling implementation code


Method Summary
 S create(Amount<Long,Time> timeout)
          Attempts to create a new connection within the given timeout and subject to this factory's connection population size policy.
 void destroy(S connection)
          Destroys a connection.
 boolean mightCreate()
          Checks whether this factory might create a connection if requested.
 

Method Detail

mightCreate

boolean mightCreate()
Checks whether this factory might create a connection if requested.

Returns:
true if this factory might create a connection at this point in time; ie a call to create(com.twitter.common.quantity.Amount) might not have returned null. May return true to multiple threads if concurrently creating connections.

create

S create(Amount<Long,Time> timeout)
                                 throws Exception
Attempts to create a new connection within the given timeout and subject to this factory's connection population size policy.

Parameters:
timeout - the maximum amount of time to wait
Returns:
a new connection or null if there are too many connections already
Throws:
Exception - if there was a problem creating the connection or establishing the connection takes too long

destroy

void destroy(S connection)
Destroys a connection. It is an error to attempt to destroy a connection this factory did not create(com.twitter.common.quantity.Amount)

Parameters:
connection - The connection to destroy.