com.hazelcast.core
Class Hazelcast

java.lang.Object
  extended by com.hazelcast.core.Hazelcast

public final class Hazelcast
extends Object

Factory for all of the Hazelcast data and execution components such as maps, queues, multimaps, topics and executor service.

If not started already, Hazelcast member (HazelcastInstance) will start automatically if any of the functions is called on Hazelcast.


Method Summary
static void addInstanceListener(InstanceListener instanceListener)
          Deprecated. as of version 2.2
static Set<HazelcastInstance> getAllHazelcastInstances()
          Returns all active/running HazelcastInstances on this JVM.
static AtomicNumber getAtomicNumber(String name)
          Deprecated. as of version 2.2
static Cluster getCluster()
          Deprecated. as of version 2.2
static Config getConfig()
          Deprecated. as of version 2.2
static ICountDownLatch getCountDownLatch(String name)
          Deprecated. as of version 2.2
static HazelcastInstance getDefaultInstance()
          Deprecated. as of version 2.2
static ExecutorService getExecutorService()
          Deprecated. as of version 2.2
static ExecutorService getExecutorService(String name)
          Deprecated. as of version 2.2
static HazelcastInstance getHazelcastInstanceByName(String instanceName)
          Returns an existing HazelcastInstance with instanceName.
static IdGenerator getIdGenerator(String name)
          Deprecated. as of version 2.2
static Collection<Instance> getInstances()
          Deprecated. as of version 2.2
static LifecycleService getLifecycleService()
          Deprecated. as of version 2.2
static
<E> IList<E>
getList(String name)
          Deprecated. as of version 2.2
static ILock getLock(Object key)
          Deprecated. as of version 2.2
static LoggingService getLoggingService()
          Deprecated. as of version 2.2
static
<K,V> IMap<K,V>
getMap(String name)
          Deprecated. as of version 2.2
static
<K,V> MultiMap<K,V>
getMultiMap(String name)
          Deprecated. as of version 2.2
static PartitionService getPartitionService()
          Deprecated. as of version 2.2
static
<E> IQueue<E>
getQueue(String name)
          Deprecated. as of version 2.2
static ISemaphore getSemaphore(String name)
          Deprecated. as of version 2.2
static
<E> ISet<E>
getSet(String name)
          Deprecated. as of version 2.2
static
<E> ITopic<E>
getTopic(String name)
          Deprecated. as of version 2.2
static Transaction getTransaction()
          Deprecated. as of version 2.2
static HazelcastInstance init(Config config)
          Deprecated. as of version 2.2
static HazelcastInstance newHazelcastInstance()
          Creates a new HazelcastInstance (a new node in a cluster).
static HazelcastInstance newHazelcastInstance(Config config)
          Creates a new HazelcastInstance (a new node in a cluster).
static HazelcastInstance newLiteMemberHazelcastInstance()
          Creates a new HazelcastInstance Lite Member (a new node in a cluster).
static void removeInstanceListener(InstanceListener instanceListener)
          Deprecated. as of version 2.2
static void restart()
          Deprecated. as of version 1.9
static void setOutOfMemoryHandler(OutOfMemoryHandler outOfMemoryHandler)
          Sets OutOfMemoryHandler to be used when an OutOfMemoryError is caught by Hazelcast threads.
static void shutdown()
          Deprecated. as of version 1.9
static void shutdownAll()
          Shuts down all running Hazelcast Instances on this JVM, including the default one if it is running.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

init

@Deprecated
public static HazelcastInstance init(Config config)
Deprecated. as of version 2.2

Initializes the default Hazelcast instance with the specified configuration. This method should be called before calling any other methods.

Parameters:
config - configuration for this Hazelcast instance.
Returns:
the default instance
Throws:
IllegalStateException - if this instance is already initialized
See Also:
newHazelcastInstance(com.hazelcast.config.Config), getHazelcastInstanceByName(String), getAllHazelcastInstances()

getDefaultInstance

@Deprecated
public static HazelcastInstance getDefaultInstance()
Deprecated. as of version 2.2

Returns the default Hazelcast instance, starts it with the default configuration, if not already started.

Returns:
the default Hazelcast instance
See Also:
newHazelcastInstance(com.hazelcast.config.Config), getHazelcastInstanceByName(String), getAllHazelcastInstances()

getQueue

@Deprecated
public static <E> IQueue<E> getQueue(String name)
Deprecated. as of version 2.2

Returns the distributed queue instance with the specified name.

Parameters:
name - name of the distributed queue
Returns:
distributed queue instance with the specified name
See Also:
newHazelcastInstance(com.hazelcast.config.Config), HazelcastInstance.getQueue(String)

getTopic

@Deprecated
public static <E> ITopic<E> getTopic(String name)
Deprecated. as of version 2.2

Returns the distributed topic instance with the specified name.

Parameters:
name - name of the distributed topic
Returns:
distributed topic instance with the specified name
See Also:
newHazelcastInstance(com.hazelcast.config.Config), HazelcastInstance.getTopic(String)

getSet

@Deprecated
public static <E> ISet<E> getSet(String name)
Deprecated. as of version 2.2

Returns the distributed set instance with the specified name.

Parameters:
name - name of the distributed set
Returns:
distributed set instance with the specified name
See Also:
newHazelcastInstance(com.hazelcast.config.Config), HazelcastInstance.getSet(String)

getList

@Deprecated
public static <E> IList<E> getList(String name)
Deprecated. as of version 2.2

Returns the distributed list instance with the specified name.

Parameters:
name - name of the distributed list
Returns:
distributed list instance with the specified name
See Also:
newHazelcastInstance(com.hazelcast.config.Config), HazelcastInstance.getList(String)

getMap

@Deprecated
public static <K,V> IMap<K,V> getMap(String name)
Deprecated. as of version 2.2

Returns the distributed map instance with the specified name.

Parameters:
name - name of the distributed map
Returns:
distributed map instance with the specified name
See Also:
newHazelcastInstance(com.hazelcast.config.Config), HazelcastInstance.getMap(String)

getMultiMap

@Deprecated
public static <K,V> MultiMap<K,V> getMultiMap(String name)
Deprecated. as of version 2.2

Returns the distributed multimap instance with the specified name.

Parameters:
name - name of the distributed multimap
Returns:
distributed multimap instance with the specified name
See Also:
newHazelcastInstance(com.hazelcast.config.Config), HazelcastInstance.getMultiMap(String)

getLock

@Deprecated
public static ILock getLock(Object key)
Deprecated. as of version 2.2

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, 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 = Hazelcast.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.
See Also:
newHazelcastInstance(com.hazelcast.config.Config), HazelcastInstance.getLock(Object)

getCluster

@Deprecated
public static Cluster getCluster()
Deprecated. as of version 2.2

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

Returns:
cluster that this Hazelcast instance is part of
See Also:
newHazelcastInstance(com.hazelcast.config.Config), HazelcastInstance.getCluster()

getExecutorService

@Deprecated
public static ExecutorService getExecutorService()
Deprecated. as of version 2.2

Returns the default distributed executor service. Executor service enables you to run your Runnables and Callables on the Hazelcast cluster. Note that it don't support invokeAll/Any and don't have standard shutdown behavior

Returns:
distributed executor service of this Hazelcast instance
See Also:
newHazelcastInstance(com.hazelcast.config.Config), HazelcastInstance.getExecutorService()

getExecutorService

@Deprecated
public static ExecutorService getExecutorService(String name)
Deprecated. as of version 2.2

Returns the distributed executor service for the given name.

Parameters:
name - name of the executor service
Returns:
executor service for the given name
See Also:
newHazelcastInstance(com.hazelcast.config.Config), HazelcastInstance.getExecutorService(String)

getTransaction

@Deprecated
public static Transaction getTransaction()
Deprecated. as of version 2.2

Returns the transaction instance associated with the current thread, creates a new one if it wasn't already.

Transaction doesn't start until you call transaction.begin() and if a transaction is started then all transactional Hazelcast operations are automatically transactional.

  Map map = Hazelcast.getMap("mymap");
  Transaction txn = Hazelcast.getTransaction();
  txn.begin();
  try {
    map.put ("key", "value");
    txn.commit();
  }catch (Exception e) {
    txn.rollback();
  }
 
Isolation is always REPEATABLE_READ . If you are in a transaction, you can read the data in your transaction and the data that is already committed and if not in a transaction, you can only read the committed data. Implementation is different for queue and map/set. For queue operations (offer,poll), offered and/or polled objects are copied to the next member in order to safely commit/rollback. For map/set, Hazelcast first acquires the locks for the write operations (put, remove) and holds the differences (what is added/removed/updated) locally for each transaction. When transaction is set to commit, Hazelcast will release the locks and apply the differences. When rolling back, Hazelcast will simply releases the locks and discard the differences. Transaction instance is attached to the current thread and each Hazelcast operation checks if the current thread holds a transaction, if so, operation will be transaction aware. When transaction is committed, rolled back or timed out, it will be detached from the thread holding it.

Returns:
transaction for the current thread
See Also:
newHazelcastInstance(com.hazelcast.config.Config), HazelcastInstance.getTransaction()

getAtomicNumber

@Deprecated
public static AtomicNumber getAtomicNumber(String name)
Deprecated. as of version 2.2

Creates cluster-wide atomic long. Hazelcast AtomicNumber is a distributed implementation of java.util.concurrent.atomic.AtomicLong.

Parameters:
name - of the AtomicNumber proxy
Returns:
AtomicNumber proxy instance
See Also:
newHazelcastInstance(com.hazelcast.config.Config), HazelcastInstance.getAtomicNumber(String)

getCountDownLatch

@Deprecated
public static ICountDownLatch getCountDownLatch(String name)
Deprecated. as of version 2.2

Creates a cluster-wide CountDownLatch. Hazelcast ICountDownLatch is a distributed implementation of java.util.concurrent.CountDownLatch.

Parameters:
name - of the distributed CountDownLatch
Returns:
ICountDownLatch proxy instance
See Also:
newHazelcastInstance(com.hazelcast.config.Config), HazelcastInstance.getCountDownLatch(String)

getSemaphore

@Deprecated
public static ISemaphore getSemaphore(String name)
Deprecated. as of version 2.2

Creates a cluster-wide semaphore. Hazelcast ISemaphore is a distributed implementation of java.util.concurrent.Semaphore.

Parameters:
name - of the distributed Semaphore
Returns:
ISemaphore proxy instance
See Also:
newHazelcastInstance(com.hazelcast.config.Config), HazelcastInstance.getSemaphore(String)

getIdGenerator

@Deprecated
public static IdGenerator getIdGenerator(String name)
Deprecated. as of version 2.2

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 -
Returns:
IdGenerator proxy instance
See Also:
newHazelcastInstance(com.hazelcast.config.Config), HazelcastInstance.getIdGenerator(String)

shutdown

@Deprecated
public static void shutdown()
Deprecated. as of version 1.9

Detaches this member from the cluster. It doesn't shutdown the entire cluster, it shuts down this local member only.

See Also:
HazelcastInstance.getLifecycleService(), LifecycleService.shutdown()

shutdownAll

public static void shutdownAll()
Shuts down all running Hazelcast Instances on this JVM, including the default one if it is running. It doesn't shutdown all members of the cluster but just the ones running on this JVM.

See Also:
newHazelcastInstance(Config)

restart

@Deprecated
public static void restart()
Deprecated. as of version 1.9

Detaches this member from the cluster first and then restarts it as a new member.

See Also:
HazelcastInstance##getLifecycleService(), LifecycleService.restart()

getInstances

@Deprecated
public static Collection<Instance> getInstances()
Deprecated. as of version 2.2

Returns all queue, map, set, list, topic, lock, multimap instances created by Hazelcast.

Returns:
the collection of instances created by Hazelcast.
See Also:
newHazelcastInstance(com.hazelcast.config.Config), HazelcastInstance.getInstances()

addInstanceListener

@Deprecated
public static void addInstanceListener(InstanceListener instanceListener)
Deprecated. as of version 2.2

Add a instance listener which will be notified when a new instance such as map, queue, multimap, topic, lock is added or removed.

Parameters:
instanceListener - instance listener
See Also:
newHazelcastInstance(com.hazelcast.config.Config), HazelcastInstance.addInstanceListener(InstanceListener)

removeInstanceListener

@Deprecated
public static void removeInstanceListener(InstanceListener instanceListener)
Deprecated. as of version 2.2

Removes the specified instance listener. Returns silently if specified instance listener doesn't exist.

Parameters:
instanceListener - instance listener to remove
See Also:
newHazelcastInstance(com.hazelcast.config.Config), HazelcastInstance.removeInstanceListener(InstanceListener)

newHazelcastInstance

public static HazelcastInstance newHazelcastInstance(Config config)
Creates a new HazelcastInstance (a new node in a cluster). This method allows you to create and run multiple instances of Hazelcast cluster members on the same JVM.

To shutdown all running HazelcastInstances (all members on this JVM) call shutdownAll().

Parameters:
config - Configuration for the new HazelcastInstance (member)
Returns:
new HazelcastInstance
See Also:
shutdownAll(), getHazelcastInstanceByName(String)

newHazelcastInstance

public static HazelcastInstance newHazelcastInstance()
Creates a new HazelcastInstance (a new node in a cluster). This method allows you to create and run multiple instances of Hazelcast cluster members on the same JVM.

To shutdown all running HazelcastInstances (all members on this JVM) call shutdownAll(). Hazelcast will look into two places for the configuration file:

  1. System property: Hazelcast will first check if "hazelcast.config" system property is set to a file path. Example: -Dhazelcast.config=C:/myhazelcast.xml.
  2. Classpath: If config file is not set as a system property, Hazelcast will check classpath for hazelcast.xml file.
If Hazelcast doesn't find any config file, it will happily start with default configuration (hazelcast-default.xml) located in hazelcast.jar.

Returns:
new HazelcastInstance
See Also:
shutdownAll(), getHazelcastInstanceByName(String)

newLiteMemberHazelcastInstance

public static HazelcastInstance newLiteMemberHazelcastInstance()
Creates a new HazelcastInstance Lite Member (a new node in a cluster). This method allows you to create and run multiple instances of Hazelcast cluster members on the same JVM.

To shutdown all running HazelcastInstances (all members on this JVM) call shutdownAll(). Hazelcast will look into two places for the configuration file:

  1. System property: Hazelcast will first check if "hazelcast.config" system property is set to a file path. Example: -Dhazelcast.config=C:/myhazelcast.xml.
  2. Classpath: If config file is not set as a system property, Hazelcast will check classpath for hazelcast.xml file.
If Hazelcast doesn't find any config file, it will happily start with default configuration (hazelcast-default.xml) located in hazelcast.jar.

Returns:
new HazelcastInstance
See Also:
shutdownAll(), getHazelcastInstanceByName(String)

getHazelcastInstanceByName

public static HazelcastInstance getHazelcastInstanceByName(String instanceName)
Returns an existing HazelcastInstance with instanceName.

To shutdown all running HazelcastInstances (all members on this JVM) call shutdownAll().

Parameters:
instanceName - Name of the HazelcastInstance (member)
Returns:
HazelcastInstance
See Also:
newHazelcastInstance(Config), shutdownAll()

getAllHazelcastInstances

public static Set<HazelcastInstance> getAllHazelcastInstances()
Returns all active/running HazelcastInstances on this JVM.

To shutdown all running HazelcastInstances (all members on this JVM) call shutdownAll().

Returns:
all HazelcastInstances
See Also:
newHazelcastInstance(Config), getHazelcastInstanceByName(String), shutdownAll()

getConfig

@Deprecated
public static Config getConfig()
Deprecated. as of version 2.2

Returns the configuration of this Hazelcast instance.

Returns:
configuration of this Hazelcast instance
See Also:
newHazelcastInstance(com.hazelcast.config.Config), HazelcastInstance.getConfig()

getPartitionService

@Deprecated
public static PartitionService getPartitionService()
Deprecated. as of version 2.2

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

Returns:
partition service
See Also:
newHazelcastInstance(com.hazelcast.config.Config), HazelcastInstance.getPartitionService()

getLoggingService

@Deprecated
public static LoggingService getLoggingService()
Deprecated. as of version 2.2

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 base on the message.

Returns:
logging service
See Also:
newHazelcastInstance(com.hazelcast.config.Config), HazelcastInstance.getLoggingService()

getLifecycleService

@Deprecated
public static LifecycleService getLifecycleService()
Deprecated. as of version 2.2

Returns the lifecycle service for this instance. LifecycleService allows you to shutdown, restart, pause and resume this HazelcastInstance and listen for the lifecycle events.

Returns:
lifecycle service
See Also:
newHazelcastInstance(com.hazelcast.config.Config), HazelcastInstance.getLifecycleService()

setOutOfMemoryHandler

public static void setOutOfMemoryHandler(OutOfMemoryHandler outOfMemoryHandler)
Sets OutOfMemoryHandler to be used when an OutOfMemoryError is caught by Hazelcast threads.

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.

Parameters:
outOfMemoryHandler -
See Also:
OutOfMemoryError, OutOfMemoryHandler


Copyright © 2008-2012 Hazelcast, Inc. All Rights Reserved.