Class SingleThreadedConnectionPoolServer

  • All Implemented Interfaces:
    ConnectionPoolServer

    final class SingleThreadedConnectionPoolServer
    extends java.lang.Object
    implements ConnectionPoolServer
    A generic database server class that provides a thread that dispatches commands to the underlying database. This class only provides a framework for creating a server. It doesn't provide any implementation specifics for protocols.

    An TCP implementation of this class would wait for connections and then create a ServerConnection implementation and feed it into the pool for processing. This object will then poll the ServerConnection until a command is pending, and then dispatch the command to a database worker thread.

    This object will ping the clients every so often to see if they are alive.

    • Field Summary

      Fields 
      Modifier and Type Field Description
      private Database database
      The Database context.
      private static boolean DISPLAY_STATS
      If this is set to true then the server periodically outputs statistics about the connections.
      private SingleThreadedConnectionPoolServer.ServerFarmer farmer
      The ServerFarmer object that polls for information from the clients and dispatches the request to the worker threads.
      private java.util.ArrayList pending_connections_list
      The list of ServerConnection objects that are pending to be added into the current service provider list next time it is checked.
      private static int PING_BREAK
      The number of milliseconds between client pings.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addConnection​(ServerConnection connection)
      Connects a new ServerConnection into the pool of connections to clients that this server maintains.
      void close()
      Closes this connection pool server down.
      DebugLogger Debug()
      Returns a DebugLogger object that we can log debug messages to.
      • Methods inherited from class java.lang.Object

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

      • PING_BREAK

        private static final int PING_BREAK
        The number of milliseconds between client pings. NOTE: Should this be a configurable variable in the '.conf' file? (45 seconds)
        See Also:
        Constant Field Values
      • DISPLAY_STATS

        private static final boolean DISPLAY_STATS
        If this is set to true then the server periodically outputs statistics about the connections.
        See Also:
        Constant Field Values
      • database

        private Database database
        The Database context.
      • pending_connections_list

        private java.util.ArrayList pending_connections_list
        The list of ServerConnection objects that are pending to be added into the current service provider list next time it is checked.
    • Constructor Detail

      • SingleThreadedConnectionPoolServer

        SingleThreadedConnectionPoolServer​(Database database)
        The Constructor. The argument is the configuration file.
    • Method Detail

      • Debug

        public final DebugLogger Debug()
        Returns a DebugLogger object that we can log debug messages to.
      • addConnection

        public void addConnection​(ServerConnection connection)
        Connects a new ServerConnection into the pool of connections to clients that this server maintains. We then cycle through these connections determining whether any commands are pending. If a command is pending we spawn off a worker thread to do the task.
        Specified by:
        addConnection in interface ConnectionPoolServer
      • close

        public void close()
        Closes this connection pool server down.
        Specified by:
        close in interface ConnectionPoolServer