orca.shirako.core
Class Policy

java.lang.Object
  extended by orca.shirako.core.Policy
All Implemented Interfaces:
IInitialize, IPolicy, IRecover, ISerialize
Direct Known Subclasses:
AuthorityPolicy, BrokerPolicy, ServiceManagerPolicy

public class Policy
extends java.lang.Object
implements IPolicy

Base class to simplify policy development.


Field Summary
protected  IActor actor
          Actor this policy belongs to.
protected  ActorClock clock
          The converter from real to local time
protected  ID guid
          Policy guid.
protected  LoggingTool logger
          Logger in use by this mapper.
static java.lang.String PropertyGuid
           
 
Constructor Summary
Policy()
          Default constructor.
Policy(Actor actor)
          Creates a new mapper instance.
 
Method Summary
 void close(ResourceReservation reservation)
          Notifies the policy that a reservation is about to be closed.
 void closed(ResourceReservation reservation)
          Notifies the policy that a reservation has been closed.
protected  void error(java.lang.String string)
           
 void extend(ResourceReservation reservation, ResourceSet resources, Term term)
          Notifies the policy that a reservation is about to be extended.
 void finish(long cycle)
          Informs the mapper that all processing for the specified cycle is complete.
 ReservationSet getClosing(long cycle)
          Returns a set of reservations that must be closed.
 ID getGuid()
          Returns the globally unique identifier of this policy object instance.
 void initialize()
          Initializes the object.
protected  void internalError(java.lang.String string)
           
protected  void logError(java.lang.String string)
           
protected  void logWarn(java.lang.String string)
           
 void prepare(long cycle)
          Informs the policy that processing for a new cycle is about to begin.
 java.util.Properties query(java.util.Properties properties)
          Answers a query from another actor.
 void remove(ResourceReservation reservation)
          Notifies the policy that a reservation is about to be removed.
 void reset()
          Post recovery entry point.
 void reset(java.util.Properties p)
          De-serializes the object from the given properties list.
 void revisit(IActor actor, java.util.Properties properties)
          Recovers state of the component using a previously saved properties list and a references to the actor this component belongs to.
 void revisit(ResourceReservation reservation)
          Informs the mapper about a reservation.
 java.util.Properties save()
          Serializes the object into a properties list.
 void save(java.util.Properties p)
          Serializes the object into the given properties list.
 void setActor(IActor actor)
          Sets the actor the mapper belongs to.
 void setLogger(LoggingTool logger)
          Sets the logger to be used by the mapper.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PropertyGuid

public static final java.lang.String PropertyGuid
See Also:
Constant Field Values

logger

protected LoggingTool logger
Logger in use by this mapper.


actor

protected IActor actor
Actor this policy belongs to.


clock

protected ActorClock clock
The converter from real to local time


guid

protected ID guid
Policy guid.

Constructor Detail

Policy

public Policy()
Default constructor.


Policy

public Policy(Actor actor)
Creates a new mapper instance.

Parameters:
actor - actor this mapper belongs to
Method Detail

initialize

public void initialize()
                throws java.lang.Exception
Description copied from interface: IInitialize
Initializes the object.

Specified by:
initialize in interface IInitialize
Throws:
java.lang.Exception

save

public java.util.Properties save()
                          throws java.lang.Exception
Description copied from interface: ISerialize
Serializes the object into a properties list.

Specified by:
save in interface ISerialize
Returns:
properties list representing this object
Throws:
java.lang.Exception

save

public void save(java.util.Properties p)
          throws java.lang.Exception
Description copied from interface: ISerialize
Serializes the object into the given properties list.

Specified by:
save in interface ISerialize
Parameters:
p - properties list to serialize the object into
Throws:
java.lang.Exception

reset

public void reset(java.util.Properties p)
           throws java.lang.Exception
Description copied from interface: ISerialize
De-serializes the object from the given properties list.

Specified by:
reset in interface ISerialize
Parameters:
p - properties list containing the serialized version of the object
Throws:
java.lang.Exception

query

public java.util.Properties query(java.util.Properties properties)
Description copied from interface: IPolicy
Answers a query from another actor. This method is intended to be used to obtain policy-specific parameters and information. This method should be used when writing more complex policies requiring additional interaction among actors. Instead of extending the proxies to support passing/obtaining the required information, policy code can use the query interface to request/obtain such information. This method is invoked with the kernel lock on: the implementation should not block for prolonged periods of time. If necessary, future versions will update this interface two allow query responses to be delivered using callbacks.

Specified by:
query in interface IPolicy
Returns:
a properties list of outgoing values. If the incoming properties collection is null or empty, should return all possible properties that can be relevant to the caller.

close

public void close(ResourceReservation reservation)
Description copied from interface: IPolicy
Notifies the policy that a reservation is about to be closed. This method will be invoked for every reservation that is about to be closed, even if the close was triggered by the policy itself. The policy should update its internal state/cancel pending operations associated with the reservation. This method is invoked with the kernel lock on.

Specified by:
close in interface IPolicy
Parameters:
reservation - reservation about to close

closed

public void closed(ResourceReservation reservation)
Description copied from interface: IPolicy
Notifies the policy that a reservation has been closed. This method will be invoked for every reservation that closes successfully. The policy must uncommit any resources associated with the reservation, e.g, physical machines, currency, etc. This method is invoked with the kernel lock on.

Note: For an authority resources are released using the #IAuthorityPolicy.release(ResourceSet) method. Authority policy implementations should not consider the resources of the passed reservation as released. The release will take place once all configuration actions complete.

Specified by:
closed in interface IPolicy
Parameters:
reservation - closed reservation
See Also:
IAuthorityPolicy.release(ResourceSet)

extend

public void extend(ResourceReservation reservation,
                   ResourceSet resources,
                   Term term)
Description copied from interface: IPolicy
Notifies the policy that a reservation is about to be extended. This method will be invoked only for reservations, whose extensions have not been triggered by the policy, e.g, from the management interface. The policy should update its state to reflect the extend request. This method is invoked with the kernel lock on.

Specified by:
extend in interface IPolicy
Parameters:
reservation - reservation to be extended
resources - resource set used for the extension
term - term used for the extension

remove

public void remove(ResourceReservation reservation)
Description copied from interface: IPolicy
Notifies the policy that a reservation is about to be removed. This method will be invoked for each reservation that is to be removed from the system. The policy should remove any state that it maintains for the reservation. This method is invoked with the kernel lock on.

Note: Only failed and closed reservations can be removed. The system will not invoke this method if the reservation is not closed or failed.

Specified by:
remove in interface IPolicy
Parameters:
reservation - reservation to be removed

revisit

public void revisit(ResourceReservation reservation)
             throws java.lang.Exception
Description copied from interface: IPolicy
Informs the mapper about a reservation. Called during recovery/startup. The mapper must re-establish any state required for the management of the reservation.

Specified by:
revisit in interface IPolicy
Throws:
java.lang.Exception

reset

public void reset()
           throws java.lang.Exception
Description copied from interface: IPolicy
Post recovery entry point. This method will be invoked once all revisit operations are complete and the actor is ready to operate normally.

Specified by:
reset in interface IPolicy
Throws:
java.lang.Exception

revisit

public void revisit(IActor actor,
                    java.util.Properties properties)
             throws java.lang.Exception
Description copied from interface: IRecover
Recovers state of the component using a previously saved properties list and a references to the actor this component belongs to. The component can use the actor object to access other objects necessary for its complete recovery.

Specified by:
revisit in interface IRecover
Parameters:
actor - actor object the component belongs to
properties - properties list containing configuration data about the component
Throws:
java.lang.Exception

getClosing

public ReservationSet getClosing(long cycle)
Description copied from interface: IPolicy
Returns a set of reservations that must be closed. This method is invoked with the kernel lock on.

Specified by:
getClosing in interface IPolicy
Parameters:
cycle - the current cycle

prepare

public void prepare(long cycle)
Description copied from interface: IPolicy
Informs the policy that processing for a new cycle is about to begin. The policy should initialize whatever internal state is necessary to process a new cycle. This method is invoked with the kernel lock on.

Note: The cycle number parameter is redundant and is passed for convenience. The policy can always obtain the cycle number by calling IActor.getCurrentCycle().

Specified by:
prepare in interface IPolicy
Parameters:
cycle - the cycle number that is about to be processed

finish

public void finish(long cycle)
Description copied from interface: IPolicy
Informs the mapper that all processing for the specified cycle is complete. The mapper can safely discard any state associated with the cycle or any previous cycles. This method is invoked with the kernel lock on.

Note: The cycle number parameter is redundant and is passed for convenience. The policy can always obtain the cycle number by calling IActor.getCurrentCycle().

Specified by:
finish in interface IPolicy
Parameters:
cycle - the cycle number that has just passed

error

protected void error(java.lang.String string)
              throws java.lang.Exception
Throws:
java.lang.Exception

internalError

protected void internalError(java.lang.String string)
                      throws java.lang.Exception
Throws:
java.lang.Exception

logError

protected void logError(java.lang.String string)

logWarn

protected void logWarn(java.lang.String string)

setActor

public void setActor(IActor actor)
Description copied from interface: IPolicy
Sets the actor the mapper belongs to.

Specified by:
setActor in interface IPolicy
Parameters:
actor - the actor the mapper belongs to

setLogger

public void setLogger(LoggingTool logger)
Description copied from interface: IPolicy
Sets the logger to be used by the mapper.

Specified by:
setLogger in interface IPolicy
Parameters:
logger - logger to use

getGuid

public ID getGuid()
Description copied from interface: IPolicy
Returns the globally unique identifier of this policy object instance. Each policy object instance should have a unique guid.

Specified by:
getGuid in interface IPolicy
Returns:


Copyright © 2007 Network/Internet Computing Lab. All Rights Reserved.