public final class HazelcastClient extends Object
Hazelcast
class and provides the ability
the create and manage Hazelcast clients. Hazelcast clients are HazelcastInstance
implementations, so
in most cases most of the code is unaware of talking to a cluster member or a client.
ClientNetworkConfig.setSmartRouting(boolean)
.
Modifier and Type | Method and Description |
---|---|
static Collection<HazelcastInstance> |
getAllHazelcastClients()
Gets an immutable collection of all client HazelcastInstances created in this JVM.
|
static HazelcastInstance |
getHazelcastClientByName(String instanceName)
Returns an existing HazelcastClient with instanceName.
|
static HazelcastInstance |
newHazelcastClient()
Creates a new HazelcastInstance (a new client in a cluster).
|
static HazelcastInstance |
newHazelcastClient(ClientConfig config)
Creates a new HazelcastInstance (a new client in a cluster).
|
static HazelcastInstance |
newHazelcastFailoverClient()
Creates a client with cluster switch capability.
|
static HazelcastInstance |
newHazelcastFailoverClient(ClientFailoverConfig clientFailoverConfig)
Creates a client with cluster switch capability.
|
static void |
setOutOfMemoryHandler(OutOfMemoryHandler outOfMemoryHandler)
Sets OutOfMemoryHandler to be used when an OutOfMemoryError
is caught by Hazelcast Client threads.
|
static void |
shutdown(HazelcastInstance instance)
Shutdown the provided client and remove it from the managed list
|
static void |
shutdown(String instanceName)
Shutdown the provided client and remove it from the managed list
|
static void |
shutdownAll()
Shuts down all the client HazelcastInstance created in this JVM.
|
public static HazelcastInstance newHazelcastClient()
shutdownAll()
.
Hazelcast will look into two places for the configuration file:
classpath:...
path. The configuration can either be an XML or a YAML configuration, distinguished by the
suffix ('.xml' or '.yaml') of the provided configuration file's name
Examples: -Dhazelcast.client.config=C:/myhazelcastclient.xml ,
-Dhazelcast.client.config=classpath:the-hazelcast-config.yaml ,
-Dhazelcast.client.config=classpath:com/mydomain/hazelcast.xml
shutdownAll()
,
(String)
public static HazelcastInstance newHazelcastClient(ClientConfig config)
shutdownAll()
.config
- Configuration for the new HazelcastInstance (member)shutdownAll()
,
(String)
public static HazelcastInstance newHazelcastFailoverClient()
ClientFailoverConfig
when it disconnects from a cluster.
The configuration is loaded using using the following resolution mechanism:
HazelcastException
is thrownHazelcastException
- if no failover configuration is foundInvalidConfigurationException
- if the loaded failover configuration is not validpublic static HazelcastInstance newHazelcastFailoverClient(ClientFailoverConfig clientFailoverConfig)
ClientFailoverConfig
when it disconnects from a cluster.
If provided clientFailoverConfig is null
, the configuration is loaded using using the following resolution
mechanism:
HazelcastException
is thrownclientFailoverConfig
- config describing the failover configs and try countHazelcastException
- if no failover configuration is foundInvalidConfigurationException
- if the provided or the loaded failover configuration is not validpublic static HazelcastInstance getHazelcastClientByName(String instanceName)
instanceName
- Name of the HazelcastInstance (client) which can be retrieved by HazelcastInstance.getName()
public static Collection<HazelcastInstance> getAllHazelcastClients()
public static void shutdownAll()
getAllHazelcastClients()
public static void shutdown(HazelcastInstance instance)
instance
- the hazelcast client instancepublic static void shutdown(String instanceName)
instanceName
- the hazelcast client instance namepublic static void setOutOfMemoryHandler(OutOfMemoryHandler outOfMemoryHandler)
Warning: OutOfMemoryHandler may not be called although JVM throws OutOfMemoryError. Because error may be thrown from an external (user thread) thread and Hazelcast may not be informed about OutOfMemoryError.
outOfMemoryHandler
- set when an OutOfMemoryError is caught by HazelcastClient threadsOutOfMemoryError
,
OutOfMemoryHandler
Copyright © 2019 Hazelcast, Inc.. All Rights Reserved.