Class AbstractConsoleServer

java.lang.Object
de.calamanari.pk.util.AbstractConsoleServer
Direct Known Subclasses:
AbstractThreadedSocketServer, CustomerManagerServer, ProductManagerServer, SecuMangaGatewayServer

public abstract class AbstractConsoleServer
extends java.lang.Object
This abstract class can be sub-classed to easily create simple servers running on the console.
Several TEMPLATE METHODs allow to define the concrete logic and to control the behavior in subclasses.
Author:
Karl Eilebrecht
  • Nested Class Summary

    Nested Classes
    Modifier and Type Class Description
    static class  AbstractConsoleServer.ServerState
    States for a server's state machine
    Why so many states?
  • Constructor Summary

    Constructors
    Constructor Description
    AbstractConsoleServer​(java.lang.String serverName)
    Creates new server without starting it yet.
  • Method Summary

    Modifier and Type Method Description
    java.lang.String getServerName()
    Returns the name of this server
    AbstractConsoleServer.ServerState getServerState()
    Returns the current state of this server
    void setupAndStart​(java.lang.String[] args)
    Creates stand-alone console server and starts it.
    This method shall be called from main()-method of subclass.
    This TEMPLATE METHOD uses operations implemented by subclasses.
    void start()
    Starts the mock server using the configured port
    This method will return immediately after having started the server thread.
    This TEMPLATE METHOD uses operations implemented by subclasses (see the ServerThread implementation).
    void stop()
    Stops the server
    This TEMPLATE METHOD uses operations implemented by subclasses.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • AbstractConsoleServer

      public AbstractConsoleServer​(java.lang.String serverName)
      Creates new server without starting it yet.
      Parameters:
      serverName - name of this server
  • Method Details

    • setupAndStart

      public void setupAndStart​(java.lang.String[] args)
      Creates stand-alone console server and starts it.
      This method shall be called from main()-method of subclass.
      This TEMPLATE METHOD uses operations implemented by subclasses.
      Parameters:
      args - command line argument
    • start

      public void start()
      Starts the mock server using the configured port
      This method will return immediately after having started the server thread.
      This TEMPLATE METHOD uses operations implemented by subclasses (see the ServerThread implementation).
    • stop

      public void stop()
      Stops the server
      This TEMPLATE METHOD uses operations implemented by subclasses.
    • getServerState

      Returns the current state of this server
      Returns:
      server state
    • getServerName

      public java.lang.String getServerName()
      Returns the name of this server
      Returns:
      server's name