Package org.jcsp.net2
Class Any2NetChannel<T>
- java.lang.Object
-
- org.jcsp.net2.Any2NetChannel<T>
-
- All Implemented Interfaces:
ChannelOutput<T>,Poisonable,SharedChannelOutput<T>,NetChannelOutput<T>,NetSharedChannelOutput<T>,Networked
final class Any2NetChannel<T> extends java.lang.Object implements NetSharedChannelOutput<T>
An outputting network channel (TX) that can be safely shared amongst multiple writers (Any2Net). This is the concrete implementation of the construct. For information on the user level interface, see NetSharedChannelOutput- See Also:
NetSharedChannelOutput
-
-
Field Summary
Fields Modifier and Type Field Description private One2NetChannelchanThe underlying One2NetChannel used by this channel.
-
Constructor Summary
Constructors Modifier Constructor Description privateAny2NetChannel(One2NetChannel channel)Constructor wrapping an existing One2NetChannel in an Any2NetChannel
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidasyncWrite(T object)Writes asynchronously to the underlying channel.(package private) static <T2> Any2NetChannel<T2>create(NetChannelLocation loc, int immunity, NetworkMessageFilter.FilterTx filter)Static factory method used to create an Any2NetChannelvoiddestroy()Removes the channel from the ChannelManager, and sets the state to DESTROYEDNetLocationgetLocation()Gets the NetChannelLocation of the input end this channel is connected to.voidpoison(int strength)Poisons the underlying channelvoidsetEncoder(NetworkMessageFilter.FilterTx encoder)Sets the underlying message filtervoidwrite(T object)Writes an object to the underlying channel.
-
-
-
Field Detail
-
chan
private final One2NetChannel chan
The underlying One2NetChannel used by this channel. This class acts like a wrapper, protecting the underlying unshared connection.
-
-
Constructor Detail
-
Any2NetChannel
private Any2NetChannel(One2NetChannel channel)
Constructor wrapping an existing One2NetChannel in an Any2NetChannel- Parameters:
channel- The One2NetChannel to be wrapped.
-
-
Method Detail
-
create
static <T2> Any2NetChannel<T2> create(NetChannelLocation loc, int immunity, NetworkMessageFilter.FilterTx filter) throws JCSPNetworkException
Static factory method used to create an Any2NetChannel- Parameters:
loc- The location of the input channel endimmunity- The immunity level of the channelfilter- The filter used to convert the object being sent into bytes- Returns:
- A new Any2NetChannel connected to the input end.
- Throws:
JCSPNetworkException- Thrown if a connection to the Node cannot be made.
-
poison
public void poison(int strength)
Poisons the underlying channel- Specified by:
poisonin interfacePoisonable- Parameters:
strength- The strength of the poison being put on the channel
-
getLocation
public NetLocation getLocation()
Gets the NetChannelLocation of the input end this channel is connected to.- Specified by:
getLocationin interfaceNetworked- Returns:
- The location of the input end that this output end is connected to.
-
write
public void write(T object) throws JCSPNetworkException, PoisonException
Writes an object to the underlying channel.- Specified by:
writein interfaceChannelOutput<T>- Parameters:
object- The Object to write to the channel- Throws:
JCSPNetworkException- Thrown if something happens in the underlying architecturePoisonException- Thrown if the channel has been poisoned.
-
asyncWrite
public void asyncWrite(T object) throws JCSPNetworkException, PoisonException
Writes asynchronously to the underlying channel.- Specified by:
asyncWritein interfaceNetChannelOutput<T>- Parameters:
object- The object to write to the channel- Throws:
JCSPNetworkException- Thrown if something happens in the underlying architecturePoisonException- Thrown is the channel has been poisoned
-
destroy
public void destroy()
Removes the channel from the ChannelManager, and sets the state to DESTROYED
-
setEncoder
public void setEncoder(NetworkMessageFilter.FilterTx encoder)
Sets the underlying message filter- Specified by:
setEncoderin interfaceNetChannelOutput<T>- Parameters:
encoder- The new message filter to use
-
-