org.apache.ignite.internal.client

## Class GridClientConfiguration

- java.lang.Object
- - org.apache.ignite.internal.client.GridClientConfiguration

    public class GridClientConfiguration
    extends Object

Java client configuration.

### Field Summary

Fields
`static GridClientProtocol` `DFLT_CLIENT_PROTOCOL` Default client protocol.
`static int` `DFLT_CONNECT_TIMEOUT` Default connect timeout in milliseconds.
`static long` `DFLT_MAX_CONN_IDLE_TIME` Default maximum time connection can be idle.
`static long` `DFLT_PING_INTERVAL` Default ping interval in milliseconds.
`static long` `DFLT_PING_TIMEOUT` Default ping timeout in milliseconds.
`static boolean` `DFLT_TCP_NODELAY` Default flag setting for TCP_NODELAY option.
`static int` `DFLT_TOP_REFRESH_FREQ` Default topology refresh frequency is 2 sec.

### Constructor Summary

Constructors
Constructor and Description
`GridClientConfiguration()` Creates default configuration.
`GridClientConfiguration(GridClientConfiguration cfg)` Copy constructor.
`GridClientConfiguration(Properties in)` Creates properties-based configuration based on passed in properties.
`GridClientConfiguration(String prefix, Properties in)` Creates properties-based configuration.

### Method Summary

Methods
`GridClientLoadBalancer` `getBalancer()` Default balancer to be used for computational client.
`int` `getConnectTimeout()` Gets timeout for socket connect operation in milliseconds.
`GridClientDataConfiguration` `getDataConfiguration(String name)` Gets data configuration for a cache with specified name.
`Collection<GridClientDataConfiguration>` `getDataConfigurations()` Gets a collection of data configurations specified by user.
`ExecutorService` `getExecutorService()` Gets `ExecutorService` where client could run asynchronous operations.
`GridClientMarshaller` `getMarshaller()` Gets the marshaller, that is used to communicate between client and server.
`long` `getMaxConnectionIdleTime()` Gets maximum amount of time that client connection can be idle before it is closed.
`long` `getPingInterval()` Gets time interval in milliseconds between ping requests.
`long` `getPingTimeout()` Gets ping timeout.
`GridClientProtocol` `getProtocol()` Gets protocol for communication between client and remote grid.
`Collection<String>` `getRouters()` Collection of `'host:port'` pairs representing grid routers used to establish connection to the grid.
`SecurityCredentialsProvider` `getSecurityCredentialsProvider()` Gets client credentials provider to authenticate with.
`Collection<String>` `getServers()` Collection of `'host:port'` pairs representing remote grid servers used to establish initial connection to the grid.
`GridSslContextFactory` `getSslContextFactory()` Gets a factory that should be used for SSL context creation.
`long` `getTopologyRefreshFrequency()` Gets topology refresh frequency.
`boolean` `isAutoFetchAttributes()` Allows client to fetch node attributes automatically with background topology refresh.
`boolean` `isAutoFetchMetrics()` Allows client to fetch node metrics automatically with background topology refresh.
`boolean` `isDaemon()` Get the daemon flag.
`boolean` `isEnableAttributesCache()` Enables client to cache per-node attributes internally.
`boolean` `isEnableMetricsCache()` Enables client to cache per-node and per-cache metrics internally.
`boolean` `isTcpNoDelay()` Gets flag indicating whether `TCP_NODELAY` flag should be enabled for outgoing connections.
`void` `load(String prefix, Properties in)` Load client configuration from the properties map.
`void` `setAutoFetchAttributes(boolean autoFetchAttrs)` Sets flag indicating whether node attributes should be fetched by client automatically.
`void` `setAutoFetchMetrics(boolean autoFetchMetrics)` Sets flag indicating whether node metrics should be fetched by client automatically.
`void` `setBalancer(GridClientLoadBalancer balancer)` Sets default compute balancer.
`void` `setConnectTimeout(int connectTimeout)` Sets timeout for socket connect operation.
`void` `setDaemon(boolean daemon)` Set the daemon flag value.
`void` `setDataConfigurations(Collection<? extends GridClientDataConfiguration> dataCfgs)` Sets data configurations.
`void` `setEnableAttributesCache(boolean enableAttrsCache)` Sets flag indicating whether node attributes should be cached by client.
`void` `setEnableMetricsCache(boolean enableMetricsCache)` Sets flag indicating whether node and cache metrics should be cached by client.
`void` `setExecutorService(ExecutorService executor)` Sets executor service.
`void` `setMarshaller(GridClientMarshaller marshaller)` Sets the marshaller to use for communication.
`void` `setMaxConnectionIdleTime(long maxConnIdleTime)` Sets maximum time in milliseconds which connection can be idle before it is closed by client.
`void` `setPingInterval(long pingInterval)` Sets ping interval in milliseconds.
`void` `setPingTimeout(long pingTimeout)` Sets ping timeout in milliseconds.
`void` `setProtocol(GridClientProtocol proto)` Sets protocol type that should be used in communication.
`void` `setRouters(Collection<String> routers)` Sets list of routers this client should connect to.
`void` `setSecurityCredentialsProvider(SecurityCredentialsProvider credProvider)` Sets client credentials provider used in authentication process.
`void` `setServers(Collection<String> srvs)` Sets list of servers this client should connect to.
`void` `setSslContextFactory(GridSslContextFactory sslCtxFactory)` Sets SSL context factory that will be used for creation of secure connections.
`void` `setTcpNoDelay(boolean tcpNoDelay)` Sets whether `TCP_NODELAY` flag should be set on underlying socket connections.
`void` `setTopologyRefreshFrequency(long topRefreshFreq)` Sets topology refresh frequency.

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

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

### Field Detail

#### DFLT_CLIENT_PROTOCOL

    public static final GridClientProtocol DFLT_CLIENT_PROTOCOL

Default client protocol.

#### DFLT_TOP_REFRESH_FREQ

    public static final int DFLT_TOP_REFRESH_FREQ

Default topology refresh frequency is 2 sec.

See Also:
  Constant Field Values

#### DFLT_MAX_CONN_IDLE_TIME

    public static final long DFLT_MAX_CONN_IDLE_TIME

Default maximum time connection can be idle.

See Also:
  Constant Field Values

#### DFLT_PING_INTERVAL

    public static final long DFLT_PING_INTERVAL

Default ping interval in milliseconds.

See Also:
  Constant Field Values

#### DFLT_PING_TIMEOUT

    public static final long DFLT_PING_TIMEOUT

Default ping timeout in milliseconds.

See Also:
  Constant Field Values

#### DFLT_CONNECT_TIMEOUT

    public static final int DFLT_CONNECT_TIMEOUT

Default connect timeout in milliseconds.

See Also:
  Constant Field Values

#### DFLT_TCP_NODELAY

    public static final boolean DFLT_TCP_NODELAY

Default flag setting for TCP_NODELAY option.

See Also:
  Constant Field Values

### Constructor Detail

#### GridClientConfiguration

    public GridClientConfiguration()

Creates default configuration.

#### GridClientConfiguration

    public GridClientConfiguration(GridClientConfiguration cfg)

Copy constructor.

Parameters:
  `cfg` - Configuration to be copied.

#### GridClientConfiguration

    public GridClientConfiguration(Properties in)
                            throws GridClientException

Creates properties-based configuration based on passed in properties.

Parameters:
  `in` - Client configuration in properties format.
Throws:
  `GridClientException` - If parsing configuration failed.

#### GridClientConfiguration

    public GridClientConfiguration(String prefix,
                           Properties in)
                            throws GridClientException

Creates properties-based configuration.

Parameters:
  `prefix` - Prefix for the client properties.
  `in` - Properties map to load configuration from.
Throws:
  `GridClientException` - If parsing configuration failed.

### Method Detail

#### getServers

    public Collection<String> getServers()

Collection of `'host:port'` pairs representing remote grid servers used to establish initial connection to the grid. Once connection is established, Ignite will get a full view on grid topology and will be able to connect to any available remote node.

Note that only these addresses are used to perform topology updates in background and to detect Grid connectivity status.

Returns:
  Collection of `'host:port'` pairs representing remote grid servers.
See Also:
  `GridClient.connected()`

#### getRouters

    public Collection<String> getRouters()

Collection of `'host:port'` pairs representing grid routers used to establish connection to the grid.

Addresses here could be owned by Routers as well as by individual Grid nodes. No additional connections will be made even if other Grid nodes are available.

This configuration mode is designated for cases when some Grid nodes are unavailable (due to security restrictions for example). So only few nodes acting as routers or dedicated router components used to access entire Grid.

This configuration parameter will not be used and direct connections to all grid nodes will be established if `getServers()` return non-empty collection value.

Note that only these addresses are used to perform topology updates in background and to detect Grid connectivity status.

Returns:
  Collection of `'host:port'` pairs representing routers.
See Also:
  `GridClient.connected()`

#### setServers

    public void setServers(Collection<String> srvs)

Sets list of servers this client should connect to.

Parameters:
  `srvs` - List of servers.

#### setRouters

    public void setRouters(Collection<String> routers)

Sets list of routers this client should connect to.

Parameters:
  `routers` - List of routers.

#### getProtocol

    public GridClientProtocol getProtocol()

Gets protocol for communication between client and remote grid. Default is defined by `DFLT_CLIENT_PROTOCOL` constant.

Returns:
  Protocol for communication between client and remote grid.

#### setProtocol

    public void setProtocol(GridClientProtocol proto)

Sets protocol type that should be used in communication. Protocol type cannot be changed after client is created.

Parameters:
  `proto` - Protocol type.
See Also:
  `GridClientProtocol`

#### getConnectTimeout

    public int getConnectTimeout()

Gets timeout for socket connect operation in milliseconds. If `0` - then wait infinitely. Default is defined by `DFLT_CONNECT_TIMEOUT` constant.

Returns:
  Connect timeout in milliseconds.

#### isTcpNoDelay

    public boolean isTcpNoDelay()

Gets flag indicating whether `TCP_NODELAY` flag should be enabled for outgoing connections. This flag reduces communication latency and in the majority of cases should be set to true. For more information, see `Socket.setTcpNoDelay(boolean)`

If not set, default value is `DFLT_TCP_NODELAY`

Returns:
  If `TCP_NODELAY` should be set on underlying sockets.

#### setTcpNoDelay

    public void setTcpNoDelay(boolean tcpNoDelay)

Sets whether `TCP_NODELAY` flag should be set on underlying socket connections.

Parameters:
  `tcpNoDelay` - `True` if flag should be set.

#### setConnectTimeout

    public void setConnectTimeout(int connectTimeout)

Sets timeout for socket connect operation.

Parameters:
  `connectTimeout` - Connect timeout in milliseconds.

#### getSslContextFactory

    public GridSslContextFactory getSslContextFactory()

Gets a factory that should be used for SSL context creation. If it returns `null` then SSL is considered disabled.

Returns:
  Factory instance.
See Also:
  `GridSslContextFactory`

#### setSslContextFactory

    public void setSslContextFactory(GridSslContextFactory sslCtxFactory)

Sets SSL context factory that will be used for creation of secure connections.

Parameters:
  `sslCtxFactory` - Context factory.

#### getBalancer

    public GridClientLoadBalancer getBalancer()

Default balancer to be used for computational client. It can be overridden for different compute instances. By default `GridClientRandomBalancer` is used.

Returns:
  Default balancer to be used for computational client.

#### setBalancer

    public void setBalancer(GridClientLoadBalancer balancer)

Sets default compute balancer.

Parameters:
  `balancer` - Balancer to use.

#### getSecurityCredentialsProvider

    public SecurityCredentialsProvider getSecurityCredentialsProvider()

Gets client credentials provider to authenticate with.

Returns:
  Credentials provider.

#### setSecurityCredentialsProvider

    public void setSecurityCredentialsProvider(SecurityCredentialsProvider credProvider)

Sets client credentials provider used in authentication process.

Parameters:
  `credProvider` - Client credentials provider.

#### getDataConfigurations

    public Collection<GridClientDataConfiguration> getDataConfigurations()

Gets a collection of data configurations specified by user.

Returns:
  Collection of data configurations (possibly empty).

#### setDataConfigurations

    public void setDataConfigurations(Collection<? extends GridClientDataConfiguration> dataCfgs)

Sets data configurations.

Parameters:
  `dataCfgs` - Data configurations.

#### getDataConfiguration

    public GridClientDataConfiguration getDataConfiguration(@Nullable
                                                   String name)

Gets data configuration for a cache with specified name.

Parameters:
  `name` - Name of grid cache.
Returns:
  Configuration or `null` if there is not configuration for specified name.

#### setEnableMetricsCache

    public void setEnableMetricsCache(boolean enableMetricsCache)

Sets flag indicating whether node and cache metrics should be cached by client.

Parameters:
  `enableMetricsCache` - `True` if cache should be enabled.

#### isEnableMetricsCache

    public boolean isEnableMetricsCache()

Enables client to cache per-node and per-cache metrics internally. In memory sensitive environments, such as mobile platforms, caching metrics may be expensive and, hence, this parameter should be set to `false`.

Note that topology is refreshed automatically every `getTopologyRefreshFrequency()` interval, and if `isAutoFetchMetrics()` enabled then metrics will be updated with that frequency.

By default this value is `true` which means that metrics will be cached on the client side.

Returns:
  `True` if metrics cache is enabled, `false` otherwise.

#### setEnableAttributesCache

    public void setEnableAttributesCache(boolean enableAttrsCache)

Sets flag indicating whether node attributes should be cached by client.

Parameters:
  `enableAttrsCache` - `True` if cache should be enabled.

#### isEnableAttributesCache

    public boolean isEnableAttributesCache()

Enables client to cache per-node attributes internally. In memory sensitive environments, such as mobile platforms, caching node attributes may be expensive and, hence, this parameter should be set to `false`.

Note that node attributes are static and, if cached, there is no need to refresh them again. If `isAutoFetchAttributes()` is enabled then attributes will be cached during client initialization.

By default this value is `true` which means that node attributes will be cached on the client side.

Returns:
  `True` if attributes cache is enabled, `false` otherwise.

#### setAutoFetchMetrics

    public void setAutoFetchMetrics(boolean autoFetchMetrics)

Sets flag indicating whether node metrics should be fetched by client automatically.

Parameters:
  `autoFetchMetrics` - `True` if metrics should be fetched.

#### isAutoFetchMetrics

    public boolean isAutoFetchMetrics()

Allows client to fetch node metrics automatically with background topology refresh.

Note that this parameter will only affect auto-fetching of node metrics. Cache metrics still need to be fetched explicitly via `GridClientData.metrics()` or `GridClientData.metricsAsync()` methods.

By default this value is `true` which means that metrics will be fetched automatically.

Returns:
  `true` if client should fetch metrics on topology refresh, `false` otherwise.

#### setAutoFetchAttributes

    public void setAutoFetchAttributes(boolean autoFetchAttrs)

Sets flag indicating whether node attributes should be fetched by client automatically.

Parameters:
  `autoFetchAttrs` - `True` if attributes should be fetched.

#### isAutoFetchAttributes

    public boolean isAutoFetchAttributes()

Allows client to fetch node attributes automatically with background topology refresh.

By default this value is `true` which means that attributes will be fetched automatically.

Returns:
  `True` if client should fetch attributes once on topology refresh, `false` otherwise.

#### getTopologyRefreshFrequency

    public long getTopologyRefreshFrequency()

Gets topology refresh frequency. Default is defined by `DFLT_TOP_REFRESH_FREQ` constant.

Returns:
  Topology refresh frequency.

#### setTopologyRefreshFrequency

    public void setTopologyRefreshFrequency(long topRefreshFreq)

Sets topology refresh frequency. If topology cache is enabled, grid topology will be refreshed every `topRefreshFreq` milliseconds.

Parameters:
  `topRefreshFreq` - Topology refresh frequency in milliseconds.

#### getMaxConnectionIdleTime

    public long getMaxConnectionIdleTime()

Gets maximum amount of time that client connection can be idle before it is closed. Default is defined by `DFLT_MAX_CONN_IDLE_TIME` constant.

Returns:
  Maximum idle time in milliseconds.

#### setMaxConnectionIdleTime

    public void setMaxConnectionIdleTime(long maxConnIdleTime)

Sets maximum time in milliseconds which connection can be idle before it is closed by client.

Parameters:
  `maxConnIdleTime` - Maximum time of connection idleness in milliseconds.

#### getPingInterval

    public long getPingInterval()

Gets time interval in milliseconds between ping requests. Default is defined by `DFLT_PING_INTERVAL` constant.

Ping requests used by `GridClientProtocol.TCP` protocol to detect network failures and half-opened sockets.

Returns:
  Ping interval.

#### setPingInterval

    public void setPingInterval(long pingInterval)

Sets ping interval in milliseconds.

Parameters:
  `pingInterval` - Ping interval in milliseconds.

#### getPingTimeout

    public long getPingTimeout()

Gets ping timeout. Default is defined by `DFLT_PING_TIMEOUT` constant.

Ping requests used by `GridClientProtocol.TCP` protocol to detect network failures and half-opened sockets. If no response received in period equal to this timeout than connection considered broken and closed.

Returns:
  Ping timeout.

#### setPingTimeout

    public void setPingTimeout(long pingTimeout)

Sets ping timeout in milliseconds.

Parameters:
  `pingTimeout` - Ping interval in milliseconds.

#### getExecutorService

    public ExecutorService getExecutorService()

Gets `ExecutorService` where client could run asynchronous operations.

When using `GridClientProtocol.TCP` this executor should be able to serve at least `Runtime.getRuntime().availableProcessors()` parallel tasks.

Note that this executor will be automatically shut down when client get closed.

Returns:
  `ExecutorService` instance to use.

#### setExecutorService

    public void setExecutorService(ExecutorService executor)

Sets executor service.

Parameters:
  `executor` - Executor service to use in client.

#### getMarshaller

    public GridClientMarshaller getMarshaller()

Gets the marshaller, that is used to communicate between client and server.

Options, that can be used out-of-the-box:

- `GridClientOptimizedMarshaller` (default) - Ignite's optimized marshaller.
- `GridClientPortableMarshaller` - Marshaller that supports portable objects.
- `GridClientJdkMarshaller` - JDK marshaller (not recommended).

Returns:
  A marshaller to use.

#### setMarshaller

    public void setMarshaller(GridClientMarshaller marshaller)

Sets the marshaller to use for communication.

Parameters:
  `marshaller` - A marshaller to use.

#### load

    public void load(String prefix,
            Properties in)
              throws GridClientException

Load client configuration from the properties map.

Parameters:
  `prefix` - Prefix for the client properties.
  `in` - Properties map to load configuration from.
Throws:
  `GridClientException` - If parsing configuration failed.

#### setDaemon

    public void setDaemon(boolean daemon)

Set the daemon flag value. Communication threads will be created as daemons if this flag is set.

Parameters:
  `daemon` - Daemon flag.

#### isDaemon

    public boolean isDaemon()

Get the daemon flag.

Returns:
  Daemon flag.

2015 Copyright © Apache Software Foundation

Follow @ApacheIgnite

Ignite Fabric | : ver. 1.1.0-incubating
Release Date | : May 20 2015