Class GridClientConfiguration
- java.lang.Object
-
- org.apache.ignite.internal.client.GridClientConfiguration
-
public class GridClientConfiguration extends Object
Java client configuration.
-
-
Field Summary
Fields Modifier and Type Field Description static GridClientProtocolDFLT_CLIENT_PROTOCOLDefault client protocol.static intDFLT_CONNECT_TIMEOUTDefault connect timeout in milliseconds.static longDFLT_MAX_CONN_IDLE_TIMEDefault maximum time connection can be idle.static longDFLT_PING_INTERVALDefault ping interval in milliseconds.static longDFLT_PING_TIMEOUTDefault ping timeout in milliseconds.static booleanDFLT_TCP_NODELAYDefault flag setting for TCP_NODELAY option.static intDFLT_TOP_REFRESH_FREQDefault topology refresh frequency is 2 sec.
-
Constructor Summary
Constructors Constructor Description GridClientConfiguration()Creates default configuration.GridClientConfiguration(String prefix, Properties in)Creates properties-based configuration.GridClientConfiguration(Properties in)Creates properties-based configuration based on passed in properties.GridClientConfiguration(GridClientConfiguration cfg)Copy constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description GridClientLoadBalancergetBalancer()Default balancer to be used for computational client.intgetConnectTimeout()Gets timeout for socket connect operation in milliseconds.GridClientDataConfigurationgetDataConfiguration(@Nullable String name)Gets data configuration for a cache with specified name.Collection<GridClientDataConfiguration>getDataConfigurations()Gets a collection of data configurations specified by user.ExecutorServicegetExecutorService()GetsExecutorServicewhere client could run asynchronous operations.GridClientMarshallergetMarshaller()Gets the marshaller, that is used to communicate between client and server.longgetMaxConnectionIdleTime()Gets maximum amount of time that client connection can be idle before it is closed.longgetPingInterval()Gets time interval in milliseconds between ping requests.longgetPingTimeout()Gets ping timeout.GridClientProtocolgetProtocol()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.SecurityCredentialsProvidergetSecurityCredentialsProvider()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.javax.cache.configuration.Factory<SSLContext>getSslContextFactory()Gets a factory that should be used for SSL context creation.longgetTopologyRefreshFrequency()Gets topology refresh frequency.Map<String,String>getUserAttributes()Returns user attributes which can be used on server node.booleanisAutoFetchAttributes()Allows client to fetch node attributes automatically with background topology refresh.booleanisAutoFetchMetrics()Allows client to fetch node metrics automatically with background topology refresh.booleanisDaemon()Get the daemon flag.booleanisEnableAttributesCache()Enables client to cache per-node attributes internally.booleanisEnableMetricsCache()Enables client to cache per-node and per-cache metrics internally.booleanisTcpNoDelay()Gets flag indicating whetherTCP_NODELAYflag should be enabled for outgoing connections.voidload(String prefix, Properties in)Load client configuration from the properties map.GridClientConfigurationsetAutoFetchAttributes(boolean autoFetchAttrs)Sets flag indicating whether node attributes should be fetched by client automatically.GridClientConfigurationsetAutoFetchMetrics(boolean autoFetchMetrics)Sets flag indicating whether node metrics should be fetched by client automatically.GridClientConfigurationsetBalancer(GridClientLoadBalancer balancer)Sets default compute balancer.GridClientConfigurationsetConnectTimeout(int connectTimeout)Sets timeout for socket connect operation.GridClientConfigurationsetDaemon(boolean daemon)Set the daemon flag value.GridClientConfigurationsetDataConfigurations(Collection<? extends GridClientDataConfiguration> dataCfgs)Sets data configurations.GridClientConfigurationsetEnableAttributesCache(boolean enableAttrsCache)Sets flag indicating whether node attributes should be cached by client.GridClientConfigurationsetEnableMetricsCache(boolean enableMetricsCache)Sets flag indicating whether node and cache metrics should be cached by client.GridClientConfigurationsetExecutorService(ExecutorService executor)Sets executor service.GridClientConfigurationsetMarshaller(GridClientMarshaller marshaller)Sets the marshaller to use for communication.GridClientConfigurationsetMaxConnectionIdleTime(long maxConnIdleTime)Sets maximum time in milliseconds which connection can be idle before it is closed by client.GridClientConfigurationsetPingInterval(long pingInterval)Sets ping interval in milliseconds.GridClientConfigurationsetPingTimeout(long pingTimeout)Sets ping timeout in milliseconds.GridClientConfigurationsetProtocol(GridClientProtocol proto)Sets protocol type that should be used in communication.GridClientConfigurationsetRouters(Collection<String> routers)Sets list of routers this client should connect to.GridClientConfigurationsetSecurityCredentialsProvider(SecurityCredentialsProvider credProvider)Sets client credentials provider used in authentication process.GridClientConfigurationsetServers(Collection<String> srvs)Sets list of servers this client should connect to.GridClientConfigurationsetSslContextFactory(javax.cache.configuration.Factory<SSLContext> sslCtxFactory)Sets SSL context factory that will be used for creation of secure connections.GridClientConfigurationsetTcpNoDelay(boolean tcpNoDelay)Sets whetherTCP_NODELAYflag should be set on underlying socket connections.GridClientConfigurationsetTopologyRefreshFrequency(long topRefreshFreq)Sets topology refresh frequency.GridClientConfigurationsetUserAttributes(Map<String,String> userAttrs)Sets user attributes which can be used to send additional info to the server nodes.
-
-
-
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 GridClientConfiguration setServers(Collection<String> srvs)
Sets list of servers this client should connect to.- Parameters:
srvs- List of servers.- Returns:
thisfor chaining.
-
setRouters
public GridClientConfiguration setRouters(Collection<String> routers)
Sets list of routers this client should connect to.- Parameters:
routers- List of routers.- Returns:
thisfor chaining.
-
getProtocol
public GridClientProtocol getProtocol()
Gets protocol for communication between client and remote grid. Default is defined byDFLT_CLIENT_PROTOCOLconstant.- Returns:
- Protocol for communication between client and remote grid.
-
setProtocol
public GridClientConfiguration 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.- Returns:
thisfor chaining.- See Also:
GridClientProtocol
-
getConnectTimeout
public int getConnectTimeout()
Gets timeout for socket connect operation in milliseconds. If0- then wait infinitely. Default is defined byDFLT_CONNECT_TIMEOUTconstant.- Returns:
- Connect timeout in milliseconds.
-
isTcpNoDelay
public boolean isTcpNoDelay()
Gets flag indicating whetherTCP_NODELAYflag 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, seeSocket.setTcpNoDelay(boolean)If not set, default value is
DFLT_TCP_NODELAY- Returns:
- If
TCP_NODELAYshould be set on underlying sockets.
-
setTcpNoDelay
public GridClientConfiguration setTcpNoDelay(boolean tcpNoDelay)
Sets whetherTCP_NODELAYflag should be set on underlying socket connections.- Parameters:
tcpNoDelay-Trueif flag should be set.- Returns:
thisfor chaining.
-
setConnectTimeout
public GridClientConfiguration setConnectTimeout(int connectTimeout)
Sets timeout for socket connect operation.- Parameters:
connectTimeout- Connect timeout in milliseconds.- Returns:
thisfor chaining.
-
getSslContextFactory
public javax.cache.configuration.Factory<SSLContext> getSslContextFactory()
Gets a factory that should be used for SSL context creation. If it returnsnullthen SSL is considered disabled.- Returns:
- Factory instance.
-
setSslContextFactory
public GridClientConfiguration setSslContextFactory(javax.cache.configuration.Factory<SSLContext> sslCtxFactory)
Sets SSL context factory that will be used for creation of secure connections.- Parameters:
sslCtxFactory- Context factory.- Returns:
thisfor chaining.
-
getBalancer
public GridClientLoadBalancer getBalancer()
Default balancer to be used for computational client. It can be overridden for different compute instances. By defaultGridClientRandomBalanceris used.- Returns:
- Default balancer to be used for computational client.
-
setBalancer
public GridClientConfiguration setBalancer(GridClientLoadBalancer balancer)
Sets default compute balancer.- Parameters:
balancer- Balancer to use.- Returns:
thisfor chaining.
-
getSecurityCredentialsProvider
public SecurityCredentialsProvider getSecurityCredentialsProvider()
Gets client credentials provider to authenticate with.- Returns:
- Credentials provider.
-
setSecurityCredentialsProvider
public GridClientConfiguration setSecurityCredentialsProvider(SecurityCredentialsProvider credProvider)
Sets client credentials provider used in authentication process.- Parameters:
credProvider- Client credentials provider.- Returns:
thisfor chaining.
-
getDataConfigurations
public Collection<GridClientDataConfiguration> getDataConfigurations()
Gets a collection of data configurations specified by user.- Returns:
- Collection of data configurations (possibly empty).
-
setDataConfigurations
public GridClientConfiguration setDataConfigurations(Collection<? extends GridClientDataConfiguration> dataCfgs)
Sets data configurations.- Parameters:
dataCfgs- Data configurations.- Returns:
thisfor chaining.
-
getDataConfiguration
public GridClientDataConfiguration getDataConfiguration(@Nullable @Nullable String name)
Gets data configuration for a cache with specified name.- Parameters:
name- Name of grid cache.- Returns:
- Configuration or
nullif there is not configuration for specified name.
-
setEnableMetricsCache
public GridClientConfiguration setEnableMetricsCache(boolean enableMetricsCache)
Sets flag indicating whether node and cache metrics should be cached by client.- Parameters:
enableMetricsCache-Trueif cache should be enabled.- Returns:
thisfor chaining.
-
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 tofalse.Note that topology is refreshed automatically every
getTopologyRefreshFrequency()interval, and ifisAutoFetchMetrics()enabled then metrics will be updated with that frequency.By default this value is
truewhich means that metrics will be cached on the client side.- Returns:
Trueif metrics cache is enabled,falseotherwise.
-
setEnableAttributesCache
public GridClientConfiguration setEnableAttributesCache(boolean enableAttrsCache)
Sets flag indicating whether node attributes should be cached by client.- Parameters:
enableAttrsCache-Trueif cache should be enabled.- Returns:
thisfor chaining.
-
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 tofalse.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
truewhich means that node attributes will be cached on the client side.- Returns:
Trueif attributes cache is enabled,falseotherwise.
-
setAutoFetchMetrics
public GridClientConfiguration setAutoFetchMetrics(boolean autoFetchMetrics)
Sets flag indicating whether node metrics should be fetched by client automatically.- Parameters:
autoFetchMetrics-Trueif metrics should be fetched.- Returns:
thisfor chaining.
-
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()orGridClientData.metricsAsync()methods.By default this value is
truewhich means that metrics will be fetched automatically.- Returns:
trueif client should fetch metrics on topology refresh,falseotherwise.
-
setAutoFetchAttributes
public GridClientConfiguration setAutoFetchAttributes(boolean autoFetchAttrs)
Sets flag indicating whether node attributes should be fetched by client automatically.- Parameters:
autoFetchAttrs-Trueif attributes should be fetched.- Returns:
thisfor chaining.
-
isAutoFetchAttributes
public boolean isAutoFetchAttributes()
Allows client to fetch node attributes automatically with background topology refresh.By default this value is
truewhich means that attributes will be fetched automatically.- Returns:
Trueif client should fetch attributes once on topology refresh,falseotherwise.
-
getTopologyRefreshFrequency
public long getTopologyRefreshFrequency()
Gets topology refresh frequency. Default is defined byDFLT_TOP_REFRESH_FREQconstant.- Returns:
- Topology refresh frequency.
-
setTopologyRefreshFrequency
public GridClientConfiguration setTopologyRefreshFrequency(long topRefreshFreq)
Sets topology refresh frequency. If topology cache is enabled, grid topology will be refreshed everytopRefreshFreqmilliseconds.- Parameters:
topRefreshFreq- Topology refresh frequency in milliseconds.- Returns:
thisfor chaining.
-
getMaxConnectionIdleTime
public long getMaxConnectionIdleTime()
Gets maximum amount of time that client connection can be idle before it is closed. Default is defined byDFLT_MAX_CONN_IDLE_TIMEconstant.- Returns:
- Maximum idle time in milliseconds.
-
setMaxConnectionIdleTime
public GridClientConfiguration 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.- Returns:
thisfor chaining.
-
getPingInterval
public long getPingInterval()
Gets time interval in milliseconds between ping requests. Default is defined byDFLT_PING_INTERVALconstant.Ping requests used by
GridClientProtocol.TCPprotocol to detect network failures and half-opened sockets.- Returns:
- Ping interval.
-
setPingInterval
public GridClientConfiguration setPingInterval(long pingInterval)
Sets ping interval in milliseconds.- Parameters:
pingInterval- Ping interval in milliseconds.- Returns:
thisfor chaining.
-
getPingTimeout
public long getPingTimeout()
Gets ping timeout. Default is defined byDFLT_PING_TIMEOUTconstant.Ping requests used by
GridClientProtocol.TCPprotocol 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 GridClientConfiguration setPingTimeout(long pingTimeout)
Sets ping timeout in milliseconds.- Parameters:
pingTimeout- Ping interval in milliseconds.- Returns:
thisfor chaining.
-
getExecutorService
public ExecutorService getExecutorService()
GetsExecutorServicewhere client could run asynchronous operations.When using
GridClientProtocol.TCPthis executor should be able to serve at leastRuntime.getRuntime().availableProcessors()parallel tasks.Note that this executor will be automatically shut down when client get closed.
- Returns:
ExecutorServiceinstance to use.
-
setExecutorService
public GridClientConfiguration setExecutorService(ExecutorService executor)
Sets executor service.- Parameters:
executor- Executor service to use in client.- Returns:
thisfor chaining.
-
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.GridClientBinaryMarshaller- Marshaller that supports binary objects.GridClientJdkMarshaller- JDK marshaller (not recommended).
- Returns:
- A marshaller to use.
-
setMarshaller
public GridClientConfiguration setMarshaller(GridClientMarshaller marshaller)
Sets the marshaller to use for communication.- Parameters:
marshaller- A marshaller to use.- Returns:
thisfor chaining.
-
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 GridClientConfiguration setDaemon(boolean daemon)
Set the daemon flag value. Communication threads will be created as daemons if this flag is set.- Parameters:
daemon- Daemon flag.- Returns:
thisfor chaining.
-
isDaemon
public boolean isDaemon()
Get the daemon flag.- Returns:
- Daemon flag.
-
getUserAttributes
public Map<String,String> getUserAttributes()
Returns user attributes which can be used on server node.- Returns:
- User attributes.
-
setUserAttributes
public GridClientConfiguration setUserAttributes(Map<String,String> userAttrs)
Sets user attributes which can be used to send additional info to the server nodes. Sent attributes can be accessed on server nodes fromGridRestRequestorClientListenerAbstractConnectionContext(depends on client type).- Parameters:
userAttrs- User attributes.- Returns:
thisfor chaining.
-
-