Package network
Interface INetwork
- All Known Implementing Classes:
NetworkService
public interface INetwork
Represents the network layer.
- Author:
- pfouto
-
Method Summary
Modifier and Type Method Description voidaddPeer(Host peerHost)Adds a new peer connection to the network layer.voidbroadcastMessage(short msgCode, Object msg, 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 messageCode, 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 messageCode, 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 msg, 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
-
Method Details
-
myHost
Host myHost()Get information about the local node- Returns:
- An object with the IP and port of the local node
-
addPeer
Adds 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.- Parameters:
peerHost- The peer to create a connection to.
-
removePeer
Removes the peer from the network layer, waiting until any pending messages are sent (or the connection attempt fails) before closing.- Parameters:
peerHost- The peer to remove from the network layer
-
forceRemovePeer
Removes the peer from the network layer, which closes any open connections.- Parameters:
peerHost- The peer to remove from the network layer
-
isConnectionActive
Checks if the is an open connection to a peer- Parameters:
peerHost- The peer- Returns:
- Whether there is an open connection to the peer.
-
sendMessage
Sends a message to a peer, possibly using a dedicated channel- 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
Sends a message to a peer- Parameters:
msgCode- The code of the message to sendmsg- The message to sendto- The peer to send the message to
-
broadcastMessage
Send a message to multiple peers- Parameters:
msgCode- The code of the message to sendmsg- The message to sendtargets- The list of peers to send the message to
-
registerConsumer
Registers a new consumer to handle messages with a specific code- Parameters:
messageCode- The message to registerconsumer- The consumer to handle messages with the given code
-
registerSerializer
Registers the (de)serializer to be used when sending or receiving messages with a specific code- Parameters:
messageCode- The message code to registerserializer- The object used to (de)serialize messages with the given code
-
registerNodeListener
Registers the listener to receive updates when peer state changes- Parameters:
listener- The listener to register.
-