Interface ChannelInputInt
- All Superinterfaces:
Poisonable
- All Known Subinterfaces:
SharedChannelInputInt
- All Known Implementing Classes:
AltingChannelInputInt
,AltingChannelInputIntImpl
,AltingChannelInputIntSymmetricImpl
,ChannelInputIntImpl
,SharedChannelInputIntImpl
A reading-end, conforming to this interface, is obtained from a channel by invoking its in() method.
Description
ChannelInput defines the interface for reading from object channels. The interface contains three methods:read
, startRead
and
endRead
.
The read
and startRead
methods block until an Object has been written
to the channel by a process at the other end. If an Object has
already been written when this method is called, the method will return
without blocking. Either way, the methods return the Object
sent down the channel.
When a
completes, the matching
read
method (invoked by
the writing process) also completes.
When a write
completes, the matching
startRead
method does not complete
until the reader process invokes an write
.
Actions performed by the reader in between a endRead
and startRead
make up an extended rendezvous.
endRead
ChannelInputInt variables are used to hold integer channels that are going to be used only for input by the declaring process. This is a security matter -- by declaring a ChannelInputInt interface, any attempt to output to the channel will generate a compile-time error. For example, the following code fragment will not compile:
void doWrite (ChannelInputInt c, int i) { c.write (i); // illegal }When configuring a CSProcess with input integer channels, they should be declared as ChannelInputInt (or, if we wish to be able to make choices between events, as AltingChannelInputInt) variables. The actual channel passed, of course, may belong to any channel class that implements ChannelInputInt (or AltingChannelInputInt).
Example
Discard data
void doRead (ChannelInputInt c) { c.read (); // clear the channel }
- See Also:
-
Method Summary
Methods inherited from interface org.jcsp.lang.Poisonable
poison
-
Method Details
-
read
int read()Read an int from the channel.- Returns:
- the integer read from the channel
-
startRead
int startRead()Begin an extended rendezvous read from the channel. An extended rendezvous is not completed until the reader has completed its extended action. This method starts an extended rendezvous. When a writer to this channel writes, this method returns what was sent immediately. The extended rendezvous continues with reader actions until the reader invokes
. Only then will the writer be released (from itsendRead
method). The writer is unaware of the extended nature of the communication.write
The reader process must call
at some point after this function, otherwise the writer will not be freed and deadlock will probably follow.endRead
The reader process may perform any actions between calling
andstartRead
, including communications on other channels. Further communications on this channel, of course, should not be made.endRead
An extended rendezvous may be started after the channel's Guard has been selected by an
Alternative
(i.e.
instead ofstartRead
).read
- Returns:
- The object read from the channel
-
endRead
void endRead()End an extended rendezvous. It must be invoked once (and only once) following a
.startRead
-