org.apache.ignite.internal.client.impl.connection

## Class GridClientConnectionManagerAdapter

- java.lang.Object
- - org.apache.ignite.internal.client.impl.connection.GridClientConnectionManagerAdapter

All Implemented Interfaces:
  GridClientConnectionManager

Direct Known Subclasses:
  GridClientConnectionManagerOsImpl

    public abstract class GridClientConnectionManagerAdapter
    extends Object
    implements GridClientConnectionManager

Cached connections manager.

### Field Summary

Fields
`protected GridClientConfiguration` `cfg` Client configuration.

### Constructor Summary

Constructors
`protected` `GridClientConnectionManagerAdapter(UUID clientId, SSLContext sslCtx, GridClientConfiguration cfg, Collection<InetSocketAddress> routers, GridClientTopology top, Byte marshId, boolean routerClient)`

### Method Summary

Methods
`protected GridClientConnection` `connect(UUID nodeId, Collection<InetSocketAddress> srvs)` Creates a connected facade and returns it.
`protected GridClientConnection` `connect(UUID nodeId, InetSocketAddress addr)` Create new connection to specified server.
`GridClientConnection` `connection(GridClientNode node)` Gets active communication facade.
`GridClientConnection` `connection(UUID nodeId, Collection<InetSocketAddress> srvs)` Returns connection to one of the given addresses.
`void` `init(Collection<InetSocketAddress> srvs)` Tries to open initial connection and fetch topology using given server addresses.
`protected abstract void` `init0()` Additional initialization.
`protected ThreadLocal<Boolean>` `keepPortablesThreadLocal()`
`void` `stop(boolean waitCompletion)` Closes all opened connections.
`void` `terminateConnection(GridClientConnection conn, GridClientNode node, Throwable e)` Callback method, which should be called by clients when they get connectivity errors.

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

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

### Field Detail

#### cfg

    protected final GridClientConfiguration cfg

Client configuration.

### Constructor Detail

#### GridClientConnectionManagerAdapter

    protected GridClientConnectionManagerAdapter(UUID clientId,
                                      SSLContext sslCtx,
                                      GridClientConfiguration cfg,
                                      Collection<InetSocketAddress> routers,
                                      GridClientTopology top,
                                      @Nullable
                                      Byte marshId,
                                      boolean routerClient)
                                          throws GridClientException

Parameters:
  `clientId` - Client ID.
  `sslCtx` - SSL context to enable secured connection or `null` to use unsecured one.
  `cfg` - Client configuration.
  `routers` - Routers or empty collection to use endpoints from topology info.
  `top` - Topology.
  `marshId` - Marshaller ID.
Throws:
  `GridClientException` - In case of error.

### Method Detail

#### init

    public void init(Collection<InetSocketAddress> srvs)
              throws GridClientException,
                     InterruptedException

Tries to open initial connection and fetch topology using given server addresses.

Specified by:
  `init` in interface `GridClientConnectionManager`
Parameters:
  `srvs` - Collection<InetSocketAddress> server addresses.
Throws:
  `GridClientAuthenticationException` - If connection failed to authenticate on server.
  `GridClientException` - If manager failed to initialise,
  `InterruptedException` - If manager was interrupted while waiting for connection.

#### init0

    protected abstract void init0()
                           throws GridClientException

Additional initialization.

Throws:
  `GridClientException` - In case of error.

#### connection

    public GridClientConnection connection(GridClientNode node)
                                    throws GridClientClosedException,
                                           GridServerUnreachableException,
                                           InterruptedException

Gets active communication facade.

Specified by:
  `connection` in interface `GridClientConnectionManager`
Parameters:
  `node` - Remote node to which connection should be established.
Returns:
  Connection to use for operations, targeted for the given node.
Throws:
  `GridServerUnreachableException` - If none of the servers can be reached after the exception.
  `GridClientClosedException` - If client was closed manually.
  `InterruptedException` - If connection was interrupted.

#### connection

    public GridClientConnection connection(@Nullable
                                  UUID nodeId,
                                  Collection<InetSocketAddress> srvs)
                                    throws GridServerUnreachableException,
                                           GridClientClosedException,
                                           InterruptedException

Returns connection to one of the given addresses.

Parameters:
  `nodeId` - `UUID` of node for mapping with connection. `null` if no need of mapping.
  `srvs` - Collection of addresses to connect to.
Returns:
  Connection to use for operations, targeted for the given node.
Throws:
  `GridServerUnreachableException` - If connection can't be established.
  `GridClientClosedException` - If connections manager has been closed already.
  `InterruptedException` - If connection was interrupted.

#### connect

    protected GridClientConnection connect(@Nullable
                               UUID nodeId,
                               Collection<InetSocketAddress> srvs)
                                    throws GridServerUnreachableException,
                                           InterruptedException

Creates a connected facade and returns it. Called either from constructor or inside a write lock.

Parameters:
  `nodeId` - `UUID` of node for mapping with connection. `null` if no need of mapping.
  `srvs` - List of server addresses that this method will try to connect to.
Returns:
  Established connection.
Throws:
  `GridServerUnreachableException` - If none of the servers can be reached.
  `InterruptedException` - If connection was interrupted.

#### connect

    protected GridClientConnection connect(@Nullable
                               UUID nodeId,
                               InetSocketAddress addr)
                                    throws IOException,
                                           GridClientException,
                                           InterruptedException

Create new connection to specified server.

Parameters:
  `nodeId` - `UUID` of node for mapping with connection. `null` if no need of mapping.
  `addr` - Remote socket to connect.
Returns:
  Established connection.
Throws:
  `IOException` - If connection failed.
  `GridClientException` - If protocol error happened.
  `InterruptedException` - If thread was interrupted before connection was established.

#### keepPortablesThreadLocal

    protected ThreadLocal<Boolean> keepPortablesThreadLocal()

Returns:
  Get thread local used to enable keep binary mode.

#### terminateConnection

    public void terminateConnection(GridClientConnection conn,
                           GridClientNode node,
                           Throwable e)

Callback method, which should be called by clients when they get connectivity errors. It's main purpose is to allow connection manager to terminate broken connection early and, try to establish a new one for the consequent `GridClientConnectionManager.connection(GridClientNode)` calls.

Specified by:
  `terminateConnection` in interface `GridClientConnectionManager`
Parameters:
  `conn` - Failed connection.
  `node` - Connected node.
  `e` - Error that caused connection termination.

#### stop

    public void stop(boolean waitCompletion)

Closes all opened connections.

Specified by:
  `stop` in interface `GridClientConnectionManager`
Parameters:
  `waitCompletion` - If `true` waits for all pending requests to be proceeded.

2015 Copyright © Apache Software Foundation

Follow @ApacheIgnite

Ignite Fabric | : ver. 1.5.0-b1
Release Date | : December 1 2015