messif.buckets.split
Class SplitPolicy

java.lang.Object
  extended by messif.buckets.split.SplitPolicy
All Implemented Interfaces:
ObjectMatcher<LocalAbstractObject>
Direct Known Subclasses:
SplitPolicyBallPartitioning, SplitPolicyExcludedMiddlePartitioning, SplitPolicyGeneralizedHyperplane, SplitPolicyMultiWayBallPartitioning, SplitPolicyVoronoiPartitioning

public abstract class SplitPolicy
extends java.lang.Object
implements ObjectMatcher<LocalAbstractObject>

This class defines an abstract policy for bucket splitting. The policy is fully defined by the internal parameters, e.g. a policy for ball partitioning requires a pivot and a radius. Each policy implements the object matcher that decides the target partition of a given object according to this policy. Some (or all) parameters can be unspecified when the policy is instantiated and can be provided through setParameter(java.lang.String, java.lang.Object) method later. However, the match method returns UnsupportedOperationException until all the parameters are fully specified, i.e. isComplete() returns true). If desired, some parameters can be locked, so they can't be changed anymore.


Nested Class Summary
protected static interface SplitPolicy.ParameterField
          Annotation of split policy parameter field.
 
Field Summary
static int PART_ID_ANY
          Identification of any partition (returned if a region cannot fit a single partition).
 
Constructor Summary
protected SplitPolicy()
          Creates a new instance of SplitPolicy.
 
Method Summary
protected  BucketBallRegion getBucketBallRegion(LocalBucket bucket)
          Returns the BucketBallRegion associated with the specified bucket.
 java.lang.Object getParameter(java.lang.String parameter)
          Returns the value of the specified parameter.
 java.util.Set<java.lang.String> getParameterNames()
          Returns all parameter names for this policy.
 java.lang.Class<?> getParameterType(java.lang.String parameter)
          Returns the type of the specified policy parameter.
abstract  int getPartitionsCount()
          Returns the number of partitions of this policy.
 boolean isComplete()
          Returns true if this policy has all the arguments necessary for a split defined.
 boolean isParameterFilled(java.lang.String parameter)
          Returns true if the specified parameter has a value set.
 boolean isParameterLocked(java.lang.String parameter)
          Returns true if the specified parameter is locked.
 void lockParameter(java.lang.String parameter)
          Locks the specified policy parameter.
abstract  int match(BallRegion region)
          Returns the group (partition) to which the whole ball region belongs.
abstract  int match(LocalAbstractObject object)
          Returns the group (partition) to which a given object belongs.
 int match(LocalBucket bucket)
          Returns the group (partition) to which the whole bucket belongs.
 void setParameter(java.lang.String parameter, java.lang.Object value)
          Use this method to set the policy parameter.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PART_ID_ANY

public static final int PART_ID_ANY
Identification of any partition (returned if a region cannot fit a single partition). Equal to -1

See Also:
Constant Field Values
Constructor Detail

SplitPolicy

protected SplitPolicy()
Creates a new instance of SplitPolicy. All policy parameters are neither locked nor filled.

Method Detail

match

public abstract int match(BallRegion region)
Returns the group (partition) to which the whole ball region belongs. Returns -1 if not all objects from the specified ball region fall into just one partition or if this policy cannot decide. In that case, the ball region must be searched one object by one using the match(messif.objects.BallRegion) method.

Parameters:
region - a ball region that is tested for the matching condition
Returns:
the group (partition) to which the whole ball region belongs or -1 if it is uncertain

match

public abstract int match(LocalAbstractObject object)
Returns the group (partition) to which a given object belongs.

Specified by:
match in interface ObjectMatcher<LocalAbstractObject>
Parameters:
object - an object that is tested for the matching condition
Returns:
the group (partition) to which the given object belongs

getBucketBallRegion

protected BucketBallRegion getBucketBallRegion(LocalBucket bucket)
                                        throws java.util.NoSuchElementException
Returns the BucketBallRegion associated with the specified bucket. It must be registered in the bucket as filter, otherwise a NoSuchElementException is thrown.

Parameters:
bucket - the bucket to get the region for
Returns:
the BucketBallRegion associated with bucket
Throws:
java.util.NoSuchElementException - if there was no ball region associated

match

public int match(LocalBucket bucket)
Returns the group (partition) to which the whole bucket belongs. Returns -1 if not all objects from the specified bucket fall into just one partition or if this policy cannot decide. In that case, the bucket must be searched one object by one using the match(messif.objects.BallRegion) method. If there is no BucketBallRegion registered in the bucket, -1 is returned.

Parameters:
bucket - a bucket that is tested for the matching condition
Returns:
the group (partition) to which the whole bucket belongs or -1 if it is uncertain

isComplete

public boolean isComplete()
Returns true if this policy has all the arguments necessary for a split defined. Otherwise, some arguments are missing (depends on the specific policy type).

Returns:
true if this policy has all the arguments necessary for a split defined

getParameterNames

public java.util.Set<java.lang.String> getParameterNames()
Returns all parameter names for this policy.

Returns:
all parameter names for this policy

setParameter

public void setParameter(java.lang.String parameter,
                         java.lang.Object value)
                  throws java.lang.IllegalStateException,
                         java.util.NoSuchElementException,
                         java.lang.NullPointerException
Use this method to set the policy parameter.

Parameters:
parameter - the name of the policy parameter
value - new value for the parameter
Throws:
java.lang.IllegalStateException - if the specified parameter is locked
java.util.NoSuchElementException - if there is no parameter for the specified name
java.lang.NullPointerException - if the specified value is null

getParameter

public java.lang.Object getParameter(java.lang.String parameter)
                              throws java.lang.IllegalStateException,
                                     java.util.NoSuchElementException
Returns the value of the specified parameter.

Parameters:
parameter - the name of the policy parameter
Returns:
the value of the specified parameter
Throws:
java.lang.IllegalStateException - if the parameter is not filled yet
java.util.NoSuchElementException - if there is no parameter for the specified name

isParameterLocked

public boolean isParameterLocked(java.lang.String parameter)
                          throws java.util.NoSuchElementException
Returns true if the specified parameter is locked.

Parameters:
parameter - the name of the policy parameter
Returns:
true if the specified parameter is locked.
Throws:
java.util.NoSuchElementException - if there is no parameter for the specified name

lockParameter

public void lockParameter(java.lang.String parameter)
                   throws java.util.NoSuchElementException
Locks the specified policy parameter. Once locked, a parameter can't be changed by setParameter(java.lang.String, java.lang.Object) method anymore.

Parameters:
parameter - the name of the policy parameter
Throws:
java.util.NoSuchElementException - if there is no parameter for the specified name

isParameterFilled

public boolean isParameterFilled(java.lang.String parameter)
                          throws java.util.NoSuchElementException
Returns true if the specified parameter has a value set. That is, if the setParameter(java.lang.String, java.lang.Object) was called for the specified parameter.

Parameters:
parameter - the name of the policy parameter
Returns:
true if the specified parameter is locked.
Throws:
java.util.NoSuchElementException - if there is no parameter for the specified name

getParameterType

public java.lang.Class<?> getParameterType(java.lang.String parameter)
                                    throws java.util.NoSuchElementException
Returns the type of the specified policy parameter.

Parameters:
parameter - the name of the policy parameter
Returns:
the type of the specified policy parameter
Throws:
java.util.NoSuchElementException - if there is no parameter for the specified name

getPartitionsCount

public abstract int getPartitionsCount()
Returns the number of partitions of this policy.

Returns:
the number of partitions of this policy