public final class PartitionManager extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static class |
PartitionManager.DisableAction
An enumeration of the possible actions that can be taken when
disabling high availability for a node.
|
static class |
PartitionManager.EnableAction
An enumeration of the possible actions that can be taken when
enabling high availability for a node.
|
Modifier and Type | Method and Description |
---|---|
static void |
clearMapper(java.lang.Class<?> managedClass)
Clear a mapper for a given managed class.
|
static void |
clearMapper(java.lang.String typeName)
Clear a mapper for a given type.
|
static void |
definePartition(java.lang.String partitionName,
Partition.Properties partitionProperties,
java.lang.String activeNode,
ReplicaNode[] replicas)
Define a partition.
|
static void |
definePartition(java.lang.String partitionName,
java.lang.String[] nodes)
Deprecated.
|
static void |
definePartition(java.lang.String partitionName,
java.lang.String restoreFromNode,
java.lang.String[] nodes)
Deprecated.
|
static void |
disablePartitions(PartitionManager.DisableAction disableAction)
Disable high availability for the all partitions defined on the node.
|
static void |
enablePartitions(PartitionManager.EnableAction enableAction)
Enable high availability for the all partitions defined on the node.
|
static Partition |
getObjectPartition(java.lang.Object obj)
Get the partition an object is in.
|
static Partition |
getPartition(java.lang.String partitionName)
Find a partition by name.
|
static Partition[] |
getPartitions()
Find all partitions on the local node.
|
static void |
getRemotePartitions(java.lang.String remoteNode)
Create local copies of all partition defined by the remote node.
|
static boolean |
isPartitioned(java.lang.Class<?> managedClass)
Deprecated.
|
static void |
repartitionInstance(java.lang.Object obj)
Move the instance from the current partition (if any) to
the partition defined by the installed mapper for the object class.
|
static void |
setMapper(java.lang.Class<?> managedClass,
PartitionMapper partitionMapper)
Associate a mapper to a given managed class.
|
static PartitionMapper |
setMapper(java.lang.Class<?> managedClass,
PartitionMapper partitionMapper,
PartitionMapper.Properties mapperProperties)
Associate a mapper to a given managed class.
|
static PartitionMapper |
setMapper(java.lang.String typeName,
PartitionMapper partitionMapper,
PartitionMapper.Properties mapperProperties)
Associate a mapper to a given shared memory type.
|
static void |
waitForNode(java.lang.String remoteNode)
Wait for a remote node to become available.
|
public static final Partition[] getPartitions()
public static final Partition getPartition(java.lang.String partitionName) throws java.lang.IllegalArgumentException, PartitionNotFound
partitionName
- Name of partition to find.PartitionNotFound
- The given partition doesn't exist.java.lang.IllegalArgumentException
- The partitionName was empty.public static final Partition getObjectPartition(java.lang.Object obj) throws ManagedClassError, PartitionNotFound
obj
- Object to examine.ManagedClassError
- The object is not a Managed object.PartitionNotFound
- The given object isn't in a partition. This can happen if
object instances were created before a PartitionMapper
was
installed for a managed class, or no mapper was ever defined.public static final void repartitionInstance(java.lang.Object obj) throws ManagedClassError
obj
- Object to repartition.ManagedClassError
- The object is not a Managed object.ResourceUnavailableException
- An illegal partition name was returned from the mapper, or the
partition that is returned in not in the ACTIVE state.@Deprecated public static final void definePartition(java.lang.String partitionName, java.lang.String[] nodes) throws java.lang.IllegalArgumentException
partitionName
- Name of partition to create.nodes
- An ordered list of nodes for the partition.java.lang.IllegalArgumentException
@Deprecated public static final void definePartition(java.lang.String partitionName, java.lang.String restoreFromNode, java.lang.String[] nodes) throws java.lang.IllegalArgumentException, NotActiveNode
partitionName
- Name of partition to create.restoreFromNode
- The remote node to use when restoring the
partition's objects.nodes
- An ordered list of nodes for the partition.java.lang.IllegalArgumentException
NotActiveNode
public static final void definePartition(java.lang.String partitionName, Partition.Properties partitionProperties, java.lang.String activeNode, ReplicaNode[] replicas) throws java.lang.IllegalArgumentException, NotActiveNode, ResourceUnavailableException
This method defines a partition. This method can be called on any node in the cluster to define a new partition, or change the definition of a pre-existing partition. Once all partitions have been defined for a node, the enablePartitions() method should be called to move the partitions to the active state. It is a runtime error to attempt to create or modify instances in a newly defined partition until the enablePartitions() method is called.
The activeNode is the node that will be the active node for the partition after it is enabled.
Optional partition properties can be used by passing in an
instance of the Partition.Properties
class. User defined
properties such as forceReplication are saved and subsequently
used during failover processing.
The replicas array contains an ordered list of replica nodes for the partition. A failure of the active node results in the partition automatically migrating to the the next entry in the replicas array. Objects are sent to each replica node based on the configuration in the ReplicaNode entry.
partitionName
- Name of partition to create.partitionProperties
- Optional properties for the partition.
If null, the default property values are used.activeNode
- The active node for the partitionreplicas
- An ordered list of replica nodes for the partition.
Should be passed in as a null instance or a zero length array if
no replicas are desired.java.lang.IllegalArgumentException
- The partitionName or activeNode was empty, or the replicas array
was invalid.NotActiveNode
- The current node is not the active node for the partition and
restoreFromNode was defined in partitionProperties.ResourceUnavailableException
- The operation timed out waiting for the active node to become
available.public static final void setMapper(java.lang.Class<?> managedClass, PartitionMapper partitionMapper) throws ManagedClassError
PartitionMapper.Properties.Audit.IGNORE_PARTITIONING
for audit.managedClass
- Name of a Managed object.partitionMapper
- User defined PartitionMapper instance.ManagedClassError
- The managedClass is not a Managed object, or has a non-abstract
parent class with a key defined but no mapper installed.setMapper(Class, PartitionMapper, PartitionMapper.Properties)
public static final PartitionMapper setMapper(java.lang.Class<?> managedClass, PartitionMapper partitionMapper, PartitionMapper.Properties mapperProperties) throws ManagedClassError
This method is used to associate a user defined PartitionMapper instance with a managed class. All managed types that are replicated must have a PartitionMapper associated with the class. This method must be called on all nodes that has the partition definition.
The same PartitionMapper instance can be associated with multiple classes. If a PartitionMapper is already associated with a class, the new value overwrites the previous one.
Applications should only delete a PartitionMapper instance after a new instance is installed. If a PartitionMapper instance is deleted, any subsequent object creates for the class will throw a runtime exception.
Mapper instances are inherited by all classes that extend the managed class. If the managed class extends another class, that class must not have any keys defined.
If auditing is enabled in the mapperProperties instance, this routine will verify that no unpartitioned instances of the given class already exist in shared memory. This can happen if instances are created before a mapper is installed.
managedClass
- Managed class.partitionMapper
- User defined PartitionMapper instance.mapperProperties
- Optional mapper properties. If null,
PartitionMapper.Properties.Audit.IGNORE_PARTITIONING
is used.ManagedClassError
- The managedClass is not a Managed object, or has a non-abstract
parent class with a key defined but no mapper installed.public static final PartitionMapper setMapper(java.lang.String typeName, PartitionMapper partitionMapper, PartitionMapper.Properties mapperProperties) throws ResourceUnavailableException
This method is used to associate a user defined PartitionMapper instance with shared memory type. All types that are replicated must have a PartitionMapper associated with the class. This method must be called on all nodes that has the partition definition.
The same PartitionMapper instance can be associated with multiple type. If a PartitionMapper is already associated with a type, the new value overwrites the previous one.
Applications should only delete a PartitionMapper instance after a new instance is installed. If a PartitionMapper instance is deleted, any subsequent object creates for the type will throw a runtime exception.
Mapper instances are inherited by all subtypes. If the type extends another type, that class must not have any keys defined.
If auditing is enabled in the mapperProperties instance, this routine will verify that no unpartitioned instances of the given type already exist in shared memory. This can happen if instances are created before a mapper is installed.
typeName
- Name of a shared memory type.partitionMapper
- User defined PartitionMapper instance.mapperProperties
- Optional mapper properties. If null,
PartitionMapper.Properties.Audit.IGNORE_PARTITIONING
is used.ResourceUnavailableException
- The typeName is not a shared memory type, or has a non-abstract
parent class with a key defined but no mapper installed.public static final void clearMapper(java.lang.Class<?> managedClass) throws ManagedClassError
This method is used to remove a user defined PartitionMapper instance for a managed class. This method must be called on all nodes where the mapper was previously defined.
If no PartitionMapper is associated with a class, this operation is a noop.
managedClass
- Managed class.ManagedClassError
- The managedClass is not a Managed object.setMapper(Class, PartitionMapper, PartitionMapper.Properties)
public static final void clearMapper(java.lang.String typeName) throws ResourceUnavailableException
This method is used to remove a user defined PartitionMapper instance for a shared memory type. This method must be called on all nodes where the mapper was previously defined.
If no PartitionMapper is associated with a class, this operation is a noop.
typeName
- Name of a Managed object.ResourceUnavailableException
- The typeName does not exist in shared memory.setMapper(String, PartitionMapper, PartitionMapper.Properties)
@Deprecated public static final boolean isPartitioned(java.lang.Class<?> managedClass)
managedClass
- Class to check.public static final void enablePartitions(PartitionManager.EnableAction enableAction) throws NodeMismatch, ResourceUnavailableException
This method is used to enable all partitions that have been defined for this node. This method should be called each time new partitions are defined. This method blocks until all required object migration is complete.
enableAction
- The action to take when enabling partitions.NodeMismatch
- The partition does not have the local node in the node list, and the
active node for the partition has a different node list.ResourceUnavailableException
- The minimum number of nodes needed to establish a quorum has not been
seen.public static final void disablePartitions(PartitionManager.DisableAction disableAction) throws ResourceUnavailableException
This method is used to remove the local node from the node list of all partitions that have been defined for this node. If called multiple times, the additional calls have no effect.
disableAction
- The action to take when disabling partitions.ResourceUnavailableException
- One or more partitions would be in the UNAVAILABLE state after the
disable executes, not thrown if LEAVE_CLUSTER_FORCE is used.public static final void waitForNode(java.lang.String remoteNode) throws ResourceUnavailableException
remoteNode
- name of remote node to wait for.ResourceUnavailableException
- The operation timed out waiting for the remote node to become
available.public static final void getRemotePartitions(java.lang.String remoteNode) throws ResourceUnavailableException
After execution of this method completes, all partitions defined
on the remote node will exist on the local node, and will be
accessible using the getPartition(String)
method.
remoteNode
- name of remote node to access.ResourceUnavailableException
- The operation timed out waiting for the remote node to become
available.