ptolemy.domains.giotto.kernel
Class GiottoReceiver

java.lang.Object
  extended byptolemy.actor.AbstractReceiver
      extended byptolemy.domains.giotto.kernel.GiottoReceiver
All Implemented Interfaces:
Receiver

public class GiottoReceiver
extends AbstractReceiver

A receiver for the Giotto domain. It uses double-buffering. An actor may write to a receiver using put at any time. However, a new token will only be available to get if update has been called before. The update method makes the token from the last put invocation available to get. The GiottoDirector delays calls to update according to the Giotto semantics.

Since:
Ptolemy II 1.0
Version:
$Id: GiottoReceiver.java,v 1.28 2004/04/13 03:31:27 cxh Exp $
Author:
Christoph Meyer Kirsch and Edward A. Lee
See Also:
GiottoDirector
Accepted Rating:
Yellow (liuj)
Proposed Rating:
Yellow (cm)

Constructor Summary
GiottoReceiver()
          Construct an empty GiottoReceiver with no container.
GiottoReceiver(IOPort container)
          Construct an empty GiottoReceiver with the specified container.
 
Method Summary
 void clear()
          Clear this receiver of any contained tokens.
 Token get()
          Get the contained and available token, i.e., get the last token that has been put into the receiver before the last update.
 boolean hasRoom()
          Return true, since writing to this receiver is always allowed.
 boolean hasRoom(int numberOfTokens)
          Return true, since writing to this receiver is always allowed.
 boolean hasToken()
          Return true if there is a token available.
 boolean hasToken(int numberOfTokens)
          Return true if there is a token available.
 void put(Token token)
          Put a token into this receiver.
 Token remove()
          Get the contained and available token, i.e., get the last token that has been put into the receiver before the last update and reset the _token only.
 void reset()
          Reset the receiver by removing all tokens from the receiver.
 void update()
          Update the receiver by making the last token that has been passed to put() available to get().
 
Methods inherited from class ptolemy.actor.AbstractReceiver
getArray, getContainer, getCurrentTime, isKnown, putArray, setContainer
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GiottoReceiver

public GiottoReceiver()
Construct an empty GiottoReceiver with no container.


GiottoReceiver

public GiottoReceiver(IOPort container)
               throws IllegalActionException
Construct an empty GiottoReceiver with the specified container.

Parameters:
container - The container.
Throws:
IllegalActionException - If the container does not accept this receiver.
Method Detail

clear

public void clear()
Clear this receiver of any contained tokens. FIXME. Should rename and replace all the reset() with clear().

Specified by:
clear in interface Receiver
Overrides:
clear in class AbstractReceiver

get

public Token get()
          throws NoTokenException
Get the contained and available token, i.e., get the last token that has been put into the receiver before the last update.

Specified by:
get in interface Receiver
Specified by:
get in class AbstractReceiver
Returns:
A token.
Throws:
NoTokenException - If no token is available.

hasRoom

public boolean hasRoom()
Return true, since writing to this receiver is always allowed.

Specified by:
hasRoom in interface Receiver
Specified by:
hasRoom in class AbstractReceiver
Returns:
True.

hasRoom

public final boolean hasRoom(int numberOfTokens)
Return true, since writing to this receiver is always allowed.

Specified by:
hasRoom in interface Receiver
Specified by:
hasRoom in class AbstractReceiver
Parameters:
numberOfTokens - The number of tokens to put into this receiver.
Returns:
True.

hasToken

public boolean hasToken()
Return true if there is a token available. A token is available whenever put() has been called at least once followed by a call to the update() method.

Specified by:
hasToken in interface Receiver
Specified by:
hasToken in class AbstractReceiver
Returns:
True if there is a token available.

hasToken

public final boolean hasToken(int numberOfTokens)
Return true if there is a token available. Any number of calls to get() is allowed and will return the same available token.

Specified by:
hasToken in interface Receiver
Specified by:
hasToken in class AbstractReceiver
Parameters:
numberOfTokens - The number of tokens desired.
Returns:
True if there is a token available.

put

public void put(Token token)
         throws NoRoomException
Put a token into this receiver. Any token which has been put into the receiver before without calling update will be lost. The token becomes available to the get() method only after update() is called.

Note that putting a null into this receiver will leave the receiver empty after update. The receiver does not check against this but expects that IOPort will always put non-null tokens into receivers.

Specified by:
put in interface Receiver
Specified by:
put in class AbstractReceiver
Parameters:
token - The token to be put into this receiver.
Throws:
NoRoomException - Not thrown in this base class.

remove

public Token remove()
             throws NoTokenException
Get the contained and available token, i.e., get the last token that has been put into the receiver before the last update and reset the _token only.

Returns:
A token.
Throws:
NoTokenException - If no token is available.

reset

public void reset()
Reset the receiver by removing all tokens from the receiver.


update

public void update()
Update the receiver by making the last token that has been passed to put() available to get().