com.hazelcast.partition.impl
Class InternalPartitionServiceImpl

java.lang.Object
  extended by com.hazelcast.partition.impl.InternalPartitionServiceImpl
All Implemented Interfaces:
InternalPartitionService, CoreService, EventPublishingService<MigrationEvent,MigrationListener>, ManagedService

public class InternalPartitionServiceImpl
extends Object
implements InternalPartitionService, ManagedService, EventPublishingService<MigrationEvent,MigrationListener>

The InternalPartitionService implementation.


Field Summary
 
Fields inherited from interface com.hazelcast.partition.InternalPartitionService
DEFAULT_REPLICA_SYNC_DELAY, REPLICA_SYNC_RETRY_DELAY, SERVICE_NAME
 
Constructor Summary
InternalPartitionServiceImpl(Node node)
           
 
Method Summary
 String addMigrationListener(MigrationListener listener)
           
 void clearPartitionReplicaVersions(int partitionId)
           
 void dispatchEvent(MigrationEvent migrationEvent, MigrationListener migrationListener)
           
 void firstArrangement()
           
 Collection<MigrationInfo> getActiveMigrations()
           
 int getMaxBackupCount()
           
 MemberImpl getMember(Address address)
           
 int getMemberGroupsSize()
           
 List<Integer> getMemberPartitions(Address target)
           
 Map<Address,List<Integer>> getMemberPartitionsMap()
          Gets member partition IDs.
 long getMigrationQueueSize()
           
 Node getNode()
           
 com.hazelcast.partition.impl.InternalPartitionImpl getPartition(int partitionId)
          Returns the InternalPartition for a given partitionId.
 com.hazelcast.partition.impl.InternalPartitionImpl getPartition(int partitionId, boolean triggerOwnerAssignment)
          Returns the InternalPartition for a given partitionId.
 int getPartitionCount()
          Returns the number of partitions.
 int getPartitionId(Data key)
          Returns the partition id for a Data key.
 int getPartitionId(Object key)
          Returns the partition id for a given object.
 long getPartitionMigrationTimeout()
           
 Address getPartitionOwner(int partitionId)
          Gets the owner of the partition if it's set.
 Address getPartitionOwnerOrWait(int partition)
          Gets the owner of the partition.
 long[] getPartitionReplicaVersions(int partitionId)
           
 InternalPartition[] getPartitions()
           
 PartitionServiceProxy getPartitionServiceProxy()
           
 int getPartitionStateVersion()
           
 boolean hasOnGoingMigration()
          Checks if there currently are any migrations.
 boolean hasOnGoingMigrationLocal()
           
 long[] incrementPartitionReplicaVersions(int partitionId, int backupCount)
           
 void init(NodeEngine nodeEngine, Properties properties)
          Initializes this ManagedService
 boolean isMemberStateSafe()
          Query and return if this member in a safe state or not.
 boolean isMigrationActive()
           
 void memberAdded(MemberImpl member)
           
 void memberRemoved(MemberImpl member)
           
 void pauseMigration()
           
 boolean prepareToSafeShutdown(long timeout, TimeUnit unit)
           
 boolean removeMigrationListener(String registrationId)
           
 void reset()
          reset this ManagedService back to initial state.
 void resumeMigration()
           
 void setPartitionReplicaVersions(int partitionId, long[] versions, int replicaOffset)
           
 void shutdown(boolean terminate)
          Shuts down this ManagedService.
 String toString()
           
 void updatePartitionReplicaVersions(int partitionId, long[] versions, int replicaIndex)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

InternalPartitionServiceImpl

public InternalPartitionServiceImpl(Node node)
Method Detail

init

public void init(NodeEngine nodeEngine,
                 Properties properties)
Description copied from interface: ManagedService
Initializes this ManagedService

Specified by:
init in interface ManagedService
Parameters:
nodeEngine - the NodeEngine this ManagedService belongs to.
properties - the Properties. Can be used to pass settings to the service.

getPartitionOwner

public Address getPartitionOwner(int partitionId)
Description copied from interface: InternalPartitionService
Gets the owner of the partition if it's set. Otherwise it will trigger partition assignment.

Specified by:
getPartitionOwner in interface InternalPartitionService
Parameters:
partitionId - the partitionId
Returns:
owner of partition or null if it's not set yet.

getPartitionOwnerOrWait

public Address getPartitionOwnerOrWait(int partition)
                                throws InterruptedException
Description copied from interface: InternalPartitionService
Gets the owner of the partition. If none is set, it will wait till the owner is set.

Specified by:
getPartitionOwnerOrWait in interface InternalPartitionService
Parameters:
partition - the partitionId
Returns:
owner of partition
Throws:
InterruptedException

firstArrangement

public void firstArrangement()
Specified by:
firstArrangement in interface InternalPartitionService

getMemberGroupsSize

public int getMemberGroupsSize()
Specified by:
getMemberGroupsSize in interface InternalPartitionService

getMaxBackupCount

public int getMaxBackupCount()
Specified by:
getMaxBackupCount in interface InternalPartitionService

memberAdded

public void memberAdded(MemberImpl member)
Specified by:
memberAdded in interface InternalPartitionService

memberRemoved

public void memberRemoved(MemberImpl member)
Specified by:
memberRemoved in interface InternalPartitionService

getActiveMigrations

public Collection<MigrationInfo> getActiveMigrations()
Specified by:
getActiveMigrations in interface InternalPartitionService

getPartitions

public InternalPartition[] getPartitions()
Specified by:
getPartitions in interface InternalPartitionService

getMember

public MemberImpl getMember(Address address)
Specified by:
getMember in interface InternalPartitionService

getPartition

public com.hazelcast.partition.impl.InternalPartitionImpl getPartition(int partitionId)
Description copied from interface: InternalPartitionService
Returns the InternalPartition for a given partitionId. If owner of the partition is not set yet, it will trigger partition assignment.

The InternalPartition for a given partitionId wil never change; so it can be cached safely.

Specified by:
getPartition in interface InternalPartitionService
Parameters:
partitionId - the partitionId
Returns:
the InternalPartition.

getPartition

public com.hazelcast.partition.impl.InternalPartitionImpl getPartition(int partitionId,
                                                                       boolean triggerOwnerAssignment)
Description copied from interface: InternalPartitionService
Returns the InternalPartition for a given partitionId. If owner of the partition is not set yet and triggerOwnerAssignment is true, it will trigger partition assignment.

The InternalPartition for a given partitionId wil never change; so it can be cached safely.

Specified by:
getPartition in interface InternalPartitionService
Parameters:
partitionId - the partitionId
triggerOwnerAssignment - flag to trigger partition assignment
Returns:
the InternalPartition.

prepareToSafeShutdown

public boolean prepareToSafeShutdown(long timeout,
                                     TimeUnit unit)
Specified by:
prepareToSafeShutdown in interface InternalPartitionService

isMemberStateSafe

public boolean isMemberStateSafe()
Description copied from interface: InternalPartitionService
Query and return if this member in a safe state or not. This method just checks for a safe state, it doesn't force this member to be in a safe state.

Specified by:
isMemberStateSafe in interface InternalPartitionService
Returns:
true if this member in a safe state, otherwise false

hasOnGoingMigration

public boolean hasOnGoingMigration()
Description copied from interface: InternalPartitionService
Checks if there currently are any migrations.

Specified by:
hasOnGoingMigration in interface InternalPartitionService
Returns:
true if there are migrations, false otherwise.

hasOnGoingMigrationLocal

public boolean hasOnGoingMigrationLocal()
Specified by:
hasOnGoingMigrationLocal in interface InternalPartitionService

getPartitionId

public final int getPartitionId(Data key)
Description copied from interface: InternalPartitionService
Returns the partition id for a Data key.

Specified by:
getPartitionId in interface InternalPartitionService
Parameters:
key - the Data key.
Returns:
the partition id.

getPartitionId

public final int getPartitionId(Object key)
Description copied from interface: InternalPartitionService
Returns the partition id for a given object.

Specified by:
getPartitionId in interface InternalPartitionService
Parameters:
key - the object key.
Returns:
the partition id.

getPartitionCount

public final int getPartitionCount()
Description copied from interface: InternalPartitionService
Returns the number of partitions.

Specified by:
getPartitionCount in interface InternalPartitionService
Returns:
the number of partitions.

getPartitionMigrationTimeout

public long getPartitionMigrationTimeout()

incrementPartitionReplicaVersions

public long[] incrementPartitionReplicaVersions(int partitionId,
                                                int backupCount)
Specified by:
incrementPartitionReplicaVersions in interface InternalPartitionService

updatePartitionReplicaVersions

public void updatePartitionReplicaVersions(int partitionId,
                                           long[] versions,
                                           int replicaIndex)
Specified by:
updatePartitionReplicaVersions in interface InternalPartitionService

getPartitionReplicaVersions

public long[] getPartitionReplicaVersions(int partitionId)
Specified by:
getPartitionReplicaVersions in interface InternalPartitionService

setPartitionReplicaVersions

public void setPartitionReplicaVersions(int partitionId,
                                        long[] versions,
                                        int replicaOffset)
Specified by:
setPartitionReplicaVersions in interface InternalPartitionService

clearPartitionReplicaVersions

public void clearPartitionReplicaVersions(int partitionId)
Specified by:
clearPartitionReplicaVersions in interface InternalPartitionService

getMemberPartitionsMap

public Map<Address,List<Integer>> getMemberPartitionsMap()
Description copied from interface: InternalPartitionService
Gets member partition IDs. Blocks until partitions are assigned.

Specified by:
getMemberPartitionsMap in interface InternalPartitionService
Returns:
map of member address to partition Ids

getMemberPartitions

public List<Integer> getMemberPartitions(Address target)
Specified by:
getMemberPartitions in interface InternalPartitionService

reset

public void reset()
Description copied from interface: ManagedService
reset this ManagedService back to initial state. todo: what is the purpose of reset

Specified by:
reset in interface ManagedService

pauseMigration

public void pauseMigration()
Specified by:
pauseMigration in interface InternalPartitionService

resumeMigration

public void resumeMigration()
Specified by:
resumeMigration in interface InternalPartitionService

isMigrationActive

public boolean isMigrationActive()

shutdown

public void shutdown(boolean terminate)
Description copied from interface: ManagedService
Shuts down this ManagedService. todo: what is the purpose of the terminate variable.

Specified by:
shutdown in interface ManagedService

getMigrationQueueSize

public long getMigrationQueueSize()
Specified by:
getMigrationQueueSize in interface InternalPartitionService

getPartitionServiceProxy

public PartitionServiceProxy getPartitionServiceProxy()
Specified by:
getPartitionServiceProxy in interface InternalPartitionService

addMigrationListener

public String addMigrationListener(MigrationListener listener)
Specified by:
addMigrationListener in interface InternalPartitionService

removeMigrationListener

public boolean removeMigrationListener(String registrationId)
Specified by:
removeMigrationListener in interface InternalPartitionService

dispatchEvent

public void dispatchEvent(MigrationEvent migrationEvent,
                          MigrationListener migrationListener)
Specified by:
dispatchEvent in interface EventPublishingService<MigrationEvent,MigrationListener>

toString

public String toString()
Overrides:
toString in class Object

getNode

public Node getNode()

getPartitionStateVersion

public int getPartitionStateVersion()
Specified by:
getPartitionStateVersion in interface InternalPartitionService


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