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
    void addPeer​(Host peerHost)
    Adds a new peer connection to the network layer.
    void broadcastMessage​(short msgCode, Object msg, Iterator<Host> targets)
    Send a message to multiple peers
    void forceRemovePeer​(Host peerHost)
    Removes the peer from the network layer, which closes any open connections.
    boolean isConnectionActive​(Host peerHost)
    Checks if the is an open connection to a peer
    Host myHost()
    Get information about the local node
    void registerConsumer​(short messageCode, IMessageConsumer consumer)
    Registers a new consumer to handle messages with a specific code
    void registerNodeListener​(INodeListener listener)
    Registers the listener to receive updates when peer state changes
    void registerSerializer​(short messageCode, ISerializer serializer)
    Registers the (de)serializer to be used when sending or receiving messages with a specific code
    void removePeer​(Host peerHost)
    Removes the peer from the network layer, waiting until any pending messages are sent (or the connection attempt fails) before closing.
    void sendMessage​(short msgCode, Object msg, Host to)
    Sends a message to a peer
    void sendMessage​(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

      void addPeer​(Host peerHost)
      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

      void removePeer​(Host peerHost)
      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

      void forceRemovePeer​(Host peerHost)
      Removes the peer from the network layer, which closes any open connections.
      Parameters:
      peerHost - The peer to remove from the network layer
    • isConnectionActive

      boolean isConnectionActive​(Host peerHost)
      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

      void sendMessage​(short msgCode, Object payload, Host to, boolean newChannel)
      Sends a message to a peer, possibly using a dedicated channel
      Parameters:
      msgCode - The code of the message to send
      payload - The message to send
      to - The peer to send the message to
      newChannel - Whether to create a dedicated channel to send the message or not
    • sendMessage

      void sendMessage​(short msgCode, Object msg, Host to)
      Sends a message to a peer
      Parameters:
      msgCode - The code of the message to send
      msg - The message to send
      to - The peer to send the message to
    • broadcastMessage

      void broadcastMessage​(short msgCode, Object msg, Iterator<Host> targets)
      Send a message to multiple peers
      Parameters:
      msgCode - The code of the message to send
      msg - The message to send
      targets - The list of peers to send the message to
    • registerConsumer

      void registerConsumer​(short messageCode, IMessageConsumer consumer)
      Registers a new consumer to handle messages with a specific code
      Parameters:
      messageCode - The message to register
      consumer - The consumer to handle messages with the given code
    • registerSerializer

      void registerSerializer​(short messageCode, ISerializer serializer)
      Registers the (de)serializer to be used when sending or receiving messages with a specific code
      Parameters:
      messageCode - The message code to register
      serializer - The object used to (de)serialize messages with the given code
    • registerNodeListener

      void registerNodeListener​(INodeListener listener)
      Registers the listener to receive updates when peer state changes
      Parameters:
      listener - The listener to register.