uk.ac.man.cs.rainbow.simulator
Class Channel

java.lang.Object
  |
  +--uk.ac.man.cs.rainbow.simulator.Channel
All Implemented Interfaces:
Serializable

public class Channel
extends Object
implements Serializable

Channels connect Rainbow threads.

See Also:
RainbowThread, Serialized Form

Inner Class Summary
 class Channel.Adapter
          Null implementation of a channel listener.
static class Channel.Data
          Channels can be turned into first-class data values.
static interface Channel.Listener
          Indicate that a class's objects might want to be told of events on channels.
 
Constructor Summary
Channel(String name)
          Create a new channel with the given name.
 
Method Summary
 void addListener(Channel.Listener l)
          Register an object for receipt of channel event notifications.
 Data getContents()
          Get the value currently on the channel.
 RainbowThread getReader()
          What thread is interested in reading from the channel?
 RainbowThread getWriter()
          What thread is trying to write to the channel?
 boolean isActivated()
          Is a transation in the process of happening on the channel?
 void removeListener(Channel.Listener l)
          Unregister an object from receipt of channel event notifications.
 void setActivated(boolean activated)
          Activate or deactivate the channel.
 void setContents(Data contents)
          Set the value that is being passed along the channel.
 void setReader(RainbowThread reader)
          Indicate that the given thread is interested in reading from the channel.
 void setWriter(RainbowThread writer)
          Indicate that the given thread has written to the channel.
 String toString()
          Get the name of this channel.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Channel

public Channel(String name)
Create a new channel with the given name. The channel will initially have the unknown data value being passed along it.
Parameters:
name - The name of the channel to create.
See Also:
UnknownData, RASM.MakeChannel
Method Detail

getContents

public Data getContents()
Get the value currently on the channel.
Returns:
The data value on the channel, or null if no data value is on the channel at the moment.

getReader

public RainbowThread getReader()
What thread is interested in reading from the channel?

getWriter

public RainbowThread getWriter()
What thread is trying to write to the channel?

isActivated

public boolean isActivated()
Is a transation in the process of happening on the channel?

setActivated

public void setActivated(boolean activated)
Activate or deactivate the channel. Will notify any listeners present what is happening to the channel
Parameters:
activated - True to activate the channel (i.e. to send a request), and false to deactivate the channel (i.e. to send an acknowledge.)

setContents

public void setContents(Data contents)
Set the value that is being passed along the channel.
Parameters:
contents - The value to pass along the channel.

setReader

public void setReader(RainbowThread reader)
Indicate that the given thread is interested in reading from the channel.
Parameters:
reader - The thread that wants to be woken up when a value is written to the channel. Use null to mark the thread as having no thread interested in write notifications.
See Also:
Scheduler

setWriter

public void setWriter(RainbowThread writer)
Indicate that the given thread has written to the channel. The thread will be notified when an acknowledgement is sent along the channel.
Parameters:
writer - The thread that wants to be woken up when the value has been finished with by the channel's reader thread. If null, then the data value being passed along the channel will be reset to the unknown value.
See Also:
Scheduler, UnknownData

toString

public String toString()
Get the name of this channel.
Overrides:
toString in class Object

addListener

public final void addListener(Channel.Listener l)
Register an object for receipt of channel event notifications.
Parameters:
l - The listener object to register.

removeListener

public final void removeListener(Channel.Listener l)
Unregister an object from receipt of channel event notifications.
Parameters:
l - The listener object to unregister.