Package org.jcsp.net2
Class Net2AnyChannel<T>
java.lang.Object
org.jcsp.net2.Net2AnyChannel<T>
- All Implemented Interfaces:
ChannelInput<T>
,Poisonable
,SharedChannelInput<T>
,NetChannelInput<T>
,NetSharedChannelInput<T>
,Networked
This class is a concrete implementation of a NetSharedChannelInput, and acts as a wrapper to a Net2OneChannel,
allowing safe shared access. This class is internal to the JCSP architecture. To create an instance of this class,
use the NetChannel factory, or the CNS.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Net2OneChannel
The underlying Net2OneChannel that this object wraps aroundprivate final Mutex
A mutual exclusion lock, allowing only one process access to perform a read operation at a time -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivate
Net2AnyChannel
(Net2OneChannel chan) Constructor for Net2AnyChannel -
Method Summary
Modifier and TypeMethodDescription(package private) static <T2> Net2AnyChannel<T2>
create
(int index, int poisonImmunity, NetworkMessageFilter.FilterRx filter) Static factory method for creating a new instance of Net2AnyChannel, given a particular index(package private) static <T2> Net2AnyChannel<T2>
create
(int poisonImmunity, NetworkMessageFilter.FilterRx filter) A static factory method to create a new Net2AnyChannel objectvoid
destroy()
Destroys the channelvoid
endRead()
Ends an extended read operationGets the channel location of this channelvoid
poison
(int strength) Poisons the underlying channelread()
Reads the next message from the channelvoid
setDecoder
(NetworkMessageFilter.FilterRx decoder) Sets the underlying message filterBegins an extended read operation on the channel
-
Field Details
-
actualChannel
The underlying Net2OneChannel that this object wraps around -
mutex
A mutual exclusion lock, allowing only one process access to perform a read operation at a time
-
-
Constructor Details
-
Net2AnyChannel
Constructor for Net2AnyChannel- Parameters:
chan
- The underlying channel that this object will wrap around
-
-
Method Details
-
create
static <T2> Net2AnyChannel<T2> create(int poisonImmunity, NetworkMessageFilter.FilterRx filter) throws JCSPNetworkException A static factory method to create a new Net2AnyChannel object- Parameters:
poisonImmunity
- The immunity level of the channelfilter
- The filter used to convert an incoming byte array into an object- Returns:
- A new Net2AnyChannel
- Throws:
JCSPNetworkException
- Thrown if there is a problem creating the underlying channel
-
create
static <T2> Net2AnyChannel<T2> create(int index, int poisonImmunity, NetworkMessageFilter.FilterRx filter) throws IllegalArgumentException, JCSPNetworkException Static factory method for creating a new instance of Net2AnyChannel, given a particular index- Parameters:
index
- The index to create the channel withpoisonImmunity
- the immunity level of the channelsfilter
- The filter used to convert the byte array back into an object- Returns:
- A new Net2AnyChannel
- Throws:
IllegalArgumentException
- Thrown if a channel with the given index already existsJCSPNetworkException
- Thrown if something goes wrong during the creation of the underlying channel
-
endRead
Ends an extended read operation- Specified by:
endRead
in interfaceChannelInput<T>
- Throws:
IllegalStateException
- Thrown if the channel is not in an extended read stateJCSPNetworkException
- Thrown if something goes wrong in the underlying network architectureNetworkPoisonException
- Thrown if the underlying channel has been poisoned
-
read
Reads the next message from the channel- Specified by:
read
in interfaceChannelInput<T>
- Returns:
- Message read from the channel
- Throws:
JCSPNetworkException
- Thrown if something goes wrong in the underlying architectureIllegalStateException
- Thrown if the channel is in an extended read stateNetworkPoisonException
- Thrown if the channel has been poisoned
-
startRead
Begins an extended read operation on the channel- Specified by:
startRead
in interfaceChannelInput<T>
- Returns:
- The message read from the channel
- Throws:
JCSPNetworkException
- Thrown if something goes wrong in the underlying architectureNetworkPoisonException
- Thrown if the channel has been poisonedIllegalStateException
- Thrown if the channel is in an extended read state
-
poison
public void poison(int strength) Poisons the underlying channel- Specified by:
poison
in interfacePoisonable
- Parameters:
strength
- The strength of the poison
-
getLocation
Gets the channel location of this channel- Specified by:
getLocation
in interfaceNetworked
- Returns:
- Location of this channel
-
destroy
public void destroy()Destroys the channel -
setDecoder
Sets the underlying message filter- Specified by:
setDecoder
in interfaceNetChannelInput<T>
- Parameters:
decoder
- The new message filter to use
-