com.hazelcast.core
Interface HazelcastInstance

All Known Subinterfaces:
HazelcastConnection
All Known Implementing Classes:
HazelcastClientInstanceImpl, HazelcastClientProxy, HazelcastConnectionImpl, HazelcastInstanceImpl, HazelcastInstanceProxy

public interface HazelcastInstance

Hazelcast instance. Each Hazelcast instance is a member (node) in a cluster. Multiple Hazelcast instances can be created on a JVM. Each Hazelcast instance has its own socket, threads.

See Also:
Hazelcast.newHazelcastInstance(Config config)

Method Summary
 String 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.
 IAtomicLong getAtomicLong(String name)
          Creates cluster-wide atomic long.
<E> IAtomicReference<E>
getAtomicReference(String name)
          Creates cluster-wide atomic reference.
 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.
 ICountDownLatch getCountDownLatch(String name)
          Creates cluster-wide CountDownLatch.
<T extends DistributedObject>
T
getDistributedObject(String serviceName, Object id)
          Deprecated. use getDistributedObject(String, String) instead.
<T extends DistributedObject>
T
getDistributedObject(String serviceName, String name)
           
 Collection<DistributedObject> getDistributedObjects()
          Returns all DistributedObject's such as; queue, map, set, list, topic, lock, multimap.
 IExecutorService getExecutorService(String name)
          Returns the distributed executor service for the given name.
 IdGenerator getIdGenerator(String name)
          Creates cluster-wide unique IDs.
 JobTracker getJobTracker(String name)
          Returns the job tracker instance with the specified name.
 LifecycleService getLifecycleService()
          Returns the lifecycle service for this instance.
<E> IList<E>
getList(String name)
          Returns the distributed list instance with the specified name.
 Endpoint getLocalEndpoint()
          Returns the local Endpoint which this HazelcastInstance belongs to.
 ILock getLock(Object key)
          Deprecated. will be removed in Hazelcast 3.2. Use getLock(String) instead.
 ILock getLock(String key)
          Returns the distributed lock instance for the specified key object.
 LoggingService getLoggingService()
          Returns the logging service of this Hazelcast instance.
<K,V> IMap<K,V>
getMap(String name)
          Returns the distributed map instance with the specified name.
<K,V> MultiMap<K,V>
getMultiMap(String name)
          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.
<E> IQueue<E>
getQueue(String name)
          Returns the distributed queue instance with the specified name.
<K,V> ReplicatedMap<K,V>
getReplicatedMap(String name)
          Returns the replicated map instance with the specified name.
 ISemaphore getSemaphore(String name)
          Creates cluster-wide semaphore.
<E> ISet<E>
getSet(String name)
          Returns the distributed set instance with the specified name.
<E> ITopic<E>
getTopic(String name)
          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.
 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(String registrationId)
          Removes the specified Distributed Object listener.
 void shutdown()
          Shuts down this HazelcastInstance.
 

Method Detail

getName

String getName()
Returns the name of this Hazelcast instance

Returns:
name of this Hazelcast instance

getQueue

<E> IQueue<E> getQueue(String name)
Returns the distributed queue instance with the specified name.

Parameters:
name - name of the distributed queue
Returns:
distributed queue instance with the specified name

getTopic

<E> ITopic<E> getTopic(String name)
Returns the distributed topic instance with the specified name.

Parameters:
name - name of the distributed topic
Returns:
distributed topic instance with the specified name

getSet

<E> ISet<E> getSet(String name)
Returns the distributed set instance with the specified name.

Parameters:
name - name of the distributed set
Returns:
distributed set instance with the specified name

getList

<E> IList<E> getList(String name)
Returns the distributed list instance with the specified name. Index based operations on the list are not supported.

Parameters:
name - name of the distributed list
Returns:
distributed list instance with the specified name

getMap

<K,V> IMap<K,V> getMap(String name)
Returns the distributed map instance with the specified name.

Parameters:
name - name of the distributed map
Returns:
distributed map instance with the specified name

getReplicatedMap

<K,V> ReplicatedMap<K,V> getReplicatedMap(String name)
Returns the replicated map instance with the specified name.

Parameters:
name - name of the distributed map
Returns:
replicated map instance with specified name
Since:
3.2

getJobTracker

JobTracker getJobTracker(String name)
Returns the job tracker instance with the specified name.

Parameters:
name - name of the job tracker
Returns:
job tracker instance with the specified name
Since:
3.2

getMultiMap

<K,V> MultiMap<K,V> getMultiMap(String name)
Returns the distributed multimap instance with the specified name.

Parameters:
name - name of the distributed multimap
Returns:
distributed multimap instance with the specified name

getLock

ILock getLock(String key)
Returns the distributed lock instance for the specified key object. The specified object is considered to be the key for this lock. So keys are considered equals cluster-wide as long as they are serialized to the same byte array such as String, long, Integer.

Locks are fail-safe. If a member holds a lock and some of the members go down, the cluster will keep your locks safe and available. Moreover, when a member leaves the cluster, all the locks acquired by this dead member will be removed so that these locks can be available for live members immediately.

 Lock lock = hazelcastInstance.getLock("PROCESS_LOCK");
 lock.lock();
 try {
   // process
 } finally {
   lock.unlock();
 }
 

Parameters:
key - key of the lock instance
Returns:
distributed lock instance for the specified key.

getLock

@Deprecated
ILock getLock(Object key)
Deprecated. will be removed in Hazelcast 3.2. Use getLock(String) instead.


getCluster

Cluster getCluster()
Returns the Cluster that this Hazelcast instance is part of. Cluster interface allows you to add a listener for membership events and to learn more about the cluster that this Hazelcast instance is part of.

Returns:
the cluster that this Hazelcast instance is part of

getLocalEndpoint

Endpoint getLocalEndpoint()
Returns the local Endpoint which this HazelcastInstance belongs to.

Returned endpoint will be a Member instance for cluster nodes and a Client instance for clients.

Returns:
the local Endpoint which this HazelcastInstance belongs to
See Also:
Member, Client

getExecutorService

IExecutorService getExecutorService(String name)
Returns the distributed executor service for the given name. Executor service enables you to run your Runnables and Callables on the Hazelcast cluster.

Note: Note that it don't support invokeAll/Any and don't have standard shutdown behavior

Parameters:
name - name of the executor service
Returns:
the distributed executor service for the given name

executeTransaction

<T> T executeTransaction(TransactionalTask<T> task)
                     throws TransactionException
Executes the given transactional task in current thread using default options and returns the result of the task.

Type Parameters:
T - return type of task
Parameters:
task - the transactional task to be executed
Returns:
result of the transactional task
Throws:
TransactionException - if an error occurs during transaction.

executeTransaction

<T> T executeTransaction(TransactionOptions options,
                         TransactionalTask<T> task)
                     throws TransactionException
Executes the given transactional task in current thread using given options and returns the result of the task.

Type Parameters:
T - return type of task
Parameters:
options - options for this transactional task
task - task to be executed
Returns:
result of the transactional task
Throws:
TransactionException - if an error occurs during transaction.

newTransactionContext

TransactionContext newTransactionContext()
Creates a new TransactionContext associated with the current thread using default options.

Returns:
new TransactionContext associated with the current thread

newTransactionContext

TransactionContext newTransactionContext(TransactionOptions options)
Creates a new TransactionContext associated with the current thread with given options.

Parameters:
options - options for this transaction
Returns:
new TransactionContext associated with the current thread

getIdGenerator

IdGenerator getIdGenerator(String name)
Creates cluster-wide unique IDs. Generated IDs are long type primitive values between 0 and Long.MAX_VALUE . Id generation occurs almost at the speed of AtomicLong.incrementAndGet() . Generated IDs are unique during the life cycle of the cluster. If the entire cluster is restarted, IDs start from 0 again.

Parameters:
name - name of the IdGenerator
Returns:
IdGenerator for the given name

getAtomicLong

IAtomicLong getAtomicLong(String name)
Creates cluster-wide atomic long. Hazelcast IAtomicLong is distributed implementation of java.util.concurrent.atomic.AtomicLong.

Parameters:
name - name of the IAtomicLong proxy
Returns:
IAtomicLong proxy for the given name

getAtomicReference

<E> IAtomicReference<E> getAtomicReference(String name)
Creates cluster-wide atomic reference. Hazelcast IAtomicReference is distributed implementation of java.util.concurrent.atomic.AtomicReference.

Parameters:
name - name of the IAtomicReference proxy
Returns:
IAtomicReference proxy for the given name

getCountDownLatch

ICountDownLatch getCountDownLatch(String name)
Creates cluster-wide CountDownLatch. Hazelcast ICountDownLatch is distributed implementation of java.util.concurrent.CountDownLatch.

Parameters:
name - name of the ICountDownLatch proxy
Returns:
ICountDownLatch proxy for the given name

getSemaphore

ISemaphore getSemaphore(String name)
Creates cluster-wide semaphore. Hazelcast ISemaphore is distributed implementation of java.util.concurrent.Semaphore.

Parameters:
name - name of the ISemaphore proxy
Returns:
ISemaphore proxy for the given name

getDistributedObjects

Collection<DistributedObject> getDistributedObjects()
Returns all DistributedObject's such as; queue, map, set, list, topic, lock, multimap.

Returns:
the collection of instances created by Hazelcast.

addDistributedObjectListener

String addDistributedObjectListener(DistributedObjectListener distributedObjectListener)
Adds a Distributed Object listener which will be notified when a new DistributedObject will be created or destroyed.

Parameters:
distributedObjectListener - instance listener
Returns:
returns registration id.

removeDistributedObjectListener

boolean removeDistributedObjectListener(String registrationId)
Removes the specified Distributed Object listener. Returns silently if the specified instance listener does not exist.

Parameters:
registrationId - Id of listener registration.
Returns:
true if registration is removed, false otherwise

getConfig

Config getConfig()
Returns the configuration of this Hazelcast instance.

Returns:
configuration of this Hazelcast instance

getPartitionService

PartitionService getPartitionService()
Returns the partition service of this Hazelcast instance. InternalPartitionService allows you to introspect current partitions in the cluster, partition the owner members, and listen for partition migration events.

Returns:
the partition service of this Hazelcast instance

getClientService

ClientService getClientService()
Returns the client service of this Hazelcast instance. Client service allows you to get information about connected clients.

Returns:
the ClientService of this Hazelcast instance.

getLoggingService

LoggingService getLoggingService()
Returns the logging service of this Hazelcast instance. LoggingService allows you to listen for LogEvents generated by Hazelcast runtime. You can log the events somewhere or take action based on the message.

Returns:
the logging service of this Hazelcast instance

getLifecycleService

LifecycleService getLifecycleService()
Returns the lifecycle service for this instance. LifecycleService allows you to shutdown this HazelcastInstance and listen for the lifecycle events.

Returns:
the lifecycle service for this instance

getDistributedObject

@Deprecated
<T extends DistributedObject> T getDistributedObject(String serviceName,
                                                                Object id)
Deprecated. use getDistributedObject(String, String) instead.

Type Parameters:
T - type of the DistributedObject
Parameters:
serviceName - name of the service
id - identifier of the object
Returns:
DistributedObject created by the service

getDistributedObject

<T extends DistributedObject> T getDistributedObject(String serviceName,
                                                     String name)
Type Parameters:
T - type of the DistributedObject
Parameters:
serviceName - name of the service
name - name of the object
Returns:
DistributedObject created by the service

getUserContext

ConcurrentMap<String,Object> getUserContext()
Returns a ConcurrentMap that can be used to add user-context to the HazelcastInstance. This can be used to store dependencies that otherwise are hard to obtain. HazelcastInstance can be obtained by implementing a 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.

Returns:
a ConcurrentMap that can be used to add user-context to the HazelcastInstance.

shutdown

void shutdown()
Shuts down this HazelcastInstance. For more information see LifecycleService.shutdown().



Copyright © 2015 Hazelcast, Inc.. All Rights Reserved.