public interface HazelcastInstance
Instances should be shut down explicitly. See the shutdown()
method.
If the instance is a client and you don't shut it down explicitly, it will continue to run and
even connect to another live member if the one it was connected to fails.
Each Hazelcast instance has its own socket and threads.
Modifier and Type | Method and Description |
---|---|
UUID |
addDistributedObjectListener(DistributedObjectListener distributedObjectListener)
Adds a Distributed Object listener which will be notified when a
new
DistributedObject will be created or destroyed. |
<T> T |
executeTransaction(TransactionalTask<T> task)
Executes the given transactional task in current thread using default options
and returns the result of the task.
|
<T> T |
executeTransaction(TransactionOptions options,
TransactionalTask<T> task)
Executes the given transactional task in current thread using given options
and returns the result of the task.
|
ICacheManager |
getCacheManager()
Obtain the
ICacheManager that provides access to JSR-107 (JCache) caches configured on a Hazelcast cluster. |
CardinalityEstimator |
getCardinalityEstimator(String name)
Obtain a
CardinalityEstimator with the given name. |
ClientService |
getClientService()
Returns the client service of this Hazelcast instance.
|
Cluster |
getCluster()
Returns the Cluster that this Hazelcast instance is part of.
|
Config |
getConfig()
Returns the configuration of this Hazelcast instance.
|
CPSubsystem |
getCPSubsystem()
Returns the CP subsystem that offers a set of in-memory linearizable data structures
|
<T extends DistributedObject> |
getDistributedObject(String serviceName,
String name) |
Collection<DistributedObject> |
getDistributedObjects()
Returns all
DistributedObject s, that is all maps, queues,
topics, locks etc. |
DurableExecutorService |
getDurableExecutorService(String name)
Creates or returns the durable executor service for the given name.
|
IExecutorService |
getExecutorService(String name)
Creates or returns the distributed executor service for the given name.
|
FlakeIdGenerator |
getFlakeIdGenerator(String name)
Creates or returns a cluster-wide unique ID generator.
|
JetService |
getJet()
Returns a Jet service to execute distributed batch and streaming jobs.
|
LifecycleService |
getLifecycleService()
Returns the lifecycle service for this instance.
|
<E> IList<E> |
getList(String name)
Creates or returns the distributed list instance with the specified name.
|
Endpoint |
getLocalEndpoint()
Returns the local Endpoint which this HazelcastInstance belongs to.
|
LoggingService |
getLoggingService()
Returns the logging service of this Hazelcast instance.
|
<K,V> IMap<K,V> |
getMap(String name)
Creates or returns the distributed map instance with the specified name.
|
<K,V> MultiMap<K,V> |
getMultiMap(String name)
Creates or returns the distributed multimap instance with the specified name.
|
String |
getName()
Returns the name of this Hazelcast instance.
|
PartitionService |
getPartitionService()
Returns the partition service of this Hazelcast instance.
|
PNCounter |
getPNCounter(String name)
Creates or returns a
PNCounter with the given
name. |
<E> IQueue<E> |
getQueue(String name)
Creates or returns the distributed queue instance with the specified name.
|
<E> ITopic<E> |
getReliableTopic(String name)
Creates or returns the reliable topic instance with the specified name.
|
<K,V> ReplicatedMap<K,V> |
getReplicatedMap(String name)
Creates or returns the replicated map instance with the specified name.
|
<E> Ringbuffer<E> |
getRingbuffer(String name)
Creates or returns the distributed Ringbuffer instance with the specified name.
|
IScheduledExecutorService |
getScheduledExecutorService(String name)
Creates or returns the
IScheduledExecutorService scheduled executor service for the given name. |
<E> ISet<E> |
getSet(String name)
Creates or returns the distributed set instance with the specified name.
|
SplitBrainProtectionService |
getSplitBrainProtectionService()
Returns the split brain protection service of this Hazelcast instance.
|
SqlService |
getSql()
Returns a service to execute distributed SQL queries.
|
<E> ITopic<E> |
getTopic(String name)
Creates or returns the distributed topic instance with the specified name.
|
ConcurrentMap<String,Object> |
getUserContext()
Returns a ConcurrentMap that can be used to add user-context to the HazelcastInstance.
|
HazelcastXAResource |
getXAResource()
Gets xaResource which will participate in XATransaction.
|
TransactionContext |
newTransactionContext()
Creates a new TransactionContext associated with the current thread using default options.
|
TransactionContext |
newTransactionContext(TransactionOptions options)
Creates a new TransactionContext associated with the current thread with given options.
|
boolean |
removeDistributedObjectListener(UUID registrationId)
Removes the specified Distributed Object listener.
|
void |
shutdown()
Shuts down this HazelcastInstance.
|
@Nonnull String getName()
@Nonnull <E> IQueue<E> getQueue(@Nonnull String name)
E
- queue item typename
- name of the distributed queue@Nonnull <E> ITopic<E> getTopic(@Nonnull String name)
E
- the type of the topic messagename
- name of the distributed topic@Nonnull <E> ISet<E> getSet(@Nonnull String name)
E
- the type of elements maintained by the setname
- name of the distributed set@Nonnull <E> IList<E> getList(@Nonnull String name)
E
- the type of elements maintained by the listname
- name of the distributed list@Nonnull <K,V> IMap<K,V> getMap(@Nonnull String name)
K
- key typeV
- value typename
- name of the distributed map@Nonnull <K,V> ReplicatedMap<K,V> getReplicatedMap(@Nonnull String name)
K
- the type of keys maintained by the replicated mapV
- the type of mapped valuesname
- name of the distributed mapReplicatedMapCantBeCreatedOnLiteMemberException
- if it is called on a lite member@Nonnull <K,V> MultiMap<K,V> getMultiMap(@Nonnull String name)
K
- type of the multimap keyV
- type of the multimap valuename
- name of the distributed multimap@Nonnull <E> Ringbuffer<E> getRingbuffer(@Nonnull String name)
E
- the type of the elements that the Ringbuffer containsname
- name of the distributed Ringbuffer@Nonnull <E> ITopic<E> getReliableTopic(@Nonnull String name)
E
- the type of the topic messagename
- name of the reliable topic@Nonnull Cluster getCluster()
@Nonnull IExecutorService getExecutorService(@Nonnull String name)
Runnable
s and Callable
s
on the Hazelcast cluster.
Note: Note that it doesn't support invokeAll/Any
and doesn't have standard shutdown behavior
name
- name of the executor service@Nonnull DurableExecutorService getDurableExecutorService(@Nonnull String name)
Runnable
s and Callable
s
on the Hazelcast cluster.
Note: Note that it doesn't support invokeAll/Any
and doesn't have standard shutdown behavior
name
- name of the executor service<T> T executeTransaction(@Nonnull TransactionalTask<T> task) throws TransactionException
T
- return type of tasktask
- the transactional task to be executedTransactionException
- if an error occurs during transaction.<T> T executeTransaction(@Nonnull TransactionOptions options, @Nonnull TransactionalTask<T> task) throws TransactionException
T
- return type of taskoptions
- options for this transactional tasktask
- task to be executedTransactionException
- if an error occurs during transaction.TransactionContext newTransactionContext()
TransactionContext newTransactionContext(@Nonnull TransactionOptions options)
options
- options for this transaction@Nonnull FlakeIdGenerator getFlakeIdGenerator(@Nonnull String name)
long
primitive values
and are k-ordered (roughly ordered). IDs are in the range from 0
to Long.MAX_VALUE
.
The IDs contain timestamp component and a node ID component, which is assigned when the member
joins the cluster. This allows the IDs to be ordered and unique without any coordination between
members, which makes the generator safe even in split-brain scenario (for caveats,
see here
).
For more details and caveats, see class documentation for FlakeIdGenerator
.
name
- name of the FlakeIdGenerator
Collection<DistributedObject> getDistributedObjects()
DistributedObject
s, that is all maps, queues,
topics, locks etc.
The results are returned on a best-effort basis. The result might miss just-created objects and contain just-deleted objects. An existing object can also be missing from the list occasionally. One cluster member is queried to obtain the list.
UUID addDistributedObjectListener(@Nonnull DistributedObjectListener distributedObjectListener)
DistributedObject
will be created or destroyed.distributedObjectListener
- instance listenerboolean removeDistributedObjectListener(@Nonnull UUID registrationId)
registrationId
- ID of listener registrationtrue
if registration is removed, false
otherwise@Nonnull Config getConfig()
@Nonnull PartitionService getPartitionService()
@Nonnull SplitBrainProtectionService getSplitBrainProtectionService()
Split brain protection service can be used to retrieve split brain protection callbacks which let you to notify split brain protection results of your own to the cluster split brain protection service.
@Nonnull ClientService getClientService()
ClientService
of this Hazelcast instance.@Nonnull LoggingService getLoggingService()
LoggingService allows you to listen for LogEvents generated by Hazelcast runtime. You can log the events somewhere or take action based on the message.
@Nonnull LifecycleService getLifecycleService()
LifecycleService allows you to shutdown this HazelcastInstance and listen for the lifecycle events.
@Nonnull <T extends DistributedObject> T getDistributedObject(@Nonnull String serviceName, @Nonnull String name)
T
- type of the DistributedObjectserviceName
- name of the servicename
- name of the object@Nonnull ConcurrentMap<String,Object> getUserContext()
HazelcastInstanceAware
interface when submitting a Runnable/Callable to
Hazelcast ExecutorService. By storing the dependencies in the user-context, they can be retrieved as soon
as you have a reference to the HazelcastInstance.
This structure is purely local and Hazelcast remains agnostic abouts its content.
@Nonnull HazelcastXAResource getXAResource()
ICacheManager getCacheManager()
ICacheManager
that provides access to JSR-107 (JCache) caches configured on a Hazelcast cluster.
Note that this method does not return a JCache CacheManager
; to obtain a JCache
CacheManager
use JCache standard API.
ICacheManager
ICacheManager
@Nonnull CardinalityEstimator getCardinalityEstimator(@Nonnull String name)
CardinalityEstimator
with the given name.
The estimator can be used to efficiently estimate the cardinality of unique entities in big data sets, without the need of storing them.
The estimator is based on a HyperLogLog++ data-structure.
name
- the name of the estimatorCardinalityEstimator
@Nonnull PNCounter getPNCounter(@Nonnull String name)
PNCounter
with the given
name.
The PN counter can be used as a counter with strong eventual consistency guarantees - if operations to the counters stop, the counter values of all replicas that can communicate with each other should eventually converge to the same value.
name
- the name of the PN counterPNCounter
@Nonnull IScheduledExecutorService getScheduledExecutorService(@Nonnull String name)
IScheduledExecutorService
scheduled executor service for the given name.
ScheduledExecutor service enables you to schedule your Runnable
s and Callable
s
on the Hazelcast cluster.name
- name of the executor service@Nonnull CPSubsystem getCPSubsystem()
@Nonnull SqlService getSql()
SqlService
@Nonnull JetService getJet()
JetService
void shutdown()
LifecycleService.shutdown()
.Copyright © 2023 Hazelcast, Inc.. All rights reserved.