Package com.mckoi.database.jdbcserver
Class SingleThreadedConnectionPoolServer
- java.lang.Object
-
- com.mckoi.database.jdbcserver.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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private classSingleThreadedConnectionPoolServer.ServerConnectionStateThis contains state information about a ServerConnection that is being maintained by the server.private classSingleThreadedConnectionPoolServer.ServerFarmerThis thread is a low priority thread that checks all the current service providers periodically to determine if there's any commands pending.
-
Field Summary
Fields Modifier and Type Field Description private DatabasedatabaseThe Database context.private static booleanDISPLAY_STATSIf this is set to true then the server periodically outputs statistics about the connections.private SingleThreadedConnectionPoolServer.ServerFarmerfarmerThe ServerFarmer object that polls for information from the clients and dispatches the request to the worker threads.private java.util.ArrayListpending_connections_listThe list of ServerConnection objects that are pending to be added into the current service provider list next time it is checked.private static intPING_BREAKThe number of milliseconds between client pings.
-
Constructor Summary
Constructors Constructor Description SingleThreadedConnectionPoolServer(Database database)The Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddConnection(ServerConnection connection)Connects a new ServerConnection into the pool of connections to clients that this server maintains.voidclose()Closes this connection pool server down.DebugLoggerDebug()Returns a DebugLogger object that we can log debug messages to.
-
-
-
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.
-
farmer
private SingleThreadedConnectionPoolServer.ServerFarmer farmer
The ServerFarmer object that polls for information from the clients and dispatches the request to the worker threads.
-
-
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:
addConnectionin interfaceConnectionPoolServer
-
close
public void close()
Closes this connection pool server down.- Specified by:
closein interfaceConnectionPoolServer
-
-