Class serverHandler

java.lang.Object
org.apache.mina.core.service.IoHandlerAdapter
name.moore.kevin.ze.game.states.remote.serverHandler
All Implemented Interfaces:
org.apache.mina.core.service.IoHandler

public class serverHandler extends org.apache.mina.core.service.IoHandlerAdapter
Use the static serverHandler.makeServer() to create a new server. Register functions that handle required incoming datatypes.
Author:
Kevin Moore <dev@kevin.moore.name>
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private org.apache.mina.core.service.IoAcceptor
    The server socket.
    private Map<Class,​Consumer<Object>>
    Used to provide handling functions for incoming data.
    private static org.slf4j.Logger
     
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    private
    serverHandler​(org.apache.mina.core.service.IoAcceptor acceptor)
    Only called via the static makeServer.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Send the object to all connected sessions.
    void
     
    void
    exceptionCaught​(org.apache.mina.core.session.IoSession session, Throwable cause)
     
    makeServer​(int port)
     
    void
    messageReceived​(org.apache.mina.core.session.IoSession session, Object message)
    void
    Server manager provides functions to handle different types of incoming objects.

    Methods inherited from class org.apache.mina.core.service.IoHandlerAdapter

    event, inputClosed, messageSent, sessionClosed, sessionCreated, sessionIdle, sessionOpened

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

    • serverHandler

      private serverHandler(org.apache.mina.core.service.IoAcceptor acceptor)
      Only called via the static makeServer. Remember the socket for broadcasting messages.
      Parameters:
      acceptor -
  • Method Details

    • makeServer

      public static serverHandler makeServer(int port) throws IOException
      Parameters:
      port -
      Returns:
      Throws:
      IOException
    • closeServer

      public void closeServer()
    • broadcast

      public void broadcast(Object s)
      Send the object to all connected sessions.
      Parameters:
      s -
    • registerFunction

      public void registerFunction(Class c, Consumer<Object> f)
      Server manager provides functions to handle different types of incoming objects.
      Parameters:
      c - class of incoming object
      f - function to handle it.
    • messageReceived

      public void messageReceived(org.apache.mina.core.session.IoSession session, Object message) throws Exception
      Specified by:
      messageReceived in interface org.apache.mina.core.service.IoHandler
      Overrides:
      messageReceived in class org.apache.mina.core.service.IoHandlerAdapter
      Throws:
      Exception
    • exceptionCaught

      public void exceptionCaught(org.apache.mina.core.session.IoSession session, Throwable cause) throws Exception
      Specified by:
      exceptionCaught in interface org.apache.mina.core.service.IoHandler
      Overrides:
      exceptionCaught in class org.apache.mina.core.service.IoHandlerAdapter
      Throws:
      Exception