Package network
Class NetworkService
java.lang.Object
network.NetworkService
- All Implemented Interfaces:
INetwork
public class NetworkService extends Object implements INetwork
-
Field Summary
Fields Modifier and Type Field Description static io.netty.util.AttributeKey<Boolean>TRANSIENT_KEY -
Constructor Summary
Constructors Constructor Description NetworkService(Properties props) -
Method Summary
Modifier and Type Method Description voidaddPeer(Host peer)Adds a new peer connection to the network layer.voidbroadcastMessage(short msgCode, Object payload, Iterator<Host> targets)Send a message to multiple peersvoidforceRemovePeer(Host peerHost)Removes the peer from the network layer, which closes any open connections.booleanisConnectionActive(Host peerHost)Checks if the is an open connection to a peerHostmyHost()Get information about the local nodevoidregisterConsumer(short msgCode, IMessageConsumer consumer)Registers a new consumer to handle messages with a specific codevoidregisterNodeListener(INodeListener listener)Registers the listener to receive updates when peer state changesvoidregisterSerializer(short msgCode, ISerializer serializer)Registers the (de)serializer to be used when sending or receiving messages with a specific codevoidremovePeer(Host peerHost)Removes the peer from the network layer, waiting until any pending messages are sent (or the connection attempt fails) before closing.voidsendMessage(short msgCode, Object payload, Host to)Sends a message to a peervoidsendMessage(short msgCode, Object payload, Host to, boolean newChannel)Sends a message to a peer, possibly using a dedicated channel
-
Field Details
-
Constructor Details
-
NetworkService
- Throws:
Exception
-
-
Method Details
-
myHost
Description copied from interface:INetworkGet information about the local node -
registerNodeListener
Description copied from interface:INetworkRegisters the listener to receive updates when peer state changes- Specified by:
registerNodeListenerin interfaceINetwork- Parameters:
listener- The listener to register.
-
registerConsumer
Description copied from interface:INetworkRegisters a new consumer to handle messages with a specific code- Specified by:
registerConsumerin interfaceINetwork- Parameters:
msgCode- The message to registerconsumer- The consumer to handle messages with the given code
-
registerSerializer
Description copied from interface:INetworkRegisters the (de)serializer to be used when sending or receiving messages with a specific code- Specified by:
registerSerializerin interfaceINetwork- Parameters:
msgCode- The message code to registerserializer- The object used to (de)serialize messages with the given code
-
addPeer
Description copied from interface:INetworkAdds a new peer connection to the network layer. This method immediately attempts to connect to the peer. This method needs to be called before attempting to send messages to the peer. -
removePeer
Description copied from interface:INetworkRemoves the peer from the network layer, waiting until any pending messages are sent (or the connection attempt fails) before closing.- Specified by:
removePeerin interfaceINetwork- Parameters:
peerHost- The peer to remove from the network layer
-
forceRemovePeer
Description copied from interface:INetworkRemoves the peer from the network layer, which closes any open connections.- Specified by:
forceRemovePeerin interfaceINetwork- Parameters:
peerHost- The peer to remove from the network layer
-
isConnectionActive
Description copied from interface:INetworkChecks if the is an open connection to a peer- Specified by:
isConnectionActivein interfaceINetwork- Parameters:
peerHost- The peer- Returns:
- Whether there is an open connection to the peer.
-
sendMessage
Description copied from interface:INetworkSends a message to a peer, possibly using a dedicated channel- Specified by:
sendMessagein interfaceINetwork- Parameters:
msgCode- The code of the message to sendpayload- The message to sendto- The peer to send the message tonewChannel- Whether to create a dedicated channel to send the message or not
-
sendMessage
Description copied from interface:INetworkSends a message to a peer- Specified by:
sendMessagein interfaceINetwork- Parameters:
msgCode- The code of the message to sendpayload- The message to sendto- The peer to send the message to
-
broadcastMessage
Description copied from interface:INetworkSend a message to multiple peers- Specified by:
broadcastMessagein interfaceINetwork- Parameters:
msgCode- The code of the message to sendpayload- The message to sendtargets- The list of peers to send the message to
-