planet.generic.commonapi.behaviours
Class BehavioursInvokerImpl

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

public class BehavioursInvokerImpl
extends java.lang.Object
implements BehavioursInvoker

This class is used to invoke a behaviour. It acts like a facade calling a behaviour only when several preconditions are met. Pre-conditions on this default implementation are probability-based.

Author:
Marc Sanchez, Jordi Pujol
See Also:
Serialized Form

Field Summary
protected  Behaviour beh
          Behaviour object: this properties is a placeholder for a behaviour.
protected  double prob
          Behaviour property: probability to be checked.
 
Constructor Summary
BehavioursInvokerImpl()
          Builds an uninitialized BehavioursInvoker.
 
Method Summary
 java.lang.String getName()
           
 boolean invoke(RouteMessage msg, Node node)
          This method invokes a behaviour.
 BehavioursInvoker setValues(Behaviour behaviour, double probability)
          Initializes this invoker with specified values.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

beh

protected Behaviour beh
Behaviour object: this properties is a placeholder for a behaviour.


prob

protected double prob
Behaviour property: probability to be checked.

Constructor Detail

BehavioursInvokerImpl

public BehavioursInvokerImpl()
Builds an uninitialized BehavioursInvoker. Requires to invoke setValues(...) method.

Method Detail

setValues

public BehavioursInvoker setValues(Behaviour behaviour,
                                   double probability)
Initializes this invoker with specified values.

Parameters:
behaviour - Behaviour to be invoked at any incomming RouteMessage
probability - The probability to be checked at any invokation of specified Behaviour.
Returns:
This same instance once has been initialized.

invoke

public boolean invoke(RouteMessage msg,
                      Node node)
This method invokes a behaviour.

Specified by:
invoke in interface BehavioursInvoker
Parameters:
msg - The RouteMessage recently arrived.
node - The Node which holds the behaviour.
Returns:
Returns a BehaviourInvokerStatus with replies from the behaviour's invocation and a boolean signaling if the invocation was finally made.

getName

public java.lang.String getName()
Returns:
Returns the name of a behaviour.

toString

public java.lang.String toString()
Returns:
Returns a string representation of the behaviour. In general, the toString method returns a string that "textually represents" this behaviour. The result should be a concise but informative representation that is easy for a person to read.