public abstract class Connection extends StorableObject
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
KEY_MAX_IDLE_SECS
The dictionary key for the maximum idle time (in seconds).
|
static java.lang.String |
KEY_MAX_OPEN
The dictionary key for the maximum number of open channels.
|
protected java.lang.String |
lastError
The error message for the last error.
|
protected long |
lastUsedTime
The timestamp (in milliseconds) of the last usage time.
|
static Path |
PATH
The connection object storage path.
|
dict, KEY_CLASSNAME, KEY_ID, KEY_TYPE
Modifier | Constructor and Description |
---|---|
protected |
Connection(java.lang.String id,
java.lang.String type,
Dict dict)
Creates a new connection from a serialized representation.
|
Modifier and Type | Method and Description |
---|---|
protected void |
cleanupChannel(Channel channel)
Destroys and removes references to a channel.
|
protected abstract Channel |
createChannel()
Creates a new connection channel.
|
protected void |
destroy()
Destroys this connection.
|
protected abstract void |
destroyChannel(Channel channel)
Destroys a connection channel, freeing any resources used
(such as database connections, networking sockets, etc).
|
static Connection |
find(Storage storage,
java.lang.String id)
Searches for a specific connection in the storage.
|
static Connection[] |
findAll(Storage storage)
Searches for all connections in the storage.
|
protected void |
init()
Initializes this connection after loading it from a storage.
|
protected boolean |
isActive()
Checks if this object is in active use.
|
java.lang.String |
lastError()
Returns the error message for the last error.
|
java.util.Date |
lastUsed()
Returns the timestamp of the last connection usage.
|
int |
maxIdleSeconds()
Returns the maximum number of seconds a channel is allowed to
be idle (in a pool).
|
int |
maxOpen()
Returns the maximum number of open channels.
|
int |
openChannels()
Returns the total number of open channels.
|
protected void |
passivate()
Attempts to deactivate this object.
|
void |
release(Channel channel)
Releases a previously reserved communication channel for this
connection.
|
Channel |
reserve()
Reserves a communication channel for this connection.
|
Dict |
serialize()
Returns a serialized representation of this object.
|
int |
usedChannels()
Returns the number of channels in use (reserved).
|
activate, id, isModified, path, toString, type
public static final java.lang.String KEY_MAX_OPEN
public static final java.lang.String KEY_MAX_IDLE_SECS
public static final Path PATH
protected long lastUsedTime
protected java.lang.String lastError
public static Connection find(Storage storage, java.lang.String id)
storage
- the storage to search inid
- the connection identifierpublic static Connection[] findAll(Storage storage)
storage
- the storage to search inprotected boolean isActive()
isActive
in class StorableObject
protected void init() throws StorageException
init
in class StorableObject
StorageException
- if the initialization failedprotected void destroy()
destroy
in class StorableObject
protected void passivate()
passivate
in class StorableObject
public Dict serialize()
serialize
in class StorableObject
public int maxOpen()
public int maxIdleSeconds()
public int openChannels()
public int usedChannels()
public java.util.Date lastUsed()
public java.lang.String lastError()
public Channel reserve() throws ConnectionException
ConnectionException
- if no communication channel could
be created and validatedpublic void release(Channel channel)
channel
- the channel to releaseprotected void cleanupChannel(Channel channel)
channel
- the channel to destroyprotected abstract Channel createChannel() throws ConnectionException
ConnectionException
- if the channel couldn't be created
properlyprotected abstract void destroyChannel(Channel channel)
channel
- the channel to destroy