planet.generic.commonapi.behaviours
Class BehavioursPatternImpl

java.lang.Object
  extended byplanet.generic.commonapi.behaviours.BehavioursPatternImpl
All Implemented Interfaces:
BehavioursPattern, java.io.Serializable

public class BehavioursPatternImpl
extends java.lang.Object
implements BehavioursPattern

This class stores a pattern for incoming messages on a node. This pattern is used to dispatch a behaviour classOf whenever the pattern matches the type and mode of the incoming message. To allow behaviours to execute randomly on time, every pattern has a probability.

Author:
Marc Sanchez Date: 10/10/2004
See Also:
Serialized Form

Field Summary
static java.lang.String COMPLEMENTARY_WILDCARD
          Complementary wildcard: given a set of patterns P, this wildcard is used to attach a behaviour to the patterns on the whole pattern space S not included in P set.
static java.lang.String ROLE_BAD
          Overlay property: Bad refers to a behvaiour which must run when node misbehaves, including routing and overlay invariant's maintenance.
static java.lang.String ROLE_GOOD
          Overlay property: Good refers to a behaviour which must run when node behaves as underlying kbr protocol stipulates.
static java.lang.String ROLE_NEUTRAL
          Overlay property: Neutral refers to a behvaiour which must run always despite node's role is bad or good.
static java.lang.String RUN_ALWAYS
          Overlay property: Always refers to a behvaiour which must run always despite RouteMessage's destination.
static java.lang.String RUN_LOCAL
          Overlay property: Local refers to a behaviour which must run only when RouteMessage's pattern is for him.
static java.lang.String RUN_REMOTE
          Overlay property: Remote refers to a behaviour which must run only when RouteMessage's pattern is for another peer rather than him.
static java.lang.String UNIVERSAL_WILDCARD
          Universal wildcard: given a set of patterns P, this wildcard is used to attach a behaviour to all the patterns on the whole pattern space S included P set, i.e.
 
Constructor Summary
BehavioursPatternImpl()
          Builds a non initialized BehavioursPattern.
 
Method Summary
 int compareTo(BehavioursPatternImpl pattern)
          Compares two patterns based on specific criteria.
 java.lang.Class getClassOf()
           
 int getMap()
           
 java.lang.String getModeOf()
           
 double getPdf()
           
 java.lang.String getRoleOf()
           
 java.lang.String getTypeOf()
           
 java.lang.String getWhenTo()
           
 int map(java.lang.String property)
          Maps a property to specific quantifier.
 BehavioursPattern setValues(java.lang.Class classOf, java.lang.String typeOf, java.lang.String modeOf, double pdf, java.lang.String whenTo, java.lang.String roleOf)
          Sets the initial values for this pattern.
 java.lang.String toString()
          Shows the string representation of this pattern.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

COMPLEMENTARY_WILDCARD

public static final java.lang.String COMPLEMENTARY_WILDCARD
Complementary wildcard: given a set of patterns P, this wildcard is used to attach a behaviour to the patterns on the whole pattern space S not included in P set.

See Also:
Constant Field Values

UNIVERSAL_WILDCARD

public static final java.lang.String UNIVERSAL_WILDCARD
Universal wildcard: given a set of patterns P, this wildcard is used to attach a behaviour to all the patterns on the whole pattern space S included P set, i.e. P C S.

See Also:
Constant Field Values

RUN_LOCAL

public static final java.lang.String RUN_LOCAL
Overlay property: Local refers to a behaviour which must run only when RouteMessage's pattern is for him.

See Also:
Constant Field Values

RUN_REMOTE

public static final java.lang.String RUN_REMOTE
Overlay property: Remote refers to a behaviour which must run only when RouteMessage's pattern is for another peer rather than him.

See Also:
Constant Field Values

RUN_ALWAYS

public static final java.lang.String RUN_ALWAYS
Overlay property: Always refers to a behvaiour which must run always despite RouteMessage's destination.

See Also:
Constant Field Values

ROLE_GOOD

public static final java.lang.String ROLE_GOOD
Overlay property: Good refers to a behaviour which must run when node behaves as underlying kbr protocol stipulates.

See Also:
Constant Field Values

ROLE_BAD

public static final java.lang.String ROLE_BAD
Overlay property: Bad refers to a behvaiour which must run when node misbehaves, including routing and overlay invariant's maintenance.

See Also:
Constant Field Values

ROLE_NEUTRAL

public static final java.lang.String ROLE_NEUTRAL
Overlay property: Neutral refers to a behvaiour which must run always despite node's role is bad or good.

See Also:
Constant Field Values
Constructor Detail

BehavioursPatternImpl

public BehavioursPatternImpl()
Builds a non initialized BehavioursPattern. Requires the setValues(...) method invokation.

Method Detail

setValues

public BehavioursPattern setValues(java.lang.Class classOf,
                                   java.lang.String typeOf,
                                   java.lang.String modeOf,
                                   double pdf,
                                   java.lang.String whenTo,
                                   java.lang.String roleOf)
Sets the initial values for this pattern.

Parameters:
classOf - Behaviours class to be invoked when this pattern is matched.
typeOf - RouteMessage type.
modeOf - RouteMessage mode.
pdf - The probability for a successfully invokation of the related behaviour.
whenTo - Determines the locality of the behaviour (local, remote or both situations).
roleOf - Determines the active role to invoke the related behaviour (good, bad or both)
Returns:
The same instance once it has been updated.

getClassOf

public java.lang.Class getClassOf()
Returns:
Returns the class of behaviour.

getModeOf

public java.lang.String getModeOf()
Returns:
Returns the mode of pattern.

getPdf

public double getPdf()
Returns:
Returns the probability binding.

getTypeOf

public java.lang.String getTypeOf()
Returns:
Returns the type of the pattern.

getWhenTo

public java.lang.String getWhenTo()
Returns:
Returns when to exec this behaviour.

getRoleOf

public java.lang.String getRoleOf()
Returns:
Returns the role of this behaviour.

getMap

public int getMap()
Returns:
Returns an integer mapping for this pattern.

map

public int map(java.lang.String property)
Maps a property to specific quantifier. So Complementary wildcard "?" is more specific than universal wildcard "*".

Parameters:
property - The property to quantify.
Returns:
The quantifier of the property.

compareTo

public int compareTo(BehavioursPatternImpl pattern)
Compares two patterns based on specific criteria.
   Specific criteria:
 		   Type  Mode	
 		1) Tag,  Tag
 		2) Tag,   ?
 		3) Tag,   *
 		4)  ? ,  Tag
      5)  * ,  Tag
      6)  ? ,   *
      7)  * ,   ?
      8)  * ,   *
 

Parameters:
pattern - The pattern to compare.
Returns:
the value 0 if the argument pattern is equal to this pattern; a value less than 0 if this pattern is less specific than the pattern argument; and a value greater than 0 if the pattern is more specific than the pattern argument.

toString

public java.lang.String toString()
Shows the string representation of this pattern.

Returns:
The string representation of this pattern.
See Also:
Object.toString()