Interface ConnectionFactory

All Superinterfaces:
AutoCloseable, Closeable

public interface ConnectionFactory extends Closeable
A connection factory provides an interface for obtaining a connection to a JSON resource provider. Connection factories can be used to wrap other connection factories in order to provide enhanced capabilities in a manner which is transparent to the application. For example:
  • Connection pooling
  • Load balancing
  • Keep alive
  • Logging connections
  • Read-only connections
An application typically obtains a connection from a connection factory, performs one or more operations, and then closes the connection. Applications should aim to close connections as soon as possible in order to avoid resource contention.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Releases any resources associated with this connection factory.
    Returns a connection to the JSON resource provider associated with this connection factory.
    Asynchronously obtains a connection to the JSON resource provider associated with this connection factory.
  • Method Details

    • close

      void close()
      Releases any resources associated with this connection factory. Depending on the implementation a factory may:
      • do nothing
      • close underlying connection factories (e.g. load-balancers)
      • close pooled connections (e.g. connection pools)
      • shutdown IO event service and related thread pools (e.g. Grizzly).
      Calling close on a connection factory which is already closed has no effect.

      Applications should avoid closing connection factories while there are remaining active connections in use or connection attempts in progress.

      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      See Also:
    • getConnection

      Connection getConnection() throws ResourceException
      Returns a connection to the JSON resource provider associated with this connection factory. The connection returned by this method can be used immediately.
      Returns:
      A connection to the JSON resource provider associated with this connection factory.
      Throws:
      ResourceException - If the connection request failed for some reason.
    • getConnectionAsync

      Promise<Connection,ResourceException> getConnectionAsync()
      Asynchronously obtains a connection to the JSON resource provider associated with this connection factory. The returned FutureResult can be used to retrieve the completed connection.
      Returns:
      A future which can be used to retrieve the connection.