Package org.apache.synapse.transport.passthru.connections

## Class TargetConnections

- java.lang.Object
- - org.apache.synapse.transport.passthru.connections.TargetConnections

-     public class TargetConnections
      extends Object

  Manages the connection from transport to the back end servers. It keeps track of the connections for host:port pair.

- - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `TargetConnections​(org.apache.http.nio.reactor.ConnectingIOReactor ioReactor, TargetConfiguration targetConfiguration, ConnectCallback callback)` | Create a TargetConnections with the given IO-Reactor

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `void` | `addConnection​(org.apache.http.nio.NHttpClientConnection conn)` | This method is called when a new connection is made.
    `void` | `closeConnection​(org.apache.http.nio.NHttpClientConnection conn, boolean isError)` | Close a connection gracefully.
    `org.apache.http.nio.NHttpClientConnection` | `getConnection​(RouteRequestMapping routeRequestMapping, org.apache.axis2.context.MessageContext msgContext, TargetErrorHandler targetErrorHandler, Queue<org.apache.axis2.context.MessageContext> queue)` | Return a connection to the host:port pair.
    `org.apache.http.nio.NHttpClientConnection` | `getExistingConnection​(RouteRequestMapping routeRequestMapping)` |
    `void` | `releaseConnection​(org.apache.http.nio.NHttpClientConnection conn)` | Release an active connection to the pool
    `void` | `resetConnectionPool​(Set<RequestDescriptor> hostList)` | Shutdown the connections of the given host:port list.
    `void` | `shutdownConnection​(org.apache.http.nio.NHttpClientConnection conn)` | This connection is no longer valid.
    `void` | `shutdownConnection​(org.apache.http.nio.NHttpClientConnection conn, boolean isError)` | This connection is no longer valid.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### TargetConnections

          public TargetConnections​(org.apache.http.nio.reactor.ConnectingIOReactor ioReactor,
                                   TargetConfiguration targetConfiguration,
                                   ConnectCallback callback)

      Create a TargetConnections with the given IO-Reactor
      Parameters:
        `ioReactor` - the IO-Reactor
        `targetConfiguration` - the configuration of the sender
        `callback` - the callback

  - ### Method Detail

    - #### getConnection

          public org.apache.http.nio.NHttpClientConnection getConnection​(RouteRequestMapping routeRequestMapping,
                                                                         org.apache.axis2.context.MessageContext msgContext,
                                                                         TargetErrorHandler targetErrorHandler,
                                                                         Queue<org.apache.axis2.context.MessageContext> queue)

      Return a connection to the host:port pair. If a connection is not available return `null`. If the particular host:port allows to create more connections this method will try to connect asynchronously. If the connection is successful it will be notified in a separate thread.
      Parameters:
        `routeRequestMapping` - Http Request route
      Returns:
        Either returns a connection if already available or returns null and notifies the delivery agent when the connection is available

    - #### getExistingConnection

          public org.apache.http.nio.NHttpClientConnection getExistingConnection​(RouteRequestMapping routeRequestMapping)

    - #### shutdownConnection

          public void shutdownConnection​(org.apache.http.nio.NHttpClientConnection conn)

      This connection is no longer valid. So we need to shutdownConnection connection.
      Parameters:
        `conn` - connection to shutdownConnection

    - #### shutdownConnection

          public void shutdownConnection​(org.apache.http.nio.NHttpClientConnection conn,
                                         boolean isError)

      This connection is no longer valid. So we need to shutdownConnection connection.
      Parameters:
        `conn` - connection to shutdownConnection
        `isError` - whether an error is causing this shutdown of the connection. It is very important to set this flag correctly. When an error causing the shutdown of the connections we should not release associated writer buffer to the pool as it might lead into situations like same buffer is getting released to both source and target buffer factories

    - #### closeConnection

          public void closeConnection​(org.apache.http.nio.NHttpClientConnection conn,
                                      boolean isError)

      Close a connection gracefully.
      Parameters:
        `conn` - the connection that needs to be closed.
        `isError` - whether an error is causing the close of the connection. When an error is causing a close of a connection we should not release the associated buffers into the pool.

    - #### releaseConnection

          public void releaseConnection​(org.apache.http.nio.NHttpClientConnection conn)

      Release an active connection to the pool
      Parameters:
        `conn` - connection to be released

    - #### addConnection

          public void addConnection​(org.apache.http.nio.NHttpClientConnection conn)

      This method is called when a new connection is made.
      Parameters:
        `conn` - connection to the target server

    - #### resetConnectionPool

          public void resetConnectionPool​(Set<RequestDescriptor> hostList)

      Shutdown the connections of the given host:port list. This will allow to create new connection at the next request happens.
      Parameters:
        `hostList` - Set of String which contains entries in hots:port format