Package org.jcsp.net2
Class One2NetChannel<T>
- java.lang.Object
-
- org.jcsp.net2.One2NetChannel<T>
-
- All Implemented Interfaces:
ChannelOutput<T>,Poisonable,NetChannelOutput<T>,Networked
final class One2NetChannel<T> extends java.lang.Object implements NetChannelOutput<T>
An outputting end of a networked channel (TX). This is a concrete implementation created internally by JCSP. For information on how to use networked channels, and how to create them, see the relevant documentation.- See Also:
NetChannelOutput,NetChannel
-
-
Field Summary
Fields Modifier and Type Field Description private ChannelDatadataA structure containing the information on the state of the channel.private booleanisLocalFlag to determine if this is a locally connected channel or notprivate LinklinkConnectedToThe actual Link this output channel sends on.private ChannelDatalocalChannelThis is used if we are ever connected locally.private NetChannelLocationlocalLocationThe local channel end locationprivate NetworkMessageFilter.FilterTxmessageFilterThe filter used to encode outgoing messagesprivate NetChannelLocationremoteLocationThe location that this channel is connected to (the input channel ends location)private AltingChannelInputtheAckChannelThe channel used to receive acknowledgements from the input end via the Link.private ChannelOutputtoLinkTxThe channel connecting to the Link that connects to the networked input end of this channel.
-
Constructor Summary
Constructors Modifier Constructor Description privateOne2NetChannel(AltingChannelInput ackChannel, ChannelOutput toLink, Link link, ChannelData chanData, NetChannelLocation loc, int immunity, NetworkMessageFilter.FilterTx filter)Private constructor for creating a One2NetChannel.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidasyncWrite(T object)Asynchronously writes an object to the channel(package private) static <T2> One2NetChannel<T2>create(NetChannelLocation loc, int immunity, NetworkMessageFilter.FilterTx filter)Creates a new One2NetChannel by connecting to an already created NetChannelInputvoiddestroy()Destroys the channel and removes it from the ChannelManager.(package private) ChannelDatagetChannelData()Gets the channel data state for this channel.NetLocationgetLocation()Gets the NetChannelLocation that this channel is connected to (i.e.(package private) NetChannelLocationlocalLocation()Gets the local NetChannelLocation that represents this channel.voidpoison(int strength)Poisons the underlying channel.voidsetEncoder(NetworkMessageFilter.FilterTx encoder)Sets the underlying message filtervoidwrite(T object)Writes an object to the input end
-
-
-
Field Detail
-
toLinkTx
private final ChannelOutput toLinkTx
The channel connecting to the Link that connects to the networked input end of this channel.
-
linkConnectedTo
private final Link linkConnectedTo
The actual Link this output channel sends on. We keep this as it allows us to register and unregister with the Link as we are created and destroyed, allowing the Link to inform the channel when a Link goes down.
-
localChannel
private final ChannelData localChannel
This is used if we are ever connected locally. We use this to check the state of a locally connected channel prior to sending a message.
-
theAckChannel
private final AltingChannelInput theAckChannel
The channel used to receive acknowledgements from the input end via the Link.
-
data
private final ChannelData data
A structure containing the information on the state of the channel.
-
remoteLocation
private final NetChannelLocation remoteLocation
The location that this channel is connected to (the input channel ends location)
-
localLocation
private final NetChannelLocation localLocation
The local channel end location
-
isLocal
private final boolean isLocal
Flag to determine if this is a locally connected channel or not
-
messageFilter
private NetworkMessageFilter.FilterTx messageFilter
The filter used to encode outgoing messages
-
-
Constructor Detail
-
One2NetChannel
private One2NetChannel(AltingChannelInput ackChannel, ChannelOutput toLink, Link link, ChannelData chanData, NetChannelLocation loc, int immunity, NetworkMessageFilter.FilterTx filter)
Private constructor for creating a One2NetChannel. This is called by the create method.- Parameters:
ackChannel- The channel used to receive acknowledgements from LinkstoLink- The channel used to send messages to the input endlink- The Link that this channel is connected tochanData- The structure used to store the state of the channelloc- The location of the input end that this channel is connected toimmunity- The poison immunity level of the channelfilter- Filter used to encode outgoing messages
-
-
Method Detail
-
create
static <T2> One2NetChannel<T2> create(NetChannelLocation loc, int immunity, NetworkMessageFilter.FilterTx filter) throws JCSPNetworkException
Creates a new One2NetChannel by connecting to an already created NetChannelInput- Parameters:
loc- The location of the NetChannelInputimmunity- The immunity level of the channelfilter- The filter used to encode outgoing messages- Returns:
- A new One2NetChannel
- Throws:
JCSPNetworkException- Thrown if the connection to the remote Node fails
-
poison
public void poison(int strength)
Poisons the underlying channel.- Specified by:
poisonin interfacePoisonable- Parameters:
strength- The strength of the poison being placed on the channel
-
getLocation
public NetLocation getLocation()
Gets the NetChannelLocation that this channel is connected to (i.e. the input end location)- Specified by:
getLocationin interfaceNetworked- Returns:
- The NetChannelLocation that this channel is connected to
-
localLocation
NetChannelLocation localLocation()
Gets the local NetChannelLocation that represents this channel.- Returns:
- The local location of the output end
-
write
public void write(T object) throws JCSPNetworkException, PoisonException
Writes an object to the input end- Specified by:
writein interfaceChannelOutput<T>- Parameters:
object- The object to send to the input end.- Throws:
JCSPNetworkException- Thrown if something goes wrong in the network architecturePoisonException- Thrown if the channel has been poisoned
-
asyncWrite
public void asyncWrite(T object) throws JCSPNetworkException, PoisonException
Asynchronously writes an object to the channel- Specified by:
asyncWritein interfaceNetChannelOutput<T>- Parameters:
object- The object being written to the channel- Throws:
JCSPNetworkException- Thrown when something goes wrong in the network architecturePoisonException- Thrown if the channel is poisoned
-
getChannelData
final ChannelData getChannelData()
Gets the channel data state for this channel.- Returns:
- ChannelData for this channel
-
destroy
public void destroy()
Destroys the channel and removes it from the ChannelManager.
-
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
-
-