com.hazelcast.core
Interface PartitionService

All Known Implementing Classes:
PartitionServiceProxy, PartitionServiceProxy

public interface PartitionService

PartitionService allows you to query Partitions and attach/detach MigrationListeners to listen to partition migration events. The methods on the PartitionService are thread-safe.

See Also:
Partition, MigrationListener

Method Summary
 String addMigrationListener(MigrationListener migrationListener)
          Adds a MigrationListener.
 boolean forceLocalMemberToBeSafe(long timeout, TimeUnit unit)
          Force the local member to be safe by checking and syncing partitions owned by the local member with at least one of the backups.
 Partition getPartition(Object key)
          Returns the partition that the given key belongs to.
 Set<Partition> getPartitions()
          Returns a set containing all the Partitions in the cluster.
 boolean isClusterSafe()
          Checks whether the cluster is in a safe state.
 boolean isLocalMemberSafe()
          Check if the local member is safe to shutdown, meaning check if at least one backup of the partitions owned by the local member are in sync with primary.
 boolean isMemberSafe(Member member)
          Check if the given member is safe to shutdown, meaning check if at least one backup of the partitions owned by the given member are in sync with primary.
 String randomPartitionKey()
          Generates a random partition key.
 boolean removeMigrationListener(String registrationId)
          Removes a MigrationListener.
 

Method Detail

getPartitions

Set<Partition> getPartitions()
Returns a set containing all the Partitions in the cluster.

Returns:
all partitions in the cluster

getPartition

Partition getPartition(Object key)
Returns the partition that the given key belongs to.

Parameters:
key - the given key
Returns:
the partition that the given key belongs to todo: what about null.

randomPartitionKey

String randomPartitionKey()
Generates a random partition key. This is useful if you want to partition data in the same partition, but you do not care which partition it is going to be.

The returned value will never be null.

Returns:
the random partition key.

addMigrationListener

String addMigrationListener(MigrationListener migrationListener)
Adds a MigrationListener.

The addMigrationListener returns a register-id. This id is needed to remove the MigrationListener using the removeMigrationListener(String) method.

There is no check for duplicate registrations, so if you register the listener twice, it will get events twice.

Parameters:
migrationListener - the added MigrationListener
Returns:
returns the registration id for the MigrationListener.
Throws:
NullPointerException - if migrationListener is null.
UnsupportedOperationException - if this operation isn't supported. For example on the client side it isn't possible to add a MigrationListener.
See Also:
removeMigrationListener(String)

removeMigrationListener

boolean removeMigrationListener(String registrationId)
Removes a MigrationListener.

If the same MigrationListener is registered multiple times, it needs to be removed multiple times.

This method can safely be called multiple times for the same registration-id; every subsequent call is just ignored.

Parameters:
registrationId - the registration id of the listener to remove.
Returns:
true if the listener is removed, false otherwise.
Throws:
NullPointerException - if registrationId is null.
UnsupportedOperationException - if this operation isn't supported. For example, on the client side it isn't possible to add/remove a MigrationListener.
See Also:
addMigrationListener(MigrationListener)

isClusterSafe

boolean isClusterSafe()
Checks whether the cluster is in a safe state. When in a safe state, it is permissible to shut down a server instance.

Returns:
true if there are no partitions being migrated, and there are sufficient backups for each partition per the configuration; false otherwise.
Since:
3.3

isMemberSafe

boolean isMemberSafe(Member member)
Check if the given member is safe to shutdown, meaning check if at least one backup of the partitions owned by the given member are in sync with primary.

Parameters:
member - the cluster member to query.
Returns:
true if the member is in a safe state, false otherwise.
Since:
3.3

isLocalMemberSafe

boolean isLocalMemberSafe()
Check if the local member is safe to shutdown, meaning check if at least one backup of the partitions owned by the local member are in sync with primary.

Since:
3.3

forceLocalMemberToBeSafe

boolean forceLocalMemberToBeSafe(long timeout,
                                 TimeUnit unit)
Force the local member to be safe by checking and syncing partitions owned by the local member with at least one of the backups.

Parameters:
timeout - the time limit for checking/syncing with the backup
unit - the unit of time for timeout
Since:
3.3


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