se.liu.ida.critiquer.activities
Class Activity

java.lang.Object
  extended by se.liu.ida.critiquer.activities.Activity
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
DefaultActivity, DispatchActivity, FirstAidActivity, RecoverActivity, RoadBlockActivity, ToplevelActivity

public abstract class Activity
extends Object
implements Serializable

Base class for all types of activities in a plan.

Author:
olale
See Also:
Serialized Form

Nested Class Summary
static interface Activity.Properties
          Interface for recognizing state properties of activities during simulation.
 
Field Summary
 String type
           
 
Constructor Summary
Activity()
          Creates a dummy placeholder activity, not to be used in tasks
Activity(Activity parent)
           
Activity(String type, Activity parent)
           
 
Method Summary
 void acquirePendingUpdatesLock()
           
static void addActivityUpdateListener(ActivityUpdateListener ul)
           
 void addAll(ArrayList<Activity> c)
           
 void addChild(Activity child)
           
 void addDefaultParams()
          Add name, description, start and end time for all activities
static void addNameChangeListener(NameChangeListener listener)
           
<T> void
addParam(ActivityParameter<T> p)
           
 void addPrivateUpdateListener(ActivityUpdateListener l)
          Adds an activity update listener
static void addStaticConsistencyChecker(ActivityConsistencyCheck checker)
           
 boolean canBeChildOf(Activity parent)
          Can this activity be a child of parent?
abstract  boolean canBeSimulated()
          Test if this activity can be simulated.
 boolean canComeBefore(Activity activity)
          Can this activity come before activity in a mission?
 void debug(Object arg0)
           
 void endParentRelationship()
          Decouple this agent from its parent
 boolean equals(Object o)
           
 void error(Object arg0)
           
 void fatal(Object arg0)
           
 Semaphore getAtomicUpdateLock()
           
 ArrayList<Activity> getChildren()
           
 Date getEndTime()
           
 long getMaxTime()
           
(package private)  ArrayList<ActivityUpdateListener> getMyUpdateListeners()
           
abstract  int getNumActivities()
          Each subclass of Activity should have a static counter of how many activities have been created, so that we may create unique new names for newly created activities.
 ArrayList<ActivityParameter> getParams()
           
 Activity getParent()
           
 int getPendingupdates()
           
 Activity getRootActivity()
           
 Date getStartTime()
           
static ArrayList<ActivityConsistencyCheck> getStaticConsistencyCheckers()
           
static ArrayList<ActivityUpdateListener> getStaticUpdateListeners()
           
 HashSet<TimeParameterOrdering> getTemporalConstraints()
           
 boolean hasParent()
           
 int indexOfChild(Activity activity)
           
 void info(Object arg0)
           
 void initParentRelationship(Activity parent)
          Called when an activity is added to an overarching activity.
 boolean isAgentAssignable()
          This method indicates whether or not an activity can be assigned an agent or if it should inherit agents from parent activities.
static
<T> boolean
isConsistent(Activity a, Parameter<T> p, T newValue)
           
 void order(Activity laterActivity)
           Introduce an ordering between two activities by ordering the end time parameter of the current activity before the start time parameter of a2.
 void postLoad()
           This function is called when an activity is deserialized.
 void preSave()
           
 void releasePendingUpdatesLock()
           
 void removeChild(Activity currentActivity)
           
 void removeChildren()
           
 void removeOrder(Activity laterActivity)
           Remove the temporal ordering between the current activity and a2 TODO: This could be an instance method so that additional ordering information could be added by subclasses, if location parameters need to be syncronized for instance
 void removePrivateUpdateListener(ActivityUpdateListener l)
           
 void setParent(Activity parent)
           
 void signalActivityRemoved()
          Notify activity listeners that this activity has been removed from the plan
 void signalActivityUpdated()
          When the activity is updated in some way, but not through parameter values, this method is called
 void signalParamChanged()
          create a new activity parameter nobody should be interested in per se and fire a paramChanged event with that parameter
<T> void
signalParamChanged(Parameter<T> p)
           
abstract  long simulate()
          Calculates the effects of performing a mission with respect to some state.
 String toString()
           
 void warn(Object arg0)
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

type

public String type
Constructor Detail

Activity

public Activity()
Creates a dummy placeholder activity, not to be used in tasks


Activity

public Activity(Activity parent)

Activity

public Activity(String type,
                Activity parent)
Method Detail

getPendingupdates

public int getPendingupdates()

acquirePendingUpdatesLock

public void acquirePendingUpdatesLock()

releasePendingUpdatesLock

public void releasePendingUpdatesLock()

getNumActivities

public abstract int getNumActivities()
Each subclass of Activity should have a static counter of how many activities have been created, so that we may create unique new names for newly created activities.

Returns:
the number of objects of this class that have been created.

getRootActivity

public Activity getRootActivity()

initParentRelationship

public void initParentRelationship(Activity parent)
Called when an activity is added to an overarching activity.

Parameters:
parent -

isAgentAssignable

public boolean isAgentAssignable()
This method indicates whether or not an activity can be assigned an agent or if it should inherit agents from parent activities. It is determined by whether or not there is a commander assigned to the activity.


endParentRelationship

public void endParentRelationship()
Decouple this agent from its parent


addActivityUpdateListener

public static void addActivityUpdateListener(ActivityUpdateListener ul)

getParams

public ArrayList<ActivityParameter> getParams()
Returns:
Returns the params.

addParam

public <T> void addParam(ActivityParameter<T> p)

isConsistent

public static <T> boolean isConsistent(Activity a,
                                       Parameter<T> p,
                                       T newValue)

signalParamChanged

public void signalParamChanged()
create a new activity parameter nobody should be interested in per se and fire a paramChanged event with that parameter


signalActivityUpdated

public void signalActivityUpdated()
When the activity is updated in some way, but not through parameter values, this method is called


signalActivityRemoved

public void signalActivityRemoved()
Notify activity listeners that this activity has been removed from the plan


signalParamChanged

public <T> void signalParamChanged(Parameter<T> p)

addPrivateUpdateListener

public void addPrivateUpdateListener(ActivityUpdateListener l)
Adds an activity update listener

Parameters:
l -

removePrivateUpdateListener

public void removePrivateUpdateListener(ActivityUpdateListener l)

toString

public String toString()
Overrides:
toString in class Object

hasParent

public boolean hasParent()

getParent

public Activity getParent()
Returns:
Returns the parent.

setParent

public void setParent(Activity parent)
Parameters:
parent - The parent to set.

addDefaultParams

public void addDefaultParams()
Add name, description, start and end time for all activities


addChild

public void addChild(Activity child)

removeChild

public void removeChild(Activity currentActivity)

getChildren

public ArrayList<Activity> getChildren()
Returns:
Returns the children.

addAll

public void addAll(ArrayList<Activity> c)

removeChildren

public void removeChildren()

getStartTime

public Date getStartTime()

getEndTime

public Date getEndTime()

addNameChangeListener

public static void addNameChangeListener(NameChangeListener listener)

equals

public boolean equals(Object o)
Overrides:
equals in class Object

getStaticUpdateListeners

public static ArrayList<ActivityUpdateListener> getStaticUpdateListeners()
Returns:
Returns the staticUpdateListeners.

getMyUpdateListeners

ArrayList<ActivityUpdateListener> getMyUpdateListeners()
Returns:
Returns the staticUpdateListeners.

indexOfChild

public int indexOfChild(Activity activity)

simulate

public abstract long simulate()
                       throws IncompleteActivityException
Calculates the effects of performing a mission with respect to some state. This is supposed to be used during simulation.

Parameters:
-
Throws:
IncompleteActivityException

canBeSimulated

public abstract boolean canBeSimulated()
Test if this activity can be simulated. This usually entails checking that some structural constraints hold. It is assumed that this method is checked before any simulation or time calculation takes place.

Returns:

getMaxTime

public long getMaxTime()

postLoad

public void postLoad()

This function is called when an activity is deserialized.


getTemporalConstraints

public HashSet<TimeParameterOrdering> getTemporalConstraints()
Returns:
Returns the temporalConstraints.

preSave

public void preSave()

removeOrder

public void removeOrder(Activity laterActivity)

Remove the temporal ordering between the current activity and a2

TODO: This could be an instance method so that additional ordering information could be added by subclasses, if location parameters need to be syncronized for instance

Parameters:
laterActivity - the activity that was ordered after this
See Also:
for more information.

order

public void order(Activity laterActivity)

Introduce an ordering between two activities by ordering the end time parameter of the current activity before the start time parameter of a2.

TODO: Possibly add other constraints that relate to ordering two consecutive actions

Parameters:
laterActivity - The activity that should come after this

canBeChildOf

public boolean canBeChildOf(Activity parent)
Can this activity be a child of parent?


canComeBefore

public boolean canComeBefore(Activity activity)
Can this activity come before activity in a mission?


getStaticConsistencyCheckers

public static ArrayList<ActivityConsistencyCheck> getStaticConsistencyCheckers()
Returns:
Returns the staticConsistencyCheckers.

addStaticConsistencyChecker

public static void addStaticConsistencyChecker(ActivityConsistencyCheck checker)
Parameters:
checker - The ActivityConsistencyChecker to add.

getAtomicUpdateLock

public Semaphore getAtomicUpdateLock()
Returns:
Returns the atomicUpdateLock.

debug

public void debug(Object arg0)
See Also:
Category.debug(java.lang.Object)

error

public void error(Object arg0)
See Also:
Category.error(java.lang.Object)

fatal

public void fatal(Object arg0)
See Also:
Category.fatal(java.lang.Object)

info

public void info(Object arg0)
See Also:
Category.info(java.lang.Object)

warn

public void warn(Object arg0)
See Also:
Category.warn(java.lang.Object)