|
CSP for Java (JCSP) 1.0-rc4 |
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
This defines the interface for reading from object channels.
ChannelInput 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.
void doRead (ChannelInput c) { c.read (); // clear the channel }
void doRead (ChannelInput c) { Boolean b = (Boolean) c.read(); // will cause a ClassCastException // if read does not return a Boolean ... etc. }
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); } }
AltingChannelInput
,
ChannelOutput
Method Summary | |
Object |
read()
Read an Object from the channel. |
Method Detail |
public Object read()
|
CSP for Java (JCSP) 1.0-rc4 |
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |