Interface ChannelInput<T>
-
- All Superinterfaces:
Poisonable
- All Known Subinterfaces:
FilteredChannelInput,FilteredSharedChannelInput,MigratableChannelInput,NetChannelInput,NetChannelInput<T>,NetSharedChannelInput,NetSharedChannelInput<T>,RejectableChannelInput,SharedChannelInput<T>
- All Known Implementing Classes:
AltingChannelInput,AltingChannelInputImpl,AltingChannelInputSymmetricImpl,AltingChannelInputWrapper,ChannelInputImpl,ChannelInputWrapper,FilteredAltingChannelInput,FilteredChannelInputWrapper,FilteredSharedChannelInputWrapper,MigratableAltingChannelInput,MigratableAltingChannelInputImpl,MobileChannelInput,Net2AnyChannel,Net2AnyChannel,Net2OneChannel,Net2OneChannel,NetAltingChannelInput,NetAltingChannelInput,RejectableAltingChannelInput,RejectableAltingChannelInputImpl,RejectableChannelInputImpl,SharedChannelInputImpl
public interface ChannelInput<T> extends Poisonable
This defines the interface for reading from an Object channel.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:,readandstartRead. TheendReadandreadmethods 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.startReadWhen a
completes, the matchingreadmethod (invoked by the writing process) also completes. When awritecompletes, the matchingstartReadmethod does not complete until the reader process invokes anwrite. Actions performed by the reader in between aendReadandstartReadmake up an extended rendezvous.endReadChannelInput variables are used to hold channels that are going to be used only for input by the declaring process. This is a security matter -- by declaring a ChannelInput 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 (ChannelInput c, Object o) { c.write (o); // illegal }When configuring a CSProcess with input channels, they should be declared as ChannelInput (or, if we wish to be able to make choices between events, as AltingChannelInput) variables. The actual channel passed, of course, may belong to any channel class that implements ChannelInput (or AltingChannelInput).The Object returned can be cast into the actual class the reader process expects. If the reader can handle more than one class of Object (similar to tagged protocols in occam), checks should be made before casting.
Examples
Discard data
void doRead (ChannelInput c) { c.read (); // clear the channel }Cast data to expected type
void doRead (ChannelInput c) { Boolean b = (Boolean) c.read(); // will cause a ClassCastException // if read does not return a Boolean ... etc. }Cast data after checking type
void doRead (ChannelInput c) { Object o = c.read (); if (o instanceof Boolean) { System.out.println ("Boolean: " + (Boolean) o); } else if (o instanceof Integer) { System.out.println ("Integer: " + (Integer) o); } else { System.out.println ("Unexpected Class: " + o); } }- See Also:
AltingChannelInput,SharedChannelInput,ChannelOutput
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description voidendRead()End an extended rendezvous.Tread()Read an Object from the channel.TstartRead()Begin an extended rendezvous read from the channel.-
Methods inherited from interface org.jcsp.lang.Poisonable
poison
-
-
-
-
Method Detail
-
read
T read()
Read an Object from the channel.- Returns:
- the object read from the channel
-
startRead
T 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 itsendReadmethod). The writer is unaware of the extended nature of the communication.writeThe reader process must call
at some point after this function, otherwise the writer will not be freed and deadlock will probably follow.endReadThe 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.endReadAn 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
-
-