Package org.jcsp.net2
Class Net2OneChannel<T>
- java.lang.Object
-
- org.jcsp.lang.Guard
-
- org.jcsp.lang.AltingChannelInput<T>
-
- org.jcsp.lang.AltingChannelInputWrapper<T>
-
- org.jcsp.net2.NetAltingChannelInput<T>
-
- org.jcsp.net2.Net2OneChannel<T>
-
- All Implemented Interfaces:
ChannelInput<T>
,Poisonable
,NetChannelInput<T>
,Networked
final class Net2OneChannel<T> extends NetAltingChannelInput<T>
A concrete implementation of a NetAltingChannelInput. This is a hidden class created by the architecture. To create an instance of this object, use the NetChannel factory, or the CNS.- See Also:
NetChannelInput
,NetAltingChannelInput
,NetChannel
-
-
Field Summary
Fields Modifier and Type Field Description private ChannelData
data
The ChannelData structure representing this channel.private AltingChannelInput
in
The input channel coming into the networked channel input object from Links or locally connected net channel outputs.private NetworkMessage
lastRead
The lastRead ChannelMessage.private NetChannelLocation
location
The location of this channelprivate NetworkMessageFilter.FilterRx
messageFilter
The filter used to convert the incoming byte array into an object
-
Constructor Summary
Constructors Modifier Constructor Description private
Net2OneChannel(AltingChannelInput input, ChannelData chanData, NetworkMessageFilter.FilterRx filter)
Private constructor for creating a new instance of a Net2OneChannel.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) static <T2> Net2OneChannel<T2>
create(int index, int poisonImmunity, NetworkMessageFilter.FilterRx filter)
Static factory method used to create a new Net2OneChannel with a given index.(package private) static <T2> Net2OneChannel<T2>
create(int poisonImmunity, NetworkMessageFilter.FilterRx filter)
Static factory method used to create a new Net2OneChannel.void
destroy()
Destroys the underlying channelvoid
endRead()
Ends an extended read operation.(package private) ChannelData
getChannelData()
Gets the channel data object for this channel.NetLocation
getLocation()
Returns the NetChannelLocation of the channelboolean
pending()
Checks if any data is waiting on the channel.void
poison(int strength)
Poisons the underlying channelT
read()
Reads the next message from the channelvoid
setDecoder(NetworkMessageFilter.FilterRx decoder)
Sets the underlying message filterT
startRead()
Performs an extended read operation on the channel-
Methods inherited from class org.jcsp.lang.AltingChannelInputWrapper
getChannel, setChannel
-
-
-
-
Field Detail
-
in
private final AltingChannelInput in
The input channel coming into the networked channel input object from Links or locally connected net channel outputs.
-
data
private final ChannelData data
The ChannelData structure representing this channel.
-
lastRead
private NetworkMessage lastRead
The lastRead ChannelMessage. Used during an extended read operation to allow the ACK message to be sent to the correct Node.
-
messageFilter
private NetworkMessageFilter.FilterRx messageFilter
The filter used to convert the incoming byte array into an object
-
location
private final NetChannelLocation location
The location of this channel
-
-
Constructor Detail
-
Net2OneChannel
private Net2OneChannel(AltingChannelInput input, ChannelData chanData, NetworkMessageFilter.FilterRx filter) throws JCSPNetworkException
Private constructor for creating a new instance of a Net2OneChannel. This is called by the create method to create the channel.- Parameters:
input
- The input channel connecting to the networked channel.chanData
- The ChannelData object representing the networked channel.filter
- The filter used to convert the incoming byte array to an object- Throws:
JCSPNetworkException
-
-
Method Detail
-
create
static <T2> Net2OneChannel<T2> create(int poisonImmunity, NetworkMessageFilter.FilterRx filter)
Static factory method used to create a new Net2OneChannel. Used internally within the architecture.- Parameters:
poisonImmunity
- The immunity level of the channelfilter
- The filter on the channel used to convert read bytes into an object- Returns:
- A new Net2OneChannel
-
create
static <T2> Net2OneChannel<T2> create(int index, int poisonImmunity, NetworkMessageFilter.FilterRx filter) throws java.lang.IllegalArgumentException
Static factory method used to create a new Net2OneChannel with a given index. Used internally within the architecture- Parameters:
index
- The index to create the channel withpoisonImmunity
- The immunity level of the channelfilter
- The filter used to take the incoming byte array and convert it into an object- Returns:
- A new Net2OneChannel
- Throws:
java.lang.IllegalArgumentException
- Thrown if the index given is already allocated within the ChannelManager
-
endRead
public void endRead() throws java.lang.IllegalStateException, JCSPNetworkException, NetworkPoisonException
Ends an extended read operation.- Specified by:
endRead
in interfaceChannelInput<T>
- Overrides:
endRead
in classAltingChannelInputWrapper<T>
- Throws:
java.lang.IllegalStateException
- Thrown if the method is called when the channel is not in an extended read stateJCSPNetworkException
- Thrown if something goes wrong in the underlying architectureNetworkPoisonException
- Thrown if the channel has been poisoned- See Also:
ChannelInput.endRead
-
pending
public boolean pending() throws JCSPNetworkException, NetworkPoisonException
Checks if any data is waiting on the channel.- Overrides:
pending
in classAltingChannelInputWrapper<T>
- Returns:
- True if data is ready, false otherwise.
- Throws:
JCSPNetworkException
- Thrown if the channel has been destroyedNetworkPoisonException
- Thrown if the channel has poisoned
-
poison
public void poison(int strength)
Poisons the underlying channel- Specified by:
poison
in interfacePoisonable
- Overrides:
poison
in classAltingChannelInputWrapper<T>
- Parameters:
strength
- The strength of the poison
-
read
public T read() throws JCSPNetworkException, NetworkPoisonException, java.lang.IllegalStateException
Reads the next message from the channel- Specified by:
read
in interfaceChannelInput<T>
- Overrides:
read
in classAltingChannelInputWrapper<T>
- Returns:
- The message read from the channel
- Throws:
JCSPNetworkException
- Thrown if something goes wrong in the underlying architectureNetworkPoisonException
- Thrown if the channel is poisonedjava.lang.IllegalStateException
- Thrown if the channel is in an extended read state
-
startRead
public T startRead() throws JCSPNetworkException, java.lang.IllegalStateException, NetworkPoisonException
Performs an extended read operation on the channel- Specified by:
startRead
in interfaceChannelInput<T>
- Overrides:
startRead
in classAltingChannelInputWrapper<T>
- Returns:
- The message read from the channel
- Throws:
JCSPNetworkException
- Thrown if something goes wrong in the underlying architecturejava.lang.IllegalStateException
- Thrown if the channel is already in an extended read stateNetworkPoisonException
- Thrown if the channel is poisoned.- See Also:
ChannelInput.startRead
-
getLocation
public NetLocation getLocation()
Returns the NetChannelLocation of the channel- Returns:
- Location of this channel
-
destroy
public void destroy()
Destroys the underlying channel
-
getChannelData
final ChannelData getChannelData()
Gets the channel data object for this channel.- Returns:
- The ChannelData for this Channel
-
setDecoder
public void setDecoder(NetworkMessageFilter.FilterRx decoder)
Sets the underlying message filter- Parameters:
decoder
- The message filter to use
-
-