Class Channel
Class Channel
java.lang.Object
|
+----Channel
- class Channel
- extends Object
Channel extends an occam CHAN for multiple readers and writers.
There is full synchronisation between a reading and writing thread. Any
thread may read or write on this channel. Readers and writers are queued
separately. A reader only completes when it gets to the front of its queue
and finds a writer. A writer only completes when it gets to the front of
its queue and finds a reader.
There is no logical buffering of data in the channel. The object passed
into the channel is not cloned, but rather a reference is passed to the
reader. Therefore, care must be taken that the object supplied by a writer
does not then have its content modified asynchronously by the writer. This
can be done by setting the reference to null, e.g. in a writer,
String s = "Hello World"; // create a new string
chan.write(s); // send the string
s = null; // delete writer's reference to string
or alternatively, a clone can be supplied, e.g.
StringBuffer s = "Hello World"; // create a new string
chan.write(s.clone()); // send the string
s.reverse(); // does not affect the reader's copy
- Version:
- $Revision: 1.1 $
- Author:
- Peter Welch, P.H.Welch@ukc.ac.uk, Dave Beckett, D.J.Beckett@ukc.ac.uk, with annotations by Richard Beton
Method Index
- o is_empty()
- is_empty method: determine whether a thread is waiting at the
other end of the channel.
- o read()
- read method: read a message from the channel.
- o write(Object)
- write method: write a message to the channel.
Methods
o read
public Object read() throws InterruptedException
- read method: read a message from the channel. This method
blocks until a corresponding thread calls the write method,
at which point a rendezvous is formed and the data is passed.
- Returns:
- the object sent from the writing thread.
- Throws: InterruptedException
- Occurs if the wait methods are interrupted.
o write
public void write(Object o) throws InterruptedException
- write method: write a message to the channel. This method
blocks until a corresponding thread calls the read method,
at which point a rendezvous is formed and the data is passed.
- Parameters:
- o - the object to be sent to the reading thread.
- Throws: InterruptedException
- Occurs if the wait methods are interrupted.
o is_empty
public boolean is_empty()
- is_empty method: determine whether a thread is waiting at the
other end of the channel. This can be used either at the writing or the
reading end of the channel.
- Returns:
- true iff no thread is waiting at the other end.