Top Description Inners Fields Constructors Methods
org.eclipse.jetty.client

public Class ValidatingConnectionPool

extends DuplexConnectionPool
Class Inheritance
Imports
java.io.IOException, java.util.Map, java.util.concurrent.ConcurrentHashMap, .TimeUnit, java.util.concurrent.atomic.AtomicBoolean, org.eclipse.jetty.util.NanoTime, org.eclipse.jetty.util.annotation.ManagedAttribute, org.eclipse.jetty.util.component.Dumpable, .DumpableCollection, org.eclipse.jetty.util.thread.Scheduler, org.slf4j.Logger, .LoggerFactory

A connection pool that validates connections before making them available for use.

Connections that have just been opened are not validated. Connections that are released will be validated.

Validation by reading from the EndPoint is not reliable, since the TCP FIN may arrive just after the validation read.

This class validates connections by putting them in a "quarantine" for a configurable timeout, where they cannot be used to send requests. When the timeout expires, the quarantined connection is made idle and therefore available to send requests.

The existing HttpClient mechanism to detect server closes will trigger and close quarantined connections, before they are made idle (and reusable) again.

There still is a small chance that the timeout expires, the connection is made idle and available again, it is used to send a request exactly when the server decides to close. This case is however unavoidable and may be mitigated by tuning the idle timeout of the servers to be larger than that of the client.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class

Field Summary

Modifier and TypeField and Description
private static final Logger
private final Map<Connection, ValidatingConnectionPool.Holder>
private final Scheduler
private final long

Constructor Summary

AccessConstructor and Description
public
ValidatingConnectionPool(Destination destination, int maxConnections, Scheduler scheduler, long timeout)

Method Summary

Modifier and TypeMethod and Description
public void
dump(Appendable
The appendable to dump to
out
,
String
The indent to apply after any new lines.
indent
)

Overrides org.eclipse.jetty.client.AbstractConnectionPool.dump.

Implements org.eclipse.jetty.util.component.Dumpable.dump.

Dump this object (and children) into an Appendable using the provided indent after any new lines.
public int
public boolean
release(Connection
the connection to release
connection
)

Overrides org.eclipse.jetty.client.AbstractConnectionPool.release.

Implements org.eclipse.jetty.client.ConnectionPool.release.

Returns the given connection, previously obtained via acquire(boolean), back to this ConnectionPool.

public boolean
remove(Connection
the connection to remove
connection
)

Overrides org.eclipse.jetty.client.AbstractConnectionPool.remove.

Implements org.eclipse.jetty.client.ConnectionPool.remove.

Removes the given connection from this ConnectionPool.

public String
toString()

Overrides org.eclipse.jetty.client.AbstractConnectionPool.toString.

Returns a string representation of the object.

Field Detail

LOGback to summary
private static final Logger LOG

Hides org.eclipse.jetty.client.AbstractConnectionPool.LOG.

quarantineback to summary
private final Map<Connection, ValidatingConnectionPool.Holder> quarantine
schedulerback to summary
private final Scheduler scheduler
timeoutback to summary
private final long timeout

Constructor Detail

ValidatingConnectionPoolback to summary
public ValidatingConnectionPool(Destination destination, int maxConnections, Scheduler scheduler, long timeout)

Method Detail

dumpback to summary
public void dump(Appendable out, String indent) throws IOException

Overrides org.eclipse.jetty.client.AbstractConnectionPool.dump.

Implements org.eclipse.jetty.util.component.Dumpable.dump.

Doc from org.eclipse.jetty.util.component.Dumpable.dump.

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.

Parameters
out:Appendable

The appendable to dump to

indent:String

The indent to apply after any new lines.

Annotations
@Override
Exceptions
IOException:
if unable to write to Appendable
getValidatingConnectionCountback to summary
public int getValidatingConnectionCount()
Annotations
@ManagedAttribute:The number of validating connections
readonly:true
releaseback to summary
public boolean release(Connection connection)

Overrides org.eclipse.jetty.client.AbstractConnectionPool.release.

Implements org.eclipse.jetty.client.ConnectionPool.release.

Doc from org.eclipse.jetty.client.ConnectionPool.release.

Returns the given connection, previously obtained via acquire(boolean), back to this ConnectionPool.

Parameters
connection:Connection

the connection to release

Returns:boolean

true if the connection has been released, false if the connection should be closed

Annotations
@Override
removeback to summary
public boolean remove(Connection connection)

Overrides org.eclipse.jetty.client.AbstractConnectionPool.remove.

Implements org.eclipse.jetty.client.ConnectionPool.remove.

Doc from org.eclipse.jetty.client.ConnectionPool.remove.

Removes the given connection from this ConnectionPool.

Parameters
connection:Connection

the connection to remove

Returns:boolean

true if the connection was removed from this ConnectionPool

Annotations
@Override
toStringback to summary
public String toString()

Overrides org.eclipse.jetty.client.AbstractConnectionPool.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object.

Annotations
@Override
org.eclipse.jetty.client back to summary

private Class ValidatingConnectionPool.Holder

extends Object
implements Runnable
Class Inheritance
All Implemented Interfaces
java.lang.Runnable

Field Summary

Modifier and TypeField and Description
private final Connection
private final long
private final AtomicBoolean
public Scheduler.Task

Constructor Summary

AccessConstructor and Description
public
Holder(Connection connection)

Method Summary

Modifier and TypeMethod and Description
public boolean
public void
run()

Implements java.lang.Runnable.run.

Runs this operation.
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

connectionback to summary
private final Connection connection
creationNanoTimeback to summary
private final long creationNanoTime
doneback to summary
private final AtomicBoolean done
taskback to summary
public Scheduler.Task task

Constructor Detail

Holderback to summary
public Holder(Connection connection)

Method Detail

cancelback to summary
public boolean cancel()
runback to summary
public void run()

Implements java.lang.Runnable.run.

Doc from java.lang.Runnable.run.

Runs this operation.

Annotations
@Override
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object.

Annotations
@Override