Triveni

triveni
Class Activity

java.lang.Object
  |
  +--triveni.Communicator
        |
        +--triveni.Activity
Direct Known Subclasses:
Assertion, Clock, ControlPanel, Counter, ManualClock, ThreadActivity

public abstract class Activity
extends Communicator

An Activity is a software component that combines three aspects of behavior:

Activities are used as subcomponents of Triveni systems by wrapping them inside an Act expression. They are controlled (started, stopped, suspended, resumed) by the surrounding system.

All three aspects of behavior may result in the emission of events to the surrounding system (the activities' environment). However, care must be taken to avoid deadlock when emitting an event in response to an incoming event. The response event must be emitted in a separate thread. See also the setUpdateHandler method.

Subclasses override the methods onStart, onStop, onSuspend, and onResume as needed. Subclasses should also override clone if they have their own reference instance variables.

Subclasses may handle incoming events either manually by overriding update, or preferably by using the method setUpdateHandler to specify a Triveni expression for this purpose. If incoming events are handled manually, the activity must use setRelevantLabels to specify which incoming events it is interested in.

See Also:
LabeledEvent, Expr, Act, ThreadActivity

Constructor Summary
Activity()
           
 
Method Summary
protected  void clearQuiescent()
          Invoked by subclasses to indicate that a new round of event processing is about to start.
 java.lang.Object clone()
           
 void emitEvent(LabeledEvent evt)
           
 void emitEvent(java.lang.Object label)
           emitEvent(new LabeledEvent(label, null))
 void emitEvent(java.lang.Object label, java.lang.Object evt)
           emitEvent(new LabeledEvent(label, evt, this))
 void emitInterruptibly(LabeledEvent evt)
          Causes this activity to emit a labeled event to the environment.
 void emitInterruptibly(java.lang.Object label)
           emitInterruptibly(new LabeledEvent(label, null))
 void emitInterruptibly(java.lang.Object label, java.lang.Object evt)
           emitInterruptibly(new LabeledEvent(label, evt, this))
 boolean isQuiescent()
          Whether this activity is currently quiescent.
 boolean isStopped()
          Whether this activity is currently stopped.
 boolean isSuspended()
          Whether this activity is currently suspended.
protected  void onEmit()
          Subclasses should put here any code to be executed when the activity emits an event.
protected  void onResume()
          Subclasses should put here any code to be executed when the activity is resumed.
protected  void onStart()
          Subclasses should put here any code to be executed when the activity is started.
protected  void onStop()
          Subclasses should put here any code to be executed when the activity is stopped.
protected  void onSuspend()
          Subclasses should put here any code to be executed when the activity is suspended.
protected  void setQuiescent()
          Invoked by subclasses to indicate that the current round of event processing has terminated and the activity has quiesced.
protected  void setUpdateHandler(Expr updateHandler)
          This method is used to provide the activity with a Triveni expression that handles incoming events.
 void update(LabeledEvent evt)
          Handles incoming events.
 
Methods inherited from class triveni.Communicator
addLabeledListener, addRelevantLabel, addRelevantLabels, fireEvent, getRelevantLabels, removeLabeledListener, removeRelevantLabel, setRelevantLabels, setRelevantLabels
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Activity

public Activity()
Method Detail

setUpdateHandler

protected final void setUpdateHandler(Expr updateHandler)
This method is used to provide the activity with a Triveni expression that handles incoming events. Unlike Triveni expressions used outside of activities, update handlers must not emit events directly to avoid deadlock. If an update handler must emit a response event, it should do so in an action by using emitEvent in a separate thread, for example, using the method javax.swing.SwingUtilities.invokeLater.
Parameters:
updateHandler - the Triveni expression that handles incoming events.

setQuiescent

protected final void setQuiescent()
Invoked by subclasses to indicate that the current round of event processing has terminated and the activity has quiesced.

clearQuiescent

protected final void clearQuiescent()
Invoked by subclasses to indicate that a new round of event processing is about to start.

update

public void update(LabeledEvent evt)
            throws java.lang.InterruptedException
Handles incoming events. This method should be overridden only if incoming events are not handled via a Triveni expression provided using the setUpdateHandler method. This method must not emit response events directly to avoid deadlock; instead, a separate thread should be used.
Throws:
java.lang.InterruptedException - when the current thread is interrupted.
See Also:
setUpdateHandler(Expr)

onStart

protected void onStart()
Subclasses should put here any code to be executed when the activity is started.

onStop

protected void onStop()
Subclasses should put here any code to be executed when the activity is stopped.

onSuspend

protected void onSuspend()
Subclasses should put here any code to be executed when the activity is suspended.

onResume

protected void onResume()
Subclasses should put here any code to be executed when the activity is resumed.

onEmit

protected void onEmit()
Subclasses should put here any code to be executed when the activity emits an event.

isStopped

public final boolean isStopped()
Whether this activity is currently stopped.

isSuspended

public final boolean isSuspended()
Whether this activity is currently suspended.

isQuiescent

public boolean isQuiescent()
Whether this activity is currently quiescent.

emitInterruptibly

public final void emitInterruptibly(LabeledEvent evt)
                             throws java.lang.InterruptedException
Causes this activity to emit a labeled event to the environment.
Throws:
java.lang.InterruptedException - when the current thread is interrupted.

emitInterruptibly

public final void emitInterruptibly(java.lang.Object label,
                                    java.lang.Object evt)
                             throws java.lang.InterruptedException
 emitInterruptibly(new LabeledEvent(label, evt, this))
 

emitInterruptibly

public final void emitInterruptibly(java.lang.Object label)
                             throws java.lang.InterruptedException
 emitInterruptibly(new LabeledEvent(label, null))
 

emitEvent

public final void emitEvent(LabeledEvent evt)

emitEvent

public final void emitEvent(java.lang.Object label,
                            java.lang.Object evt)
 emitEvent(new LabeledEvent(label, evt, this))
 

emitEvent

public final void emitEvent(java.lang.Object label)
 emitEvent(new LabeledEvent(label, null))
 

clone

public java.lang.Object clone()
Overrides:
clone in class Communicator

Triveni

http://www.cs.luc.edu/triveni/