Package com.tangosol.net.partition
Class PartitionSet
java.lang.Object
com.tangosol.net.partition.PartitionSet
- All Implemented Interfaces:
- ExternalizableLite,- PortableObject,- Serializable,- Iterable<Integer>
public class PartitionSet
extends Object
implements ExternalizableLite, PortableObject, Iterable<Integer>
PartitionSet is a light-weight data structure that represents a set of
 partitions that are used in parallel processing. This set quite often
 accompanies a result of partial parallel execution and is used to determine
 whether or not the entire set of partitions was successfully processed.
 
Note that all PartitionSet operations that take another set as an argument assume that both sets have the same partition count.
This implementation is not thread-safe.
- Since:
- Coherence 3.1
- Author:
- gg 2005.12.20
- See Also:
- 
Field SummaryFieldsModifier and TypeFieldDescriptionprotected static final intSerialization format indicator: Indicates that all partitions are marked; MARKED_ALL requires no additional data.protected static final intSerialization format indicator: Indicates that a small number of partitions are marked; followed by stream of packed integers indicating gaps between each marked partition, terminated with a -1.protected static final intSerialization format indicator: Indicates that a large number of partitions are marked; followed by a sequence of 64-bit values sufficient to represent the cardinality of the PartitionSet.protected static final intSerialization format indicator: Indicates that no partitions are marked; MARKED_NONE requires no additional data.
- 
Constructor SummaryConstructorsConstructorDescriptionDefault constructor (necessary for the ExternalizableLite interface).PartitionSet(int cPartitions) Construct an empty partition set with a given count.PartitionSet(int cPartitions, int nPartition) Construct a partition set with a given partition count and a single marked partition.PartitionSet(int cPartitions, int... aiPartitions) Construct a partition set with a given partition count and the specified partitions set.PartitionSet(int cPartitions, Collection<? extends Integer> colPartitions) Construct a partition set with a given partition count and the specified partitions set.PartitionSet(PartitionSet partitions) Copy constructor: construct a new PartitionSet object equivalent to the specified one.
- 
Method SummaryModifier and TypeMethodDescriptionbooleanadd(int nPartition) Add the specified partition to the set.booleanadd(PartitionSet partitions) Add the specified PartitionSet to this set.intReturns the number of marked partitions.clear()Clear the set.booleancontains(int nPartition) Check whether or not the specified partition belongs to the set.booleancontains(PartitionSet partitions) Check whether or not the specified partition set belongs to this set.booleanIndicates whether some other object is "equal to" this one.fill()Fill the set to contain all the partitions.intfirst()Return an index of the first marked partition.intReturn the number of partitions represented by this PartitionSet.inthashCode()Returns a hash code value for this PartitionSet.booleanintersects(PartitionSet partitions) Check whether or not the specified partition set intersects with this set.invert()Invert all the partitions.booleanisEmpty()Check whether or not the partition set is empty.booleanisFull()Check whether or not the partition set is full.iterator()intnext(int nPartition) Return an index of the first marked partition that is greater than or equal to the specified partition.voidRestore the contents of a user type instance by reading its state using the specified PofReader object.voidRestore the contents of this object by loading the object's state from the passed DataInput object.booleanremove(int nPartition) Remove the specified partition from the set.booleanremove(PartitionSet partitions) Remove the specified PartitionSet from this set.intremoveNext(int nPartition) Remove the first marked partition starting at the specified partition.booleanretain(PartitionSet partitions) Retain only partitions in this set that are contained in the specified PartitionSet.intrnd()Obtain a random partition from the partition set.split()Split this partition set into two partition sets that are mutually exclusive.int[]toArray()Convert the partition set to an array of partition identifiers.toString()Returns a string representation of this PartitionSet.toString(boolean fVerbose) Returns a string representation of this PartitionSet.static PartitionSetunion(PartitionSet partsA, PartitionSet partsB) Return a union of the two provided PartitionSets.voidwriteExternal(PofWriter out) Save the contents of a POF user type instance by writing its state using the specified PofWriter object.voidwriteExternal(DataOutput out) Save the contents of this object by storing the object's state into the passed DataOutput object.Methods inherited from class java.lang.Objectclone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.lang.IterableforEach, spliterator
- 
Field Details- 
MARKED_NONEprotected static final int MARKED_NONESerialization format indicator: Indicates that no partitions are marked; MARKED_NONE requires no additional data.- See Also:
 
- 
MARKED_FEWprotected static final int MARKED_FEWSerialization format indicator: Indicates that a small number of partitions are marked; followed by stream of packed integers indicating gaps between each marked partition, terminated with a -1.- See Also:
 
- 
MARKED_MANYprotected static final int MARKED_MANYSerialization format indicator: Indicates that a large number of partitions are marked; followed by a sequence of 64-bit values sufficient to represent the cardinality of the PartitionSet.- See Also:
 
- 
MARKED_ALLprotected static final int MARKED_ALLSerialization format indicator: Indicates that all partitions are marked; MARKED_ALL requires no additional data.- See Also:
 
 
- 
- 
Constructor Details- 
PartitionSetpublic PartitionSet()Default constructor (necessary for the ExternalizableLite interface).
- 
PartitionSetpublic PartitionSet(int cPartitions) Construct an empty partition set with a given count.- Parameters:
- cPartitions- the partition count
 
- 
PartitionSetpublic PartitionSet(int cPartitions, int nPartition) Construct a partition set with a given partition count and a single marked partition.- Parameters:
- cPartitions- the partition count
- nPartition- the partition to set
 
- 
PartitionSetConstruct a partition set with a given partition count and the specified partitions set.- Parameters:
- cPartitions- the partition count
- colPartitions- the partitions to set
 
- 
PartitionSetpublic PartitionSet(int cPartitions, int... aiPartitions) Construct a partition set with a given partition count and the specified partitions set.- Parameters:
- cPartitions- the partition count
- aiPartitions- the partitions to set
 
- 
PartitionSetCopy constructor: construct a new PartitionSet object equivalent to the specified one.- Parameters:
- partitions- the partition set to copy
 
 
- 
- 
Method Details- 
addpublic boolean add(int nPartition) Add the specified partition to the set.- Parameters:
- nPartition- the partition to add
- Returns:
- true if the specified partition was actually added as a result of this call; false otherwise
 
- 
addAdd the specified PartitionSet to this set.- Parameters:
- partitions- the PartitionSet to add
- Returns:
- true if all of the partitions were actually added as a result of this call; false otherwise
 
- 
removepublic boolean remove(int nPartition) Remove the specified partition from the set.- Parameters:
- nPartition- the partition to remove
- Returns:
- true if the specified partition was actually removed as a result of this call; false otherwise
 
- 
removeNextpublic int removeNext(int nPartition) Remove the first marked partition starting at the specified partition. If there are no marked partitions greater or equal to the specified partition, the first marked partition greater or equal to 0 but less than the specified partition is removed. If this PartitionSet is empty, -1 is returned.- Parameters:
- nPartition- the partition to start checking from (inclusive)
- Returns:
- the marked partition that was removed or -1 if this PartitionSet is empty
- Throws:
- IndexOutOfBoundsException- if the specified partition is invalid
 
- 
removeRemove the specified PartitionSet from this set.- Parameters:
- partitions- the PartitionSet to remove
- Returns:
- true if all of the specified partitions were actually removed; false otherwise
 
- 
retainRetain only partitions in this set that are contained in the specified PartitionSet.- Parameters:
- partitions- the PartitionSet to retain
- Returns:
- true if this PartitionSet changes as a result of this call; false otherwise
 
- 
containspublic boolean contains(int nPartition) Check whether or not the specified partition belongs to the set.- Parameters:
- nPartition- the partition to check
- Returns:
- true if the specified partition is in the set; false otherwise
 
- 
containsCheck whether or not the specified partition set belongs to this set.- Parameters:
- partitions- the partition set to check
- Returns:
- true if all the partitions from the specified set are in this set; false otherwise
 
- 
intersectsCheck whether or not the specified partition set intersects with this set.- Parameters:
- partitions- the partition set to check
- Returns:
- true if the specified set contains at least one partition that is also present in this partition set; false otherwise
 
- 
isEmptypublic boolean isEmpty()Check whether or not the partition set is empty.- Returns:
- true if none of the partitions are marked; false otherwise
 
- 
isFullpublic boolean isFull()Check whether or not the partition set is full.- Returns:
- true if all the partitions are marked; false otherwise
 
- 
clearClear the set.- Returns:
- this PartitionSet
 
- 
fillFill the set to contain all the partitions.- Returns:
- this PartitionSet
 
- 
invertInvert all the partitions. As a result of this operation, all marked partitions will be cleared and all cleared partitions will become marked.- Returns:
- this PartitionSet
 
- 
firstpublic int first()Return an index of the first marked partition. If no marked partitions exists then -1 is returned.- Returns:
- the first marked partition, or -1 if no marked partitions exists in the set
 
- 
nextpublic int next(int nPartition) Return an index of the first marked partition that is greater than or equal to the specified partition. If no such partition exists then -1 is returned.This method could be used to iterate over all marked partitions: for (int i = ps.next(0); i >= 0; i = ps.next(i+1)) { // process partition }- Parameters:
- nPartition- the partition to start checking from (inclusive)
- Returns:
- the next marked partition, or -1 if no next marked partition exists in the set
- Throws:
- IndexOutOfBoundsException- if the specified partition is invalid
 
- 
cardinalitypublic int cardinality()Returns the number of marked partitions.- Returns:
- the number of marked partitions
 
- 
toArraypublic int[] toArray()Convert the partition set to an array of partition identifiers.- Returns:
- an array of integer partition identifiers
 
- 
rndpublic int rnd()Obtain a random partition from the partition set.- Returns:
- a randomly selected marked partition, or -1 if no partitions are marked
 
- 
splitSplit this partition set into two partition sets that are mutually exclusive.- Returns:
- a new PartitionSet containing approximately half of the marked partitions from this set, or null if this PartitionSet cannot be split
 
- 
unionReturn a union of the two provided PartitionSets.This method will return a reference to one of the provided sets (or null), and may mutate the returned set. - Parameters:
- partsA- set A
- partsB- set B
- Returns:
- union of A & B
 
- 
iterator
- 
readExternalRestore the contents of this object by loading the object's state from the passed DataInput object.- Specified by:
- readExternalin interface- ExternalizableLite
- Parameters:
- in- the DataInput stream to read data from in order to restore the state of this object
- Throws:
- IOException- if an I/O exception occurs
 
- 
writeExternalSave the contents of this object by storing the object's state into the passed DataOutput object.- Specified by:
- writeExternalin interface- ExternalizableLite
- Parameters:
- out- the DataOutput stream to write the state of this object to
- Throws:
- IOException- if an I/O exception occurs
 
- 
readExternalRestore the contents of a user type instance by reading its state using the specified PofReader object.- Specified by:
- readExternalin interface- PortableObject
- Parameters:
- in- the PofReader from which to read the object's state
- Throws:
- IOException- if an I/O error occurs
 
- 
writeExternalSave the contents of a POF user type instance by writing its state using the specified PofWriter object.- Specified by:
- writeExternalin interface- PortableObject
- Parameters:
- out- the PofWriter to which to write the object's state
- Throws:
- IOException- if an I/O error occurs
 
- 
equalsIndicates whether some other object is "equal to" this one.
- 
hashCodepublic int hashCode()Returns a hash code value for this PartitionSet.
- 
toStringReturns a string representation of this PartitionSet.
- 
toStringReturns a string representation of this PartitionSet.- Parameters:
- fVerbose- true for full information, false for terse
- Returns:
- a string representation of this PartitionSet
 
- 
getPartitionCountpublic int getPartitionCount()Return the number of partitions represented by this PartitionSet.- Returns:
- the total partition count
 
 
-