Package com.tangosol.net.partition
Class PartitionSet
java.lang.Object
com.tangosol.util.Base
com.tangosol.net.partition.PartitionSet
- All Implemented Interfaces:
ExternalizableLite
,PortableObject
,Serializable
,Iterable<Integer>
public class PartitionSet
extends Base
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:
-
Nested Class Summary
Nested classes/interfaces inherited from class com.tangosol.util.Base
Base.LoggingWriter
-
Field Summary
Modifier and TypeFieldDescriptionprotected static final int
Serialization format indicator: Indicates that all partitions are marked; MARKED_ALL requires no additional data.protected static final int
Serialization 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 int
Serialization 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 int
Serialization format indicator: Indicates that no partitions are marked; MARKED_NONE requires no additional data. -
Constructor Summary
ConstructorDescriptionDefault constructor (necessary for the ExternalizableLite interface).PartitionSet
(int cPartitions) Construct an empty partition set with a given count.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 Summary
Modifier and TypeMethodDescriptionboolean
add
(int nPartition) Add the specified partition to the set.boolean
add
(PartitionSet partitions) Add the specified PartitionSet to this set.int
Returns the number of marked partitions.clear()
Clear the set.boolean
contains
(int nPartition) Check whether or not the specified partition belongs to the set.boolean
contains
(PartitionSet partitions) Check whether or not the specified partition set belongs to this set.boolean
Indicates whether some other object is "equal to" this one.fill()
Fill the set to contain all the partitions.int
first()
Return an index of the first marked partition.int
Return the number of partitions represented by this PartitionSet.int
hashCode()
Returns a hash code value for this PartitionSet.boolean
intersects
(PartitionSet partitions) Check whether or not the specified partition set intersects with this set.invert()
Invert all the partitions.boolean
isEmpty()
Check whether or not the partition set is empty.boolean
isFull()
Check whether or not the partition set is full.iterator()
int
next
(int nPartition) Return an index of the first marked partition that is greater than or equal to the specified partition.void
Restore the contents of a user type instance by reading its state using the specified PofReader object.void
Restore the contents of this object by loading the object's state from the passed DataInput object.boolean
remove
(int nPartition) Remove the specified partition from the set.boolean
remove
(PartitionSet partitions) Remove the specified PartitionSet from this set.int
removeNext
(int nPartition) Remove the first marked partition starting at the specified partition.boolean
retain
(PartitionSet partitions) Retain only partitions in this set that are contained in the specified PartitionSet.int
rnd()
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 PartitionSet
union
(PartitionSet partsA, PartitionSet partsB) Return a union of the two provided PartitionSets.void
writeExternal
(PofWriter out) Save the contents of a POF user type instance by writing its state using the specified PofWriter object.void
writeExternal
(DataOutput out) Save the contents of this object by storing the object's state into the passed DataOutput object.Methods inherited from class com.tangosol.util.Base
azzert, azzert, azzert, azzertFailed, breakLines, breakLines, capitalize, checkNotEmpty, checkNotNull, checkRange, computeSafeWaitTime, decimalValue, dup, dup, ensureBigDecimal, ensureClassLoader, ensureRuntimeException, ensureRuntimeException, equals, equalsDeep, err, err, err, err, err, escape, formatDateTime, getCallerStackFrame, getCommonMonitor, getCommonMonitor, getCommonMonitor, getContextClassLoader, getContextClassLoader, getDeepMessage, getErr, getLastSafeTimeMillis, getLog, getMaxDecDigits, getMaxHexDigits, getOriginalException, getOut, getProcessRandom, getRandom, getRandomBinary, getRandomBinary, getRandomString, getSafeTimeMillis, getStackFrame, getStackFrames, getStackTrace, getStackTrace, getStackTrace, getThreadFactory, getTimeZone, getUpTimeMillis, hashCode, hexValue, indentString, indentString, isDecimal, isHex, isLogEcho, isOctal, log, log, log, log, log, makeInteger, makeLong, makeThread, mergeArray, mergeBooleanArray, mergeByteArray, mergeCharArray, mergeDoubleArray, mergeFloatArray, mergeIntArray, mergeLongArray, mod, mod, octalValue, out, out, out, out, out, pad, parseBandwidth, parseBandwidth, parseDelimitedString, parseHex, parseHex, parseMemorySize, parseMemorySize, parsePercentage, parseTime, parseTime, parseTimeNanos, parseTimeNanos, printStackTrace, randomize, randomize, randomize, randomize, read, read, read, read, read, read, read, replace, setErr, setLog, setLogEcho, setOut, sleep, toBandwidthString, toBandwidthString, toCharEscape, toCrc, toCrc, toCrc, toCrc, toCrc, toDecString, toDelimitedString, toDelimitedString, toDelimitedString, toDelimitedString, toHex, toHex, toHexDump, toHexEscape, toHexEscape, toHexEscape, toHexEscape, toHexString, toMemorySizeString, toMemorySizeString, toQuotedCharEscape, toQuotedStringEscape, toSqlString, toString, toString, toStringEscape, toUnicodeEscape, trace, trace, trace, trace, trace, trace, trace, trace, trace, truncateString, truncateString, wait
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
MARKED_NONE
protected static final int MARKED_NONESerialization format indicator: Indicates that no partitions are marked; MARKED_NONE requires no additional data.- See Also:
-
MARKED_FEW
protected 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_MANY
protected 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_ALL
protected static final int MARKED_ALLSerialization format indicator: Indicates that all partitions are marked; MARKED_ALL requires no additional data.- See Also:
-
-
Constructor Details
-
PartitionSet
public PartitionSet()Default constructor (necessary for the ExternalizableLite interface). -
PartitionSet
public PartitionSet(int cPartitions) Construct an empty partition set with a given count.- Parameters:
cPartitions
- the partition count
-
PartitionSet
Construct a partition set with a given partition count and the specified partitions set.- Parameters:
cPartitions
- the partition countcolPartitions
- the partitions to set
-
PartitionSet
public PartitionSet(int cPartitions, int... aiPartitions) Construct a partition set with a given partition count and the specified partitions set.- Parameters:
cPartitions
- the partition countaiPartitions
- the partitions to set
-
PartitionSet
Copy constructor: construct a new PartitionSet object equivalent to the specified one.- Parameters:
partitions
- the partition set to copy
-
-
Method Details
-
add
public 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
-
add
Add 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
-
remove
public 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
-
removeNext
public 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
-
remove
Remove 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
-
retain
Retain 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
-
contains
public 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
-
contains
Check 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
-
intersects
Check 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
-
isEmpty
public boolean isEmpty()Check whether or not the partition set is empty.- Returns:
- true if none of the partitions are marked; false otherwise
-
isFull
public boolean isFull()Check whether or not the partition set is full.- Returns:
- true if all the partitions are marked; false otherwise
-
clear
Clear the set.- Returns:
- this PartitionSet
-
fill
Fill the set to contain all the partitions.- Returns:
- this PartitionSet
-
invert
Invert 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
-
first
public 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
-
next
public 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
-
cardinality
public int cardinality()Returns the number of marked partitions.- Returns:
- the number of marked partitions
-
toArray
public int[] toArray()Convert the partition set to an array of partition identifiers.- Returns:
- an array of integer partition identifiers
-
rnd
public int rnd()Obtain a random partition from the partition set.- Returns:
- a randomly selected marked partition, or -1 if no partitions are marked
-
split
Split 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
-
union
Return 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 ApartsB
- set B- Returns:
- union of
A & B
-
iterator
-
readExternal
Restore the contents of this object by loading the object's state from the passed DataInput object.- Specified by:
readExternal
in interfaceExternalizableLite
- 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
-
writeExternal
Save the contents of this object by storing the object's state into the passed DataOutput object.- Specified by:
writeExternal
in interfaceExternalizableLite
- Parameters:
out
- the DataOutput stream to write the state of this object to- Throws:
IOException
- if an I/O exception occurs
-
readExternal
Restore the contents of a user type instance by reading its state using the specified PofReader object.- Specified by:
readExternal
in interfacePortableObject
- Parameters:
in
- the PofReader from which to read the object's state- Throws:
IOException
- if an I/O error occurs
-
writeExternal
Save the contents of a POF user type instance by writing its state using the specified PofWriter object.- Specified by:
writeExternal
in interfacePortableObject
- Parameters:
out
- the PofWriter to which to write the object's state- Throws:
IOException
- if an I/O error occurs
-
equals
Indicates whether some other object is "equal to" this one. -
hashCode
public int hashCode()Returns a hash code value for this PartitionSet. -
toString
Returns a string representation of this PartitionSet. -
toString
Returns a string representation of this PartitionSet.- Parameters:
fVerbose
- true for full information, false for terse- Returns:
- a string representation of this PartitionSet
-
getPartitionCount
public int getPartitionCount()Return the number of partitions represented by this PartitionSet.- Returns:
- the total partition count
-