public class ConnectionManager extends LifecycleParticipant
| Modifier and Type | Class and Description |
|---|---|
static interface |
ConnectionManager.ClientTask<T>
An interface for all the kinds of activities that need a connection to the dbserver, so we can keep track
of how many sessions are in effect, clean up after them, and know when the client is idle and can be closed.
|
| Modifier and Type | Field and Description |
|---|---|
static int |
DEFAULT_SOCKET_TIMEOUT
The default value we will use for timeouts on opening and reading from sockets.
|
| Modifier and Type | Method and Description |
|---|---|
int |
getIdleLimit()
Check how long an idle connection will be kept open for reuse.
|
static ConnectionManager |
getInstance()
Get the singleton instance of this class.
|
int |
getPlayerDBServerPort(int player)
Look up the database server port reported by a given player.
|
int |
getSocketTimeout()
Check how long we will wait for a socket to connect or for a read operation to complete.
|
<T> T |
invokeWithClientSession(int targetPlayer,
ConnectionManager.ClientTask<T> task,
String description)
Obtain a dbserver client session that can be used to perform some task, call that task with the client,
then release the client.
|
boolean |
isRunning()
Check whether we are currently running.
|
void |
setIdleLimit(int seconds)
Determine how long an idle connection will be kept open for reuse.
|
void |
setSocketTimeout(int timeout)
Set how long we will wait for a socket to connect or for a read operation to complete.
|
void |
start()
Start offering shared dbserver sessions.
|
void |
stop()
Stop offering shared dbserver sessions.
|
String |
toString() |
addLifecycleListener, deliverLifecycleAnnouncement, ensureRunning, getLifecycleListeners, removeLifecycleListenerpublic static final int DEFAULT_SOCKET_TIMEOUT
public void setIdleLimit(int seconds)
seconds - how many seconds a connection will be kept open while not being usedIllegalArgumentException - if a negative value is suppliedpublic int getIdleLimit()
public <T> T invokeWithClientSession(int targetPlayer,
ConnectionManager.ClientTask<T> task,
String description)
throws Exception
T - the type that will be returned by the task to be performedtargetPlayer - the player number whose dbserver we wish to communicate withtask - the activity that will be performed with exclusive access to a dbserver connectiondescription - a short description of the task being performed for error reporting if it fails,
should be a verb phrase like "requesting track metadata"IOException - if there is a problem communicatingException - from the underlying task, if anypublic int getPlayerDBServerPort(int player)
player - the player number of interestIllegalStateException - if not runningpublic void setSocketTimeout(int timeout)
timeout - after how many milliseconds will an attempt to open or read from a socket failpublic int getSocketTimeout()
public boolean isRunning()
isRunning in class LifecycleParticipantpublic void start()
throws SocketException
SocketException - if there is a problem opening connectionspublic void stop()
public static ConnectionManager getInstance()
Copyright © 2016–2018 Deep Symmetry, LLC. All rights reserved.