gov.nasa.arc.brahms.vm.rt
Class VMWorkframeCtx

java.lang.Object
  extended by gov.nasa.arc.brahms.common.rt.BrahmsObjectCtx
      extended by gov.nasa.arc.brahms.common.rt.FrameCtx
          extended by gov.nasa.arc.brahms.vm.rt.VMFrameCtx
              extended by gov.nasa.arc.brahms.vm.rt.VMWorkframeCtx
All Implemented Interfaces:
IBrahmsObjectCtx, IFrameCtx, IRuntimeConstants, IWorkframeCtx, gov.nasa.arc.brahms.vm.events.IDiscreteEventData, gov.nasa.arc.brahms.vm.events.IDiscreteEventHandler, java.io.Serializable

public class VMWorkframeCtx
extends VMFrameCtx
implements IWorkframeCtx

The VMWorkframeCtx maintains the state for a workframe and has extensions for use in the virtual machine. In addition to keeping track of the state information as defined in the VMFrameCtx the workframe context also tracks the activity currently executed in the frame, the activities that have completed and the detectable contexts defining the detectables that were executed in the context of the workframe.

Version:
$Revision: 1.4 $ $Date: 2011/10/28 13:36:26 $ $Author: rvanhoof $
Author:
Ron van Hoof
See Also:
VMFrameCtx, Serialized Form

Field Summary
static java.lang.String DETECTABLE
          property name used with DiscreteEvent to indicate a detectable causing a state change
static java.lang.String IMPASSE_RESOLVING_BELIEF
          property name used with DiscreteEvent to indicate a belief resolving the impasse
static java.lang.String INTERRUPTING_FRAME
          Property name used with DiscreteEvent to indicate an interrupting frame
 
Fields inherited from interface gov.nasa.arc.brahms.common.rt.IRuntimeConstants
ABORTED, ACTIVE, ACTIVITY, AVAILABLE, COMPLETED, CONSEQUENCE, ENDED, ENGINE, EXTERNAL_AGENT, FROM, IMPASSED, INITIAL, INTERRUPTED, JAVA_PROPERTY, sABORTED, sACTIVE, sAVAILABLE, sCOMPLETED, sENDED, sIMPASSED, sINTERRUPTED, sUNAVAILABLE, TO, TRANSFER, UNAVAILABLE
 
Constructor Summary
VMWorkframeCtx(VMWorkframe frame)
          Constructor, creates a new context for the specified workframe.
VMWorkframeCtx(VMWorkframe frame, VMActiveInstanceCtx agent)
          Constructor, creates a new context for the specified frame setting the specified agent as the agent working on frame.
 
Method Summary
 void addActiveDetectable(IDetectableCtx detectable)
          Adds the specified detectable as an active detectable to the list of active detectables.
 void addCompletedActivity(ActivityCtx act)
          Adds the specified activity as a completed activity to the list of completed activities.
protected  void doWork(long currentTime)
          Executes work up to the time higher then the time currently being executed.
 java.util.ListIterator getActiveDetectables()
          Returns the list of active detectables.
 java.util.ListIterator getCompletedActivities()
          Returns the list of completed activities.
 ActivityCtx getCurrentActivity()
          Returns the activity currently active in the workframe
 VMWorkframeCtx getLowestCurrentWork()
          Returns the workframe context lowest in the frame hierarchy using this workframe context as the starting point.
protected  int getPreviousStatus()
          Returns the previous status, the status the frame had before the current status.
 int getPriority()
          Returns the priority of the frame context.
 boolean handleDiscreteEvent(gov.nasa.arc.brahms.vm.events.DiscreteEvent evt)
          Process the specified discrete event.
 void onAbort(gov.nasa.arc.brahms.vm.events.DiscreteEvent evt)
          Called when the frame context is aborted.
 void onComplete(gov.nasa.arc.brahms.vm.events.DiscreteEvent evt)
          Called when the frame context is to be completed.
 void onCompleteFinal(gov.nasa.arc.brahms.vm.events.DiscreteEvent evt)
          Called when the frame context was completed by a detectable and all remaining consequences have been fired and their events processed.
 void onContinue(gov.nasa.arc.brahms.vm.events.DiscreteEvent evt)
          Called when the frame context is continued from an interrupt.
 void onContinueFromImpasse(gov.nasa.arc.brahms.vm.events.DiscreteEvent evt)
          Called when the frame context is continued from an impasse.
 void onEnd(gov.nasa.arc.brahms.vm.events.DiscreteEvent evt)
          Called when a frame terminated under normal conditions meaning that there was nothing more to work on.
 void onImpasse(gov.nasa.arc.brahms.vm.events.DiscreteEvent evt)
          Called when the frame context is impassed.
 void onInterrupt(gov.nasa.arc.brahms.vm.events.DiscreteEvent evt)
          Called when the frame context is interrupted.
 void onStart(gov.nasa.arc.brahms.vm.events.DiscreteEvent evt)
          Called when the frame context is started for the first time.
 void removeActiveDetectable(IDetectableCtx detectable)
          Removes the specified detectable as an active detectable from the list of active detectables.
 void removeCompletedActivity(ActivityCtx act)
          Removes the specified activity as a completed activity from the list of completed activities.
 void setCurrentActivity(ActivityCtx act)
          Sets the activity currently active in the workframe
 void setStatus(int status)
          Sets the frame's current status.
protected  void setTestEndCompositeActivity(boolean test)
          Sets the flag indicating whether or not this workframe should test if its current composite activity should be ended due to no more work being available.
protected  void updateDeltaEventTime(IActivityCtx activity, long deltaTime)
          Update the delta event time for the end activity event for the specified activity.
 
Methods inherited from class gov.nasa.arc.brahms.vm.rt.VMFrameCtx
addFrameStatusListener, fireStatusChanged, handleDiscreteEvent, onAvailable, onUnavailable, removeFrameStatusListener
 
Methods inherited from class gov.nasa.arc.brahms.common.rt.FrameCtx
addBinding, addFiredConsequence, getBinding, getBindings, getFiredConsequences, getPerformedBy, getPerformedIn, getState, getStatus, getTimeAvailable, removeBinding, removeFiredConsequence, setPerformedBy, setPerformedIn, setPriority, setState, setState, setTimeAvailable, toString
 
Methods inherited from class gov.nasa.arc.brahms.common.rt.BrahmsObjectCtx
addNote, getContextFor, getEndTime, getID, getNote, getNotes, getStartTime, removeNote, setContextFor, setEndTime, setID, setStartTime
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface gov.nasa.arc.brahms.common.rt.IFrameCtx
addBinding, addFiredConsequence, getBinding, getBindings, getFiredConsequences, getPerformedBy, getPerformedIn, getState, getStatus, getTimeAvailable, removeBinding, removeFiredConsequence, setPerformedBy, setPerformedIn, setPriority, setState, setState, setTimeAvailable
 
Methods inherited from interface gov.nasa.arc.brahms.common.rt.IBrahmsObjectCtx
addNote, getContextFor, getEndTime, getID, getNote, getNotes, getStartTime, removeNote, setEndTime, setID, setStartTime
 

Field Detail

INTERRUPTING_FRAME

public static final java.lang.String INTERRUPTING_FRAME
Property name used with DiscreteEvent to indicate an interrupting frame

See Also:
Constant Field Values

DETECTABLE

public static final java.lang.String DETECTABLE
property name used with DiscreteEvent to indicate a detectable causing a state change

See Also:
Constant Field Values

IMPASSE_RESOLVING_BELIEF

public static final java.lang.String IMPASSE_RESOLVING_BELIEF
property name used with DiscreteEvent to indicate a belief resolving the impasse

See Also:
Constant Field Values
Constructor Detail

VMWorkframeCtx

public VMWorkframeCtx(VMWorkframe frame)
Constructor, creates a new context for the specified workframe.

Parameters:
frame - the Workframe for which this frame context is a context

VMWorkframeCtx

public VMWorkframeCtx(VMWorkframe frame,
                      VMActiveInstanceCtx agent)
Constructor, creates a new context for the specified frame setting the specified agent as the agent working on frame.

Parameters:
frame - the Workframe for which this frame context is a context
agent - the agent working on the frame
Method Detail

getPriority

public int getPriority()
                throws gov.nasa.arc.brahms.common.exceptions.BrahmsException
Returns the priority of the frame context. The priority is calculated by the virtual machine based on the priorities of its activities.

Specified by:
getPriority in interface IFrameCtx
Overrides:
getPriority in class FrameCtx
Returns:
int the frame context's priority
Throws:
gov.nasa.arc.brahms.common.exceptions.BrahmsException - if no priority is set

setTestEndCompositeActivity

protected void setTestEndCompositeActivity(boolean test)
Sets the flag indicating whether or not this workframe should test if its current composite activity should be ended due to no more work being available. This flag is set by the composite activity.

Parameters:
test - true if the test should be performed, false otherwise.

doWork

protected void doWork(long currentTime)
Executes work up to the time higher then the time currently being executed.

Specified by:
doWork in class VMFrameCtx
Parameters:
currentTime - the time at which and for which work can be executed
Throws:
VMError - if an unexpected error occurs in executing the work

setStatus

public void setStatus(int status)
               throws gov.nasa.arc.brahms.common.exceptions.BrahmsException
Sets the frame's current status.

Specified by:
setStatus in interface IFrameCtx
Overrides:
setStatus in class VMFrameCtx
Parameters:
status - the status of the frame context
Throws:
gov.nasa.arc.brahms.common.exceptions.BrahmsException - if status is an invalid status
See Also:
IRuntimeConstants.UNAVAILABLE, IRuntimeConstants.AVAILABLE, IRuntimeConstants.ACTIVE, IRuntimeConstants.INTERRUPTED, IRuntimeConstants.IMPASSED, IRuntimeConstants.ABORTED, IRuntimeConstants.COMPLETED, IRuntimeConstants.ENDED

getPreviousStatus

protected int getPreviousStatus()
Returns the previous status, the status the frame had before the current status. After the frame performed work the previous status is set to the current status to keep track of whether the frame is continuing its work or if it is continuing work after an interrupt.

Returns:
int the previous status of the frame context
See Also:
IRuntimeConstants.UNAVAILABLE, IRuntimeConstants.AVAILABLE, IRuntimeConstants.ACTIVE, IRuntimeConstants.INTERRUPTED, IRuntimeConstants.IMPASSED, IRuntimeConstants.ABORTED, IRuntimeConstants.COMPLETED, IRuntimeConstants.ENDED

setCurrentActivity

public void setCurrentActivity(ActivityCtx act)
Sets the activity currently active in the workframe

Specified by:
setCurrentActivity in interface IWorkframeCtx
Parameters:
act - the current activity (ActivityCtx)

getCurrentActivity

public ActivityCtx getCurrentActivity()
Returns the activity currently active in the workframe

Specified by:
getCurrentActivity in interface IWorkframeCtx
Returns:
ActivityCtx the current activity (ActivityCtx) of the workframe context, null if the workframe context has no activity active

getLowestCurrentWork

public VMWorkframeCtx getLowestCurrentWork()
Returns the workframe context lowest in the frame hierarchy using this workframe context as the starting point. This method returns the lowest current work in the current activity if the activity is a composite activity that has current work specified. If the current activity is not a composite activity or the composite activity has no current work then this workframe context is returned.

Returns:
VMWorkframeCtx the lowest current workframe context

addCompletedActivity

public void addCompletedActivity(ActivityCtx act)
                          throws gov.nasa.arc.brahms.common.exceptions.BrahmsException
Adds the specified activity as a completed activity to the list of completed activities.

Specified by:
addCompletedActivity in interface IWorkframeCtx
Parameters:
act - the ActivityCtx for the activity completed in the workframe
Throws:
gov.nasa.arc.brahms.common.exceptions.BrahmsException - if the activity is null

removeCompletedActivity

public void removeCompletedActivity(ActivityCtx act)
                             throws gov.nasa.arc.brahms.common.exceptions.BrahmsException
Removes the specified activity as a completed activity from the list of completed activities.

Specified by:
removeCompletedActivity in interface IWorkframeCtx
Parameters:
act - the ActivityCtx for the activity to be removed as a completed activity
Throws:
gov.nasa.arc.brahms.common.exceptions.BrahmsException - if the activity is null or no completed activities exist or the specified activity is not found

getCompletedActivities

public java.util.ListIterator getCompletedActivities()
                                              throws gov.nasa.arc.brahms.common.exceptions.BrahmsException
Returns the list of completed activities.

Specified by:
getCompletedActivities in interface IWorkframeCtx
Returns:
ListIterator the list of completed activities (ActivityCtx)
Throws:
gov.nasa.arc.brahms.common.exceptions.BrahmsException - if no completed activities exist

addActiveDetectable

public void addActiveDetectable(IDetectableCtx detectable)
                         throws gov.nasa.arc.brahms.common.exceptions.BrahmsException
Adds the specified detectable as an active detectable to the list of active detectables. An active detectable is actively checked while the workframe is active.

Specified by:
addActiveDetectable in interface IWorkframeCtx
Parameters:
detectable - the IDetectableCtx for the detectable active in the workframe
Throws:
gov.nasa.arc.brahms.common.exceptions.BrahmsException - if the detectable is null

removeActiveDetectable

public void removeActiveDetectable(IDetectableCtx detectable)
                            throws gov.nasa.arc.brahms.common.exceptions.BrahmsException
Removes the specified detectable as an active detectable from the list of active detectables.

Specified by:
removeActiveDetectable in interface IWorkframeCtx
Parameters:
detectable - the IDetectableCtx for the detectable to be removed as an active detectable
Throws:
gov.nasa.arc.brahms.common.exceptions.BrahmsException - if the detectable is null or no active detectables exist or the specified detectable is not found

getActiveDetectables

public java.util.ListIterator getActiveDetectables()
                                            throws gov.nasa.arc.brahms.common.exceptions.BrahmsException
Returns the list of active detectables.

Specified by:
getActiveDetectables in interface IWorkframeCtx
Returns:
ListIterator the list of active detectables (IDetectableCtx)
Throws:
gov.nasa.arc.brahms.common.exceptions.BrahmsException - if no active detectables exist

handleDiscreteEvent

public boolean handleDiscreteEvent(gov.nasa.arc.brahms.vm.events.DiscreteEvent evt)
Process the specified discrete event.

Specified by:
handleDiscreteEvent in interface gov.nasa.arc.brahms.vm.events.IDiscreteEventHandler
Overrides:
handleDiscreteEvent in class VMFrameCtx
Parameters:
evt - the DiscreteEvent to be processed.
Returns:
boolean true if the event could be processed, false if not

onStart

public void onStart(gov.nasa.arc.brahms.vm.events.DiscreteEvent evt)
Called when the frame context is started for the first time.

Overrides:
onStart in class VMFrameCtx
Parameters:
evt - the DiscreteEvent that initiated the start of the frame

onEnd

public void onEnd(gov.nasa.arc.brahms.vm.events.DiscreteEvent evt)
Called when a frame terminated under normal conditions meaning that there was nothing more to work on.

Overrides:
onEnd in class VMFrameCtx
Parameters:
evt - the DiscreteEvent that initiated the end of the frame

onInterrupt

public void onInterrupt(gov.nasa.arc.brahms.vm.events.DiscreteEvent evt)
Called when the frame context is interrupted. Sets the status and notifies the event notifier of the interruption.

Parameters:
evt - the DiscreteEvent that initiated the interruption of the frame

onContinue

public void onContinue(gov.nasa.arc.brahms.vm.events.DiscreteEvent evt)
Called when the frame context is continued from an interrupt. Sets the status and notifies the event notifier of the continuation.

Parameters:
evt - the DiscreteEvent that initiated the continuation of the frame

onImpasse

public void onImpasse(gov.nasa.arc.brahms.vm.events.DiscreteEvent evt)
Called when the frame context is impassed. Sets the status and notifies the event notifier of the impasse.

Parameters:
evt - the DiscreteEvent that initiated the impasse of the frame

onContinueFromImpasse

public void onContinueFromImpasse(gov.nasa.arc.brahms.vm.events.DiscreteEvent evt)
Called when the frame context is continued from an impasse. Sets the status and notifies the event notifier of the continuation after the impasse. Continuation from an impasse means that the frame is moved from the state impasse to the state interrupted.

Parameters:
evt - the DiscreteEvent that initiated the continuation of the frame from an impasse

onAbort

public void onAbort(gov.nasa.arc.brahms.vm.events.DiscreteEvent evt)
Called when the frame context is aborted. Sets the status and notifies the event notifier of the abort. An abort terminates the frame context immediately without completing any activities or consequences.

Parameters:
evt - the DiscreteEvent that initiated the abort of the frame

onComplete

public void onComplete(gov.nasa.arc.brahms.vm.events.DiscreteEvent evt)
Called when the frame context is to be completed. Sets the status and notifies the event notifier of the completion. Completion of a frame context causes the frame to terminate the current activity, skip over any remaining activities, but to fire all consequences following the terminated activity and that are listed in the frame.

Parameters:
evt - the DiscreteEvent that initiated the completion of the frame

onCompleteFinal

public void onCompleteFinal(gov.nasa.arc.brahms.vm.events.DiscreteEvent evt)
Called when the frame context was completed by a detectable and all remaining consequences have been fired and their events processed.

Parameters:
evt - the DiscreteEvent that initiated the completion of the frame

updateDeltaEventTime

protected void updateDeltaEventTime(IActivityCtx activity,
                                    long deltaTime)
Update the delta event time for the end activity event for the specified activity. This method can only be used while the events are still in the next event queue before they are asserted on the active instance's event queue. This method should only be used by activities onContinue. This method is currently only used by the move activities to correct the end time after a move has been interrupted and the agent had moved to a different location while the frame was interrupted.

Parameters:
activity - the activity for which to update the event
deltaTime - the new delta time


Copyright © 1997-2012 All Rights Reserved.