planet.behaviour
Class BehavioursPoolImpl

java.lang.Object
  extended byplanet.behaviour.BehavioursPoolImpl
All Implemented Interfaces:
BehavioursPool

public class BehavioursPoolImpl
extends java.lang.Object
implements BehavioursPool

The BehavioursPool's class is aimed at providing an internal scheduler of node's behaviuours. At startup, behaviours are registered to the pool from Behaviour.properties file, following the next syntax:

    
      Class = Type, Mode, Probability, When, Role 
 
Then, a message interceptor is build up and is ready to invoke behaviours when a message pattern matches to those provided by Behaviour.properties file.

Author:
Marc Sanchez Date: 10/10/2004

Field Summary
protected static int ALWAYS_MASK
           
protected static int BadRole
          Behaviour's Property: Bad modifier for Behaviour's role.
protected  java.util.Vector[][] beh
          BehavioursPool properties: mapping from to
protected static int BEH_MAPPINGS
           
protected  int behSlots
           
protected  Filter filter
           
protected static int GoodRole
          Behaviour's Property: Good modifier for Behaviour's role.
protected static int LocalTraffic
          Behaviour's Property: Local modifier applied to a behaviour means it only will be scheduled when a RouteMessage has as destination the local node.
protected static int NEUTRAL_MASK
           
protected  java.lang.Class nodeClass
           
protected static int NULL_MASK
           
protected  int numberModes
           
protected  int numberTypes
           
protected static int RemoteTraffic
          Behaviour's Property: Remote modifier applied to a behaviour means it only will be scheduled when a RouteMessage has as destination a remode node and needs to be rerouted trough the strucutred overlay again.
 
Fields inherited from interface planet.behaviour.BehavioursPool
NumberOfModes, NumberOfTypes
 
Constructor Summary
BehavioursPoolImpl(java.lang.Class filterClass, java.util.Vector patterns, java.lang.Class nodeClass)
           
 
Method Summary
protected  void build(java.util.Vector patterns)
          Given the patterns sorted from more-to-less specific as input, builds a mapping from RouteMessage's patterns to behaviours.
protected  RouteMessage[] copyInto(java.util.Vector s)
           
protected  void copyInto(java.util.Vector copy, RouteMessage[] source)
           
 RouteMessage[] onMessage(RouteMessage msg, Node node)
          Given a RouteMessage and a Node as input, onMessage's method intends to invoke some behaviours only if RouteMessage's type and mode fields matches some behaviour's pattern.
protected  void prettyPrintAll()
           
protected  void printMap(int queue)
           
protected  void setPattern(int queue, int typePos, java.lang.String modeOf, Pattern pattern)
          Given the initial position for type on mapping typePos and mode as input, sets the pattern on the mapping taking into account the grammar tree extracted from wildcards semantics.
protected  boolean[] whichQueues(int Mask, int RoleOf, int WhenTo)
          The WhichQueue's method selects for a given pattern what Queues must include a copy of the current behaviour.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

beh

protected java.util.Vector[][] beh
BehavioursPool properties: mapping from to . ~ Patterns are composed by: Type and Mode, for example: "QUERY_JOIN" and "REQUEST". ~ Types: NodeImpl class has several public static final int constants from range 0..NumberOfTypes. ~ Modes: NodeImpl class has several public static final int constants from range 0..NumberOfModes. By reflection, the behaviour's pool given a set of patterns P from behaviours.properties file do: For each pattern on P do Mode = pattern.getMode(); Type = pattern.getType(); beh[Type * NumberOfModes + Mode] = pattern; done; Moreover, Pattern's definiton provides additional specifiers: ~ Incoming RouteMessage's destination: Local, Remote and Always. Local qualifier affects iff incoming messages for the local node. Hence, only behaviours for the local node may be matched. Remote qualifier affects iff messages for remote nodes. Hence, programmer must code behaviours which alter the underlying overlay protocol when RouteMessages are destined to remote nodes. Always modifier is used as a wild card to ignore local or remote behaviour. ~ Behaviours's role: Bad, Good and Neutral. Bad qualifier alters only the behaviours from bad nodes. Good qualifier alters only the behaviours from good nodes and Neutral is a wild card used to ignore peer's behaviour.


GoodRole

protected static int GoodRole
Behaviour's Property: Good modifier for Behaviour's role. This means the behaviour qualified by this modifier only will be scheduled by good peers.


BadRole

protected static int BadRole
Behaviour's Property: Bad modifier for Behaviour's role. This means the behaviour qualified by this modifier only will be scheduled by bad peers.


LocalTraffic

protected static int LocalTraffic
Behaviour's Property: Local modifier applied to a behaviour means it only will be scheduled when a RouteMessage has as destination the local node.


RemoteTraffic

protected static int RemoteTraffic
Behaviour's Property: Remote modifier applied to a behaviour means it only will be scheduled when a RouteMessage has as destination a remode node and needs to be rerouted trough the strucutred overlay again.


nodeClass

protected java.lang.Class nodeClass

numberModes

protected int numberModes

numberTypes

protected int numberTypes

filter

protected Filter filter

behSlots

protected int behSlots

ALWAYS_MASK

protected static final int ALWAYS_MASK
See Also:
Constant Field Values

NEUTRAL_MASK

protected static final int NEUTRAL_MASK
See Also:
Constant Field Values

NULL_MASK

protected static final int NULL_MASK
See Also:
Constant Field Values

BEH_MAPPINGS

protected static final int BEH_MAPPINGS
See Also:
Constant Field Values
Constructor Detail

BehavioursPoolImpl

public BehavioursPoolImpl(java.lang.Class filterClass,
                          java.util.Vector patterns,
                          java.lang.Class nodeClass)
                   throws InitializationException
Method Detail

whichQueues

protected boolean[] whichQueues(int Mask,
                                int RoleOf,
                                int WhenTo)
The WhichQueue's method selects for a given pattern what Queues must include a copy of the current behaviour.

Parameters:
Mask - The Mask for Pattern.Always and Pattern.Neutral modifiers.
RoleOf - The Behaviour's Role for a Good or Bad peer.
WhenTo - Specifies Behaviour should be activated when incoming messages refer to the local node or either when refer to a remote.
Returns:
Which Behaviour's Queue must copy this behaviour.

build

protected void build(java.util.Vector patterns)
              throws InitializationException
Given the patterns sorted from more-to-less specific as input, builds a mapping from RouteMessage's patterns to behaviours.

Parameters:
patterns - The List of patterns.
Throws:
InitializationException

setPattern

protected void setPattern(int queue,
                          int typePos,
                          java.lang.String modeOf,
                          Pattern pattern)
                   throws InitializationException
Given the initial position for type on mapping typePos and mode as input, sets the pattern on the mapping taking into account the grammar tree extracted from wildcards semantics. Hence, the maximum number of mappings goes from typePos to typePos + NumberOfModes. For example, suppose type is QUERY_JOIN and modes are REQUEST and REPLY the maximun number of mappings to set is 2;

Parameters:
queue - Identifies where to be queued the pattern.
typePos - Initial position on behaviours mapping array, i.e, [typePos..typePos + NumberOfModes]
modeOf - Mode of the pattern: Universal wildcard or '*', Complementary wildcard or '?' and Tag.
pattern - Pattern to be treat.
Throws:
InitializationException

prettyPrintAll

protected void prettyPrintAll()

printMap

protected void printMap(int queue)

onMessage

public RouteMessage[] onMessage(RouteMessage msg,
                                Node node)
                         throws NoSuchBehaviourException,
                                NoBehaviourDispatchedException
Given a RouteMessage and a Node as input, onMessage's method intends to invoke some behaviours only if RouteMessage's type and mode fields matches some behaviour's pattern.

Specified by:
onMessage in interface BehavioursPool
Parameters:
msg - RoteMessage taken as input.
node - Node taken as input.
Returns:
Returns either an array of RouteMessages or null when no messages need to transmit this node.
Throws:
NoSuchBehaviourException - when no behaviour matches RouteMessage's pattern.
NoBehaviourDispatchedException

copyInto

protected void copyInto(java.util.Vector copy,
                        RouteMessage[] source)

copyInto

protected RouteMessage[] copyInto(java.util.Vector s)