W
- Type of worker object being multiplexed.abstract class DatabaseMultiplexer<W> extends java.lang.Object implements RemoteMultiplexer<java.lang.String>
getMultiplexID(String)
method to obtain an ID for a particular physical
database name. This ID will be provided with all future service requests
and is used to multiplex such requests to the appropriate worker object
which is associated with that database.
Subclasses are responsible for implementing the actual service methods,
each of which must accept as a parameter a multiplex ID returned by an
earlier call to getMultiplexID()
. The implementations of
those methods obtain the appropriate worker object to which the request is
delegated by invoking lookupWorker(int)
. This method lazily
associates a worker object with the database identified by the multiplex
ID, the first time it is invoked for a particular ID. This is accomplished
via the getWorker(Database)
method, which must be implemented by
the subclass.
Service requests may originate from more than one external server, so this implementation is threadsafe.
Modifier and Type | Field and Description |
---|---|
private Database[] |
databases
Databases managed by this P2J server instance
|
private java.util.List<W> |
workers
Worker delegates to which requests will be multiplexed
|
Modifier | Constructor and Description |
---|---|
protected |
DatabaseMultiplexer()
Default constructor.
|
Modifier and Type | Method and Description |
---|---|
int |
getMultiplexID(java.lang.String key)
Retrieve a unique ID for the given physical database name on this P2J
server.
|
protected abstract W |
getWorker(Database database)
Get the worker object which is associated with the given database.
|
protected W |
lookupWorker(int id)
Access the appropriate worker delegate for the given database ID.
|
private final Database[] databases
private final java.util.List<W> workers
public final int getMultiplexID(java.lang.String key)
getMultiplexID
in interface RemoteMultiplexer<java.lang.String>
key
- Physical database name.java.lang.IllegalArgumentException
- if no database with the given physical name is configured at
this server.protected final W lookupWorker(int id)
id
- Integer which uniquely identifies a physical database being
managed by the current P2J server instance.protected abstract W getWorker(Database database)
database
- Physical database with which the returned worker is associated.