Class GridClientImpl
- java.lang.Object
-
- org.apache.ignite.internal.client.impl.GridClientImpl
-
- All Implemented Interfaces:
AutoCloseable,GridClient,GridClientBeforeNodeStart
public class GridClientImpl extends Object implements GridClient, GridClientBeforeNodeStart
Client implementation.
-
-
Field Summary
Fields Modifier and Type Field Description protected GridClientConfigurationcfgClient configuration.protected GridClientConnectionManagerconnMgrConnection manager.protected GridClientTopologytopTopology.
-
Constructor Summary
Constructors Constructor Description GridClientImpl(UUID id, GridClientConfiguration cfg0, boolean routerClient, boolean beforeNodeStart)Creates a new client based on a given configuration.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddTopologyListener(GridClientTopologyListener lsnr)Adds topology listener.@Nullable GridClientNodeStateBeforeStartbeforeStartState()Getting a client projection of node state before its start.GridClientExceptioncheckLastError()Check for last topology errors.voidclose()Closes client instance.GridClientComputecompute()Gets a default compute projection.booleanconnected()Indicates whether client is connected to remote Grid.GridClientConnectionconnection()Getting a client connection without topology information.GridClientConnectionManagerconnectionManager()GridClientDatadata(@Nullable String cacheName)Gets a data projection for grid cache with name cacheName.UUIDid()Gets a unique client identifier.GridClientConnectionManagernewConnectionManager(@Nullable Byte marshId, boolean routerClient)voidremoveTopologyListener(GridClientTopologyListener lsnr)Removes previously added topology listener.GridClientClusterStatestate()Get client cluster state projection, for perform activate/deactivate operation on cluster.voidstop(boolean waitCompletion)Closes client.GridClientTopologytopology()Gets topology instance.Collection<GridClientTopologyListener>topologyListeners()Gets an unmodifiable snapshot of topology listeners list.StringtoString()
-
-
-
Field Detail
-
cfg
protected final GridClientConfiguration cfg
Client configuration.
-
top
protected final GridClientTopology top
Topology.
-
connMgr
protected final GridClientConnectionManager connMgr
Connection manager.
-
-
Constructor Detail
-
GridClientImpl
public GridClientImpl(UUID id, GridClientConfiguration cfg0, boolean routerClient, boolean beforeNodeStart) throws GridClientException
Creates a new client based on a given configuration. IfbeforeNodeStart == true, topology will not be received/updated, and there will also be errors when trying to work with topology, compute, state and cache.- Parameters:
id- Client identifier.cfg0- Client configuration.routerClient- Router client flag.beforeNodeStart- Connecting to a node before it start.- Throws:
GridClientException- If client configuration is incorrect.GridServerUnreachableException- If none of the servers specified in configuration can be reached.
-
-
Method Detail
-
id
public UUID id()
Gets a unique client identifier. This identifier is generated by factory on client creation and used in identification and authentication procedure on server node.- Specified by:
idin interfaceGridClient- Specified by:
idin interfaceGridClientBeforeNodeStart- Returns:
- Generated client id.
-
stop
public void stop(boolean waitCompletion)
Closes client.- Parameters:
waitCompletion- Iftruewill wait for all pending requests to be proceeded.
-
data
public GridClientData data(@Nullable @Nullable String cacheName) throws GridClientException
Gets a data projection for grid cache with name cacheName. If no data configuration with given name was provided at client startup, an exception will be thrown.- Specified by:
datain interfaceGridClient- Parameters:
cacheName- Grid cache name for which data projection should be obtained.- Returns:
- Data projection for grid cache with name cacheName.
- Throws:
GridClientException- If client was closed or no configuration with given name was provided.
-
compute
public GridClientCompute compute()
Gets a default compute projection. Default compute projection will include all nodes in remote grid. Selection of node that will be connected to perform operations will be done according toGridClientLoadBalancerprovided in client configuration or according to affinity if projection call involves affinity key.More restricted projection configurations may be created with
GridClientComputemethods.- Specified by:
computein interfaceGridClient- Returns:
- Default compute projection.
- See Also:
GridClientCompute
-
state
public GridClientClusterState state()
Get client cluster state projection, for perform activate/deactivate operation on cluster.- Specified by:
statein interfaceGridClient- Returns:
- Cluster state projection.
- See Also:
GridClientClusterState
-
addTopologyListener
public void addTopologyListener(GridClientTopologyListener lsnr)
Adds topology listener. Remote grid topology is refreshed everyGridClientConfiguration.getTopologyRefreshFrequency()milliseconds. If any node was added or removed, a listener will be notified.- Specified by:
addTopologyListenerin interfaceGridClient- Parameters:
lsnr- Listener to add.
-
removeTopologyListener
public void removeTopologyListener(GridClientTopologyListener lsnr)
Removes previously added topology listener.- Specified by:
removeTopologyListenerin interfaceGridClient- Parameters:
lsnr- Listener to remove.
-
topologyListeners
public Collection<GridClientTopologyListener> topologyListeners()
Gets an unmodifiable snapshot of topology listeners list.- Specified by:
topologyListenersin interfaceGridClient- Returns:
- List of topology listeners.
-
connected
public boolean connected()
Indicates whether client is connected to remote Grid. In other words it allow to determine if client is able to communicate with Grid right now. If it can't all methods on Compute and Data projections throwGridClientDisconnectedException.Connection status is updated in background together with topology update. See
GridClientConfiguration.getTopologyRefreshFrequency()for more details on how background topology update works.Note that due to asynchronous nature of topology update and connectivity detection this method gives no guarantees for subsequent calls for projections methods. It can be used only fo diagnostic and monitoring purposes.
- Specified by:
connectedin interfaceGridClient- Specified by:
connectedin interfaceGridClientBeforeNodeStart- Returns:
- Whether client is connected to remote Grid.
-
close
public void close()
Closes client instance. This method is identical toGridClientFactory.stop(clientId).The method is invoked automatically on objects managed by the
try-with-resourcesstatement.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceGridClient- Specified by:
closein interfaceGridClientBeforeNodeStart
-
topology
public GridClientTopology topology()
Gets topology instance.- Returns:
- Topology instance.
-
checkLastError
public GridClientException checkLastError()
Check for last topology errors.- Specified by:
checkLastErrorin interfaceGridClient- Specified by:
checkLastErrorin interfaceGridClientBeforeNodeStart- Returns:
Exceptionif client was not connected.
-
beforeStartState
@Nullable public @Nullable GridClientNodeStateBeforeStart beforeStartState()
Getting a client projection of node state before its start.- Specified by:
beforeStartStatein interfaceGridClientBeforeNodeStart- Returns:
- Projection of node state before its start.
- See Also:
GridClientNodeStateBeforeStart
-
connectionManager
public GridClientConnectionManager connectionManager()
- Returns:
- Connection manager.
-
newConnectionManager
public GridClientConnectionManager newConnectionManager(@Nullable @Nullable Byte marshId, boolean routerClient) throws GridClientException
- Returns:
- New connection manager based on current client settings.
- Throws:
GridClientException- If failed to start connection server.
-
connection
public GridClientConnection connection() throws GridClientException, InterruptedException
Getting a client connection without topology information.- Returns:
- Client connection.
- Throws:
GridClientException- If failed.InterruptedException
-
-