Package org.eclipse.jetty.client
Class MultiplexConnectionPool
- java.lang.Object
-
- org.eclipse.jetty.client.AbstractConnectionPool
-
- org.eclipse.jetty.client.MultiplexConnectionPool
-
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
,ConnectionPool
,ConnectionPool.Multiplexable
,Dumpable
,Sweeper.Sweepable
public class MultiplexConnectionPool extends AbstractConnectionPool implements ConnectionPool.Multiplexable, Sweeper.Sweepable
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
MultiplexConnectionPool.Holder
-
Nested classes/interfaces inherited from interface org.eclipse.jetty.client.ConnectionPool
ConnectionPool.Factory, ConnectionPool.Multiplexable
-
Nested classes/interfaces inherited from interface org.eclipse.jetty.util.component.Dumpable
Dumpable.DumpableContainer
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.Map<Connection,MultiplexConnectionPool.Holder>
busyConnections
private java.util.Deque<MultiplexConnectionPool.Holder>
idleConnections
private java.util.concurrent.locks.ReentrantLock
lock
private static Logger
LOG
private int
maxMultiplex
private java.util.Map<Connection,MultiplexConnectionPool.Holder>
muxedConnections
-
Constructor Summary
Constructors Constructor Description MultiplexConnectionPool(HttpDestination destination, int maxConnections, Callback requester, int maxMultiplex)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected Connection
acquire(boolean create)
Returns an idle connection, if available; if an idle connection is not available, and the givencreate
parameter istrue
, then schedules the opening of a new connection, if possible within the configuration of this connection pool (for example, if it does not exceed the max connection count); otherwise returnsnull
.protected Connection
activate()
private static int
ceilDiv(int a, int b)
void
close()
Closes this ConnectionPool.void
dump(java.lang.Appendable out, java.lang.String indent)
Dump this object (and children) into an Appendable using the provided indent after any new lines.int
getMaxMultiplex()
boolean
isActive(Connection connection)
protected void
lock()
protected void
onCreated(Connection connection)
boolean
release(Connection connection)
Returns the given connection, previously obtained viaConnectionPool.acquire()
, back to this ConnectionPool.boolean
remove(Connection connection)
Removes the given connection from this ConnectionPool.protected boolean
remove(Connection connection, boolean force)
void
setMaxMultiplex(int maxMultiplex)
boolean
sweep()
java.lang.String
toString()
protected void
unlock()
-
Methods inherited from class org.eclipse.jetty.client.AbstractConnectionPool
acquire, acquired, active, close, dump, getConnectionCount, getHttpDestination, getMaxConnectionCount, getPendingConnectionCount, getPendingCount, idle, isClosed, isEmpty, proceed, released, removed, tryCreate
-
-
-
-
Field Detail
-
LOG
private static final Logger LOG
-
lock
private final java.util.concurrent.locks.ReentrantLock lock
-
idleConnections
private final java.util.Deque<MultiplexConnectionPool.Holder> idleConnections
-
muxedConnections
private final java.util.Map<Connection,MultiplexConnectionPool.Holder> muxedConnections
-
busyConnections
private final java.util.Map<Connection,MultiplexConnectionPool.Holder> busyConnections
-
maxMultiplex
private int maxMultiplex
-
-
Constructor Detail
-
MultiplexConnectionPool
public MultiplexConnectionPool(HttpDestination destination, int maxConnections, Callback requester, int maxMultiplex)
-
-
Method Detail
-
acquire
protected Connection acquire(boolean create)
Description copied from class:AbstractConnectionPool
Returns an idle connection, if available; if an idle connection is not available, and the given
create
parameter istrue
, then schedules the opening of a new connection, if possible within the configuration of this connection pool (for example, if it does not exceed the max connection count); otherwise returnsnull
.- Overrides:
acquire
in classAbstractConnectionPool
- Parameters:
create
- whether to schedule the opening of a connection if no idle connections are available- Returns:
- an idle connection or
null
if no idle connections are available - See Also:
AbstractConnectionPool.tryCreate(int)
-
ceilDiv
private static int ceilDiv(int a, int b)
- Parameters:
a
- the dividendb
- the divisor- Returns:
- the ceiling of the algebraic quotient
-
lock
protected void lock()
-
unlock
protected void unlock()
-
getMaxMultiplex
public int getMaxMultiplex()
- Specified by:
getMaxMultiplex
in interfaceConnectionPool.Multiplexable
- Returns:
- the max number of requests multiplexable on a single connection
-
setMaxMultiplex
public void setMaxMultiplex(int maxMultiplex)
- Specified by:
setMaxMultiplex
in interfaceConnectionPool.Multiplexable
- Parameters:
maxMultiplex
- the max number of requests multiplexable on a single connection
-
isActive
public boolean isActive(Connection connection)
- Specified by:
isActive
in interfaceConnectionPool
- Parameters:
connection
- the connection to test- Returns:
- whether the given connection is currently in use
-
onCreated
protected void onCreated(Connection connection)
- Specified by:
onCreated
in classAbstractConnectionPool
-
activate
protected Connection activate()
- Specified by:
activate
in classAbstractConnectionPool
-
release
public boolean release(Connection connection)
Description copied from interface:ConnectionPool
Returns the given connection, previously obtained via
ConnectionPool.acquire()
, back to this ConnectionPool.- Specified by:
release
in interfaceConnectionPool
- Parameters:
connection
- the connection to release- Returns:
- true if the connection has been released, false if the connection should be closed
-
remove
public boolean remove(Connection connection)
Description copied from interface:ConnectionPool
Removes the given connection from this ConnectionPool.
- Specified by:
remove
in interfaceConnectionPool
- Parameters:
connection
- the connection to remove- Returns:
- true if the connection was removed from this ConnectionPool
-
remove
protected boolean remove(Connection connection, boolean force)
-
close
public void close()
Description copied from interface:ConnectionPool
Closes this ConnectionPool.- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Specified by:
close
in interfaceConnectionPool
- Overrides:
close
in classAbstractConnectionPool
- See Also:
ConnectionPool.isClosed()
-
dump
public void dump(java.lang.Appendable out, java.lang.String indent) throws java.io.IOException
Description copied from interface:Dumpable
Dump this object (and children) into an Appendable using the provided indent after any new lines. The indent should not be applied to the first object dumped.
-
sweep
public boolean sweep()
- Specified by:
sweep
in interfaceSweeper.Sweepable
- Returns:
- whether this resource should be swept
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-