ptolemy.domains.ct.kernel
Class CTReceiver

java.lang.Object
  extended by ptolemy.actor.AbstractReceiver
      extended by ptolemy.actor.Mailbox
          extended by ptolemy.domains.ct.kernel.CTReceiver
All Implemented Interfaces:
Receiver

public class CTReceiver
extends Mailbox

The receiver for the continuous-time and mixed-signal domain. The receiver can be of one of the two types: CONTINUOUS and DISCRETE. Conceptually, a CONTINUOUS CTReceiver contains a sample of a continuous signal at a particular time (defined by the CTDirector). Thus, there is one and only one token at all time in a CONTINUOUS CTReceiver. A DISCRETE CTReceiver contains a discrete event. Thus a DISCRETE CTReceiver may be empty if an event is not present.

The receiver is implemented as a Mailbox of capacity one. Any token put in the receiver overwrites any token previously present in the receiver. As a consequence, hasRoom() method always returns true.

The behavior of the get() method depends on the type of the receiver. If it is CONTINUOUS, then get() only reads the value. Consecutive calls on the get method will return the same token if the put method has not been called. For a CONTINUOUS CTReceiver, hasToken() will always return true after the first put() has been called. For a DISCRETE CTReceiver, get() will return and destroy the token, thus the token can only be retrived once. Therefore after the consumption, the hasToken() method will return false, until a token is put into this receiver.

Since:
Ptolemy II 0.2
Version:
$Id: CTReceiver.java 57040 2010-01-27 20:52:32Z cxh $
Author:
Jie Liu
Accepted Rating:
Green (yuhong)
Proposed Rating:
Green (liuj)

Nested Class Summary
static class CTReceiver.SignalType
          Inner class used for the static enumeration of indicators of signal types.
 
Field Summary
private  CTReceiver.SignalType _type
           
static CTReceiver.SignalType CONTINUOUS
          Signal type: CONTINUOUS.
static CTReceiver.SignalType DISCRETE
          Signal type: DISCRETE.
static CTReceiver.SignalType UNKNOWN
          Signal type: UNKNOWN.
 
Fields inherited from class ptolemy.actor.Mailbox
_token
 
Constructor Summary
CTReceiver()
          Construct an empty CTReceiver with no container.
CTReceiver(IOPort container)
          Construct an empty CTReceiver with the specified container.
 
Method Summary
 Token get()
          Return the contained token if it is not null.
 CTReceiver.SignalType getSignalType()
          Return the signal type of this receiver.
 boolean hasRoom()
          Return true, since the new token will overwrite the old one.
 void put(Token token)
          Put a token into this receiver.
 void reset()
          Reset this receiver so that it contains a zero-valued token of the same type as whatever token is currently in the receiver, if there is one.
 void setSignalType(CTReceiver.SignalType type)
          Set the signal type of this receiver.
 
Methods inherited from class ptolemy.actor.Mailbox
clear, elementList, hasRoom, hasToken, hasToken
 
Methods inherited from class ptolemy.actor.AbstractReceiver
getArray, getContainer, getCurrentTime, getModelTime, isKnown, putArray, putArrayToAll, putToAll, setContainer, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

CONTINUOUS

public static final CTReceiver.SignalType CONTINUOUS
Signal type: CONTINUOUS.


DISCRETE

public static final CTReceiver.SignalType DISCRETE
Signal type: DISCRETE.


UNKNOWN

public static final CTReceiver.SignalType UNKNOWN
Signal type: UNKNOWN.


_type

private CTReceiver.SignalType _type
Constructor Detail

CTReceiver

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


CTReceiver

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

Parameters:
container - The port that contains the receiver.
Throws:
IllegalActionException - If this receiver cannot be contained by the proposed container.
Method Detail

get

public Token get()
          throws NoTokenException
Return the contained token if it is not null. If the receiver is CONTINUOUS, then the token is still available for the next get, i.e. the token is not set to null. If the receiver is DISCRETE, then the token is removed from the receiver, and the receiver contains null, which means that is another get() is called before a calling of put, then an exception will be thrown. If the receiver contains null, then thrown a NoTokenException.

Specified by:
get in interface Receiver
Overrides:
get in class Mailbox
Returns:
The token contained by this mailbox.
Throws:
NoTokenException - If the receiver contains null.
InvalidStateException - If this method is called and the signal type of this receiver is UNKNOWN.

getSignalType

public CTReceiver.SignalType getSignalType()
Return the signal type of this receiver.

Returns:
The signal type of the receiver.
See Also:
setSignalType(ptolemy.domains.ct.kernel.CTReceiver.SignalType)

hasRoom

public boolean hasRoom()
Return true, since the new token will overwrite the old one.

Specified by:
hasRoom in interface Receiver
Overrides:
hasRoom in class Mailbox
Returns:
True.

put

public void put(Token token)
         throws NoRoomException
Put a token into this receiver. If the argument is null, then this receiver will not contain any token after this method returns. If the receiver already has a token, then the new token will overwrite the old token, and the old token will be lost.

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

reset

public void reset()
           throws IllegalActionException
Reset this receiver so that it contains a zero-valued token of the same type as whatever token is currently in the receiver, if there is one.

Specified by:
reset in interface Receiver
Overrides:
reset in class AbstractReceiver
Throws:
IllegalActionException - If reset() is not supported by the domain.

setSignalType

public void setSignalType(CTReceiver.SignalType type)
Set the signal type of this receiver. This method must be called by the CTScheduler before any get() method are called.

Parameters:
type - The SignalType to set to the receiver.
See Also:
getSignalType()