Trull

edu.luc.cs.trull
Class Suspend

java.lang.Object
  extended by edu.luc.cs.trull.EmptyComponent
      extended by edu.luc.cs.trull.TerminatingComponent
          extended by edu.luc.cs.trull.AbstractComponent
              extended by edu.luc.cs.trull.AbstractCombinator
                  extended by edu.luc.cs.trull.SingleChildCombinator
                      extended by edu.luc.cs.trull.Suspend
All Implemented Interfaces:
Combinator, Component, PropertyChangeSource, Startable, Suspendable, Terminating, java.beans.PropertyChangeListener, java.util.EventListener

public class Suspend
extends SingleChildCombinator

A combinator for mapping sets of events to a component's lifecycle methods suspend and resume. It behaves as follows. First, the body component is executed automatically. If, before the body terminates, an event occurs whose label matches the suspend labels, then the execution of the body is suspended. If, while the body is suspended, an event occurs whose label matches the resume labels, then the execution of the body is resumed where it had been suspended.

See Also:
Control, Watching

Nested Class Summary
protected  class Suspend.LocalListener
          A dedicated listener that forwards the event to all external listeners.
protected  class Suspend.SuspendTerminationListener
          This component terminates when its child component terminates.
 
Nested classes/interfaces inherited from class edu.luc.cs.trull.AbstractCombinator
AbstractCombinator.DefaultTerminationListener
 
Field Summary
private  java.beans.PropertyChangeListener internalListener
          The internal listener that listens to the child component.
private static org.apache.log4j.Logger logger
           
private  java.beans.PropertyChangeListener resumeAction
          An action to be invoked when a resume event is received.
private  java.util.Set resumeEvents
          The set of triggering events for resuming this component.
private  java.beans.PropertyChangeListener suspendAction
          An action to be invoked when a susupend event is received.
private  boolean suspended
          The current state of this component.
private  java.util.Set suspendEvents
          The set of triggering events for suspending this component.
private  TerminationListener terminationListener
          The child termination listener for this component.
 
Fields inherited from class edu.luc.cs.trull.AbstractCombinator
components
 
Constructor Summary
Suspend()
          Constructs a Suspend component.
Suspend(Component body)
          Suspend([], [], body)
Suspend(java.lang.String[] suspendLabels, java.beans.PropertyChangeListener suspendAction, java.lang.String[] resumeLabels, java.beans.PropertyChangeListener resumeAction, Component body)
          Constsructs a Suspend component.
Suspend(java.lang.String[] suspendLabels, java.lang.String[] resumeLabels, Component body)
          Suspend([suspendLabel], null, [resumeLabel], null, body)
Suspend(java.lang.String suspendLabel, java.beans.PropertyChangeListener suspendAction, java.lang.String resumeLabel, java.beans.PropertyChangeListener resumeAction, Component body)
          Suspend([suspendLabel], suspendAction, [resumeLabel], resumeAction, body)
Suspend(java.lang.String suspendLabel, java.lang.String resumeLabel, Component body)
          Suspend([suspendLabel], [resumeLabel], body)
 
Method Summary
protected  TerminationListener getChildTerminationListener()
          Returns the internal listener that is notified if the child component terminates.
protected  Component getDefaultChild()
          This method returns the default child component.
protected  java.beans.PropertyChangeListener getInternalListener()
          Returns the internal listener that listens to the child component.
 java.beans.PropertyChangeListener getResumeAction()
          Returns the action invoked upon receiving a resuming event.
 java.lang.String[] getResumeEvents()
          Returns the array of resuming event labels for this component.
 java.beans.PropertyChangeListener getSuspendAction()
          Returns the action invoked upon receiving a suspending event.
 java.lang.String[] getSuspendEvents()
          Returns the array of suspending event labels for this component.
 void propertyChange(java.beans.PropertyChangeEvent evt)
          Forwards incoming events to the child component.
protected  void resumeChild(java.beans.PropertyChangeEvent incoming)
          Resumes the child component.
 void setResumeAction(java.beans.PropertyChangeListener action)
          Sets the action invoked upon receiving a resuming event.
 void setResumeEvent(java.lang.String label)
          Sets the resuming event label for this component to the given string.
 void setResumeEvents(java.util.Collection evts)
          Sets the resuming event labels for this component to the given collection of strings.
 void setResumeEvents(java.lang.String[] labels)
          Sets the resuming event labels for this component to the given array of strings.
 void setSuspendAction(java.beans.PropertyChangeListener action)
          Sets the action invoked upon receiving a suspending event.
 void setSuspendEvent(java.lang.String label)
          Sets the suspending event label for this component to the given string.
 void setSuspendEvents(java.util.Collection evts)
          Sets the suspending event labels for this component to the given collection of strings.
 void setSuspendEvents(java.lang.String[] labels)
          Sets the suspending event labels for this component to the given array of strings.
 void start(java.beans.PropertyChangeEvent incoming)
          Starts this startable component.
protected  void suspendChild(java.beans.PropertyChangeEvent incoming)
          Suspends the child component.
 
Methods inherited from class edu.luc.cs.trull.SingleChildCombinator
addComponent, getChild, removeComponent, resume, stop, suspend
 
Methods inherited from class edu.luc.cs.trull.AbstractCombinator
addComponent, addComponent, getComponent, getComponentCount, getComponents, removeAllComponents, removeComponent
 
Methods inherited from class edu.luc.cs.trull.AbstractComponent
addPropertyChangeListener, firePropertyChange, firePropertyChange, firePropertyChange, getExternalListeners, getPropertyChangeListeners, removePropertyChangeListener
 
Methods inherited from class edu.luc.cs.trull.TerminatingComponent
fireTermination, getParent, getTermEvent, scheduleTermination, setTerminationListener
 
Methods inherited from class edu.luc.cs.trull.EmptyComponent
getTerminationListener
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface edu.luc.cs.trull.PropertyChangeSource
addPropertyChangeListener, getPropertyChangeListeners, removePropertyChangeListener
 
Methods inherited from interface edu.luc.cs.trull.Terminating
getTerminationListener, setTerminationListener
 

Field Detail

internalListener

private java.beans.PropertyChangeListener internalListener
The internal listener that listens to the child component.


logger

private static final org.apache.log4j.Logger logger

resumeAction

private java.beans.PropertyChangeListener resumeAction
An action to be invoked when a resume event is received.


resumeEvents

private java.util.Set resumeEvents
The set of triggering events for resuming this component.


suspendAction

private java.beans.PropertyChangeListener suspendAction
An action to be invoked when a susupend event is received.


suspended

private boolean suspended
The current state of this component.


suspendEvents

private java.util.Set suspendEvents
The set of triggering events for suspending this component.


terminationListener

private TerminationListener terminationListener
The child termination listener for this component.

Constructor Detail

Suspend

public Suspend()
Constructs a Suspend component. Specific properties can be changed later.


Suspend

public Suspend(Component body)
Suspend([], [], body)


Suspend

public Suspend(java.lang.String[] suspendLabels,
               java.beans.PropertyChangeListener suspendAction,
               java.lang.String[] resumeLabels,
               java.beans.PropertyChangeListener resumeAction,
               Component body)
Constsructs a Suspend component.

Parameters:
suspendLabels - the event labels on which the body is suspended.
suspendAction - the action invoked upon suspending. May be null.
resumeLabels - the event labels on which the body is resumed.
resumeAction - the action invoked upon resuming. May be null.
body - the body of the component. If null, Nil is used.

Suspend

public Suspend(java.lang.String[] suspendLabels,
               java.lang.String[] resumeLabels,
               Component body)
Suspend([suspendLabel], null, [resumeLabel], null, body)


Suspend

public Suspend(java.lang.String suspendLabel,
               java.beans.PropertyChangeListener suspendAction,
               java.lang.String resumeLabel,
               java.beans.PropertyChangeListener resumeAction,
               Component body)
Suspend([suspendLabel], suspendAction, [resumeLabel], resumeAction, body)


Suspend

public Suspend(java.lang.String suspendLabel,
               java.lang.String resumeLabel,
               Component body)
Suspend([suspendLabel], [resumeLabel], body)

Method Detail

getChildTerminationListener

protected TerminationListener getChildTerminationListener()
Description copied from class: AbstractCombinator
Returns the internal listener that is notified if the child component terminates.

Specified by:
getChildTerminationListener in class AbstractCombinator
Returns:
the termination listener.

getDefaultChild

protected Component getDefaultChild()
Description copied from class: SingleChildCombinator
This method returns the default child component.

Specified by:
getDefaultChild in class SingleChildCombinator

getInternalListener

protected java.beans.PropertyChangeListener getInternalListener()
Description copied from class: SingleChildCombinator
Returns the internal listener that listens to the child component.

Specified by:
getInternalListener in class SingleChildCombinator

getResumeAction

public java.beans.PropertyChangeListener getResumeAction()
Returns the action invoked upon receiving a resuming event.

Returns:
the resume action.

getResumeEvents

public java.lang.String[] getResumeEvents()
Returns the array of resuming event labels for this component.

Returns:
the resuming event labels.

getSuspendAction

public java.beans.PropertyChangeListener getSuspendAction()
Returns the action invoked upon receiving a suspending event.

Returns:
the suspend action.

getSuspendEvents

public java.lang.String[] getSuspendEvents()
Returns the array of suspending event labels for this component.

Returns:
the suspending event labels.

propertyChange

public void propertyChange(java.beans.PropertyChangeEvent evt)
Forwards incoming events to the child component.

Specified by:
propertyChange in interface java.beans.PropertyChangeListener
Overrides:
propertyChange in class SingleChildCombinator
Parameters:
evt - the event received.

resumeChild

protected void resumeChild(java.beans.PropertyChangeEvent incoming)
Resumes the child component.

Parameters:
incoming - the resuming event.

setResumeAction

public void setResumeAction(java.beans.PropertyChangeListener action)
Sets the action invoked upon receiving a resuming event.

Parameters:
action - the resume action.

setResumeEvent

public void setResumeEvent(java.lang.String label)
Sets the resuming event label for this component to the given string.

Parameters:
label - the resuming event label.

setResumeEvents

public void setResumeEvents(java.util.Collection evts)
Sets the resuming event labels for this component to the given collection of strings.

Parameters:
evts - the resuming event labels.

setResumeEvents

public void setResumeEvents(java.lang.String[] labels)
Sets the resuming event labels for this component to the given array of strings.

Parameters:
labels - the resuming event labels.

setSuspendAction

public void setSuspendAction(java.beans.PropertyChangeListener action)
Sets the action invoked upon receiving a suspending event.

Parameters:
action - the suspend action.

setSuspendEvent

public void setSuspendEvent(java.lang.String label)
Sets the suspending event label for this component to the given string.

Parameters:
label - the suspending event label.

setSuspendEvents

public void setSuspendEvents(java.util.Collection evts)
Sets the suspending event labels for this component to the given collection of strings.

Parameters:
evts - the suspending event labels.

setSuspendEvents

public void setSuspendEvents(java.lang.String[] labels)
Sets the suspending event labels for this component to the given array of strings.

Parameters:
labels - the suspending event labels.

start

public void start(java.beans.PropertyChangeEvent incoming)
Description copied from interface: Startable
Starts this startable component.

Specified by:
start in interface Startable
Overrides:
start in class SingleChildCombinator
Parameters:
incoming - the event that triggered the invocation of this method. May be null.

suspendChild

protected void suspendChild(java.beans.PropertyChangeEvent incoming)
Suspends the child component.

Parameters:
incoming - the suspending event.

Trull

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