Class NIONetworkConnectionManager

java.lang.Object
java.lang.Thread
marauroa.server.net.nio.NIONetworkConnectionManager
All Implemented Interfaces:
Runnable, ConnectionManager, IWorker

public final class NIONetworkConnectionManager extends Thread implements IWorker, ConnectionManager
This is the implementation of a worker that sends messages, receives them, ... This class also handles validation of connection and disconnection events
Author:
miguel
  • Constructor Details

    • NIONetworkConnectionManager

      public NIONetworkConnectionManager(IServerManager serverManager) throws IOException
      Constructor
      Throws:
      IOException - if there any exception when starting the socket server.
  • Method Details

    • setServer

      public void setServer(marauroa.server.net.nio.NioServer server)
      Associate this object with a server. This model a master-slave approach for managing network messages.
      Specified by:
      setServer in interface IWorker
      Parameters:
      server - the master server.
    • finish

      public void finish()
      This method notifies the thread to finish the execution
      Specified by:
      finish in interface ConnectionManager
    • isFinished

      public boolean isFinished()
      Description copied from interface: ConnectionManager
      was the server shutdown?
      Specified by:
      isFinished in interface ConnectionManager
      Returns:
      true, if the server was shut down; false otherwise
    • onConnect

      public void onConnect(SocketChannel internalChannel)
      We check that this socket is not banned. We do it just on connect so we save lots of queries.
      Specified by:
      onConnect in interface IWorker
      Parameters:
      internalChannel - SocketChannel
    • onData

      public void onData(marauroa.server.net.nio.NioServer server, SocketChannel channel, byte[] data, int count)
      This method is called when new data is received on server from channel.
      Specified by:
      onData in interface IWorker
      Parameters:
      server - the master server
      channel - socket channel associated to the event
      data - the data received
      count - the amount of data received.
    • send

      public void send(Object internalChannel, Message msg, boolean isPerceptionRequired)
      This method add a message to be delivered to the client the message is pointed to.
      Specified by:
      send in interface ConnectionManager
      Parameters:
      internalChannel - the channel to the client
      msg - the message to be delivered.
      isPerceptionRequired - true indicates that the message may not be skipped
    • close

      public void close(Object channel)
      This method disconnect a socket.
      Specified by:
      close in interface ConnectionManager
      Parameters:
      channel - the socket channel to close
    • run

      public void run()
      Specified by:
      run in interface Runnable
      Overrides:
      run in class Thread
    • onDisconnect

      public void onDisconnect(SocketChannel channel)
      Removes stored parts of message for this channel at the decoder.
      Specified by:
      onDisconnect in interface IWorker
      Parameters:
      channel - the channel to clear