Skip navigation links

Oracle® Coherence Java API Reference
Release 3.7.0.0

E18683-01


com.tangosol.net.partition
Class PartitionSet

java.lang.Object
  extended by com.tangosol.util.Base
      extended by com.tangosol.util.BitHelper
          extended by com.tangosol.net.partition.PartitionSet

All Implemented Interfaces:
ExternalizableLite, PortableObject, java.io.Serializable

public class PartitionSet
extends BitHelper
implements ExternalizableLite, PortableObject

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.

This implementation is not thread-safe.

Since:
Coherence 3.1
Author:
gg 2005.12.20

Field Summary
protected static int MARKED_ALL
          Serialization format indicator: Indicates that all partitions are marked; MARKED_ALL requires no additional data.
protected static int MARKED_FEW
          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 int MARKED_MANY
          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 int MARKED_NONE
          Serialization format indicator: Indicates that no partitions are marked; MARKED_NONE requires no additional data.

 

Constructor Summary
PartitionSet()
          Default constructor (necessary for the ExternalizableLite interface).
PartitionSet(int cPartitions)
          Construct an empty partition set with a given count.
PartitionSet(PartitionSet partitions)
          Copy constructor: construct a new PartitionSet object equivalent to the specified one.

 

Method Summary
 boolean add(int nPartition)
          Add the specified partition to the set.
 boolean add(PartitionSet partitions)
          Add the specified PartitionSet to this set.
 int cardinality()
          Returns the number of marked partitions.
 void 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 equals(java.lang.Object o)
          Indicates whether some other object is "equal to" this one.
 void fill()
          Fill the set to contain all the partitions.
 int getPartitionCount()
          Return the number of partitions represented by this PartitionSet.
protected static int getTrailingZeroCount(long l)
          Determine the number of trailing zero bits in the passed long value.
 boolean intersects(PartitionSet partitions)
          Check whether or not the specified partition set intersects with this set.
 void 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.
 int next(int nPartition)
          Return an index of the first marked partition that is greater than or equal to the specified partition.
 void readExternal(java.io.DataInput in)
          Restore the contents of this object by loading the object's state from the passed DataInput object.
 void readExternal(PofReader in)
          Restore the contents of a user type instance by reading its state using the specified PofReader 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.
 int[] toArray()
          Convert the partition set to an array of partition identifiers.
 java.lang.String toString()
          Returns a string representation of this PartitionSet.
 void writeExternal(java.io.DataOutput out)
          Save the contents of this object by storing the object's state into the passed DataOutput object.
 void writeExternal(PofWriter out)
          Save the contents of a POF user type instance by writing its state using the specified PofWriter object.

 

Methods inherited from class com.tangosol.util.BitHelper
countBits, countBits, countBits, indexOfLSB, indexOfLSB, indexOfLSB, indexOfMSB, indexOfMSB, indexOfMSB, rotateLeft, rotateLeft, rotateLeft, rotateRight, rotateRight, rotateRight, toBitString, toBitString, toBitString

 

Field Detail

MARKED_NONE

protected static final int MARKED_NONE
Serialization format indicator: Indicates that no partitions are marked; MARKED_NONE requires no additional data.
See Also:
Constant Field Values

MARKED_FEW

protected static final int MARKED_FEW
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.
See Also:
Constant Field Values

MARKED_MANY

protected static final int MARKED_MANY
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.
See Also:
Constant Field Values

MARKED_ALL

protected static final int MARKED_ALL
Serialization format indicator: Indicates that all partitions are marked; MARKED_ALL requires no additional data.
See Also:
Constant Field Values

Constructor Detail

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

public PartitionSet(PartitionSet partitions)
Copy constructor: construct a new PartitionSet object equivalent to the specified one.
Parameters:
partitions - the partition set to copy

Method Detail

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

public boolean add(PartitionSet partitions)
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:
java.lang.IndexOutOfBoundsException - if the specified partition is invalid

remove

public boolean remove(PartitionSet partitions)
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

public boolean retain(PartitionSet partitions)
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

public boolean contains(PartitionSet partitions)
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

public boolean intersects(PartitionSet partitions)
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

public void clear()
Clear the set.

fill

public void fill()
Fill the set to contain all the partitions.

invert

public void invert()
Invert all the partitions. As a result of this operation, all marked partitions will be cleared and all cleared partitions will become marked.

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 parition 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:
java.lang.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

readExternal

public void readExternal(java.io.DataInput in)
                  throws java.io.IOException
Restore the contents of this object by loading the object's state from the passed DataInput object.
Specified by:
readExternal in interface ExternalizableLite
Parameters:
in - the DataInput stream to read data from in order to restore the state of this object
Throws:
java.io.IOException - if an I/O exception occurs
java.io.NotActiveException - if the object is not in its initial state, and therefore cannot be deserialized into

writeExternal

public void writeExternal(java.io.DataOutput out)
                   throws java.io.IOException
Save the contents of this object by storing the object's state into the passed DataOutput object.
Specified by:
writeExternal in interface ExternalizableLite
Parameters:
out - the DataOutput stream to write the state of this object to
Throws:
java.io.IOException - if an I/O exception occurs

readExternal

public void readExternal(PofReader in)
                  throws java.io.IOException
Restore the contents of a user type instance by reading its state using the specified PofReader object.
Specified by:
readExternal in interface PortableObject
Parameters:
in - the PofReader from which to read the object's state
Throws:
java.io.IOException - if an I/O error occurs

writeExternal

public void writeExternal(PofWriter out)
                   throws java.io.IOException
Save the contents of a POF user type instance by writing its state using the specified PofWriter object.
Specified by:
writeExternal in interface PortableObject
Parameters:
out - the PofWriter to which to write the object's state
Throws:
java.io.IOException - if an I/O error occurs

getTrailingZeroCount

protected static int getTrailingZeroCount(long l)
Determine the number of trailing zero bits in the passed long value.
Parameters:
l - a long value
Returns:
the number of trailing zero bits in the value, from 0 (indicating that the least signifcant bit is set) to 64 (indicating that no bits are set)

equals

public boolean equals(java.lang.Object o)
Indicates whether some other object is "equal to" this one.
Parameters:
o - the object to test for equality
Returns:
true if this object is the same as the given one; false otherwise.

toString

public java.lang.String toString()
Returns a string representation of this PartitionSet.
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

Skip navigation links

Oracle® Coherence Java API Reference
Release 3.7.0.0

E18683-01


Copyright © 2000, 2011, Oracle and/or its affiliates. All rights reserved.