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
final class Net2AnyChannel<T> extends java.lang.Object implements NetSharedChannelInput<T>
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:
NetChannelInput,NetSharedChannelInput,NetChannel
-
-
Field Summary
Fields Modifier and Type Field Description private Net2OneChannelactualChannelThe underlying Net2OneChannel that this object wraps aroundprivate MutexmutexA mutual exclusion lock, allowing only one process access to perform a read operation at a time
-
Constructor Summary
Constructors Modifier Constructor Description privateNet2AnyChannel(Net2OneChannel chan)Constructor for Net2AnyChannel
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description (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 objectvoiddestroy()Destroys the channelvoidendRead()Ends an extended read operationNetLocationgetLocation()Gets the channel location of this channelvoidpoison(int strength)Poisons the underlying channelTread()Reads the next message from the channelvoidsetDecoder(NetworkMessageFilter.FilterRx decoder)Sets the underlying message filterTstartRead()Begins an extended read operation on the channel
-
-
-
Field Detail
-
actualChannel
private final Net2OneChannel actualChannel
The underlying Net2OneChannel that this object wraps around
-
mutex
private final Mutex mutex
A mutual exclusion lock, allowing only one process access to perform a read operation at a time
-
-
Constructor Detail
-
Net2AnyChannel
private Net2AnyChannel(Net2OneChannel chan)
Constructor for Net2AnyChannel- Parameters:
chan- The underlying channel that this object will wrap around
-
-
Method Detail
-
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 java.lang.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:
java.lang.IllegalArgumentException- Thrown if a channel with the given index already existsJCSPNetworkException- Thrown if something goes wrong during the creation of the underlying channel
-
endRead
public void endRead() throws java.lang.IllegalStateException, JCSPNetworkException, NetworkPoisonExceptionEnds an extended read operation- Specified by:
endReadin interfaceChannelInput<T>- Throws:
java.lang.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
public T read() throws JCSPNetworkException, java.lang.IllegalStateException, NetworkPoisonException
Reads the next message from the channel- Specified by:
readin interfaceChannelInput<T>- Returns:
- Message read from the channel
- Throws:
JCSPNetworkException- Thrown if something goes wrong in the underlying architecturejava.lang.IllegalStateException- Thrown if the channel is in an extended read stateNetworkPoisonException- Thrown if the channel has been poisoned
-
startRead
public T startRead() throws JCSPNetworkException, NetworkPoisonException, java.lang.IllegalStateException
Begins an extended read operation on the channel- Specified by:
startReadin 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 poisonedjava.lang.IllegalStateException- Thrown if the channel is in an extended read state
-
poison
public void poison(int strength)
Poisons the underlying channel- Specified by:
poisonin interfacePoisonable- Parameters:
strength- The strength of the poison
-
getLocation
public NetLocation getLocation()
Gets the channel location of this channel- Specified by:
getLocationin interfaceNetworked- Returns:
- Location of this channel
-
setDecoder
public void setDecoder(NetworkMessageFilter.FilterRx decoder)
Sets the underlying message filter- Specified by:
setDecoderin interfaceNetChannelInput<T>- Parameters:
decoder- The new message filter to use
-
-