public class ClientPool
extends com.lf.commons.lang.ManagedFactory
while (true) ; do clear;ps aux|grep vsftp ; sleep 1; done
while (true) ; do clear;ps aux|grep sshd: ; sleep 1; done
Modifier and Type | Field and Description |
---|---|
protected java.util.Hashtable<java.lang.String,java.util.Vector<com.lf.commons.lang.ManagedObject>> |
cachePool
Remembers all clients currently managed by this factory, managed object is
ClientWrapper . |
protected static ClientPool |
sharedInstance
Shared
ClientPool instance. |
protected static com.lf.commons.lang.strategy.TimeoutStrategy |
STRATEGY
Recycled strategy instance.
|
Constructor and Description |
---|
ClientPool()
Default constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
addClient(ClientWrapper client)
Adds a new client for the pool, normally added by the provider client factories.
|
boolean |
canRelease(java.lang.Object id)
Checks whether a factory shared object can be released or not.
|
void |
cleanup(java.lang.Object id)
Perform optional cleanup tasks like closing network connections or disposing dialogs.
|
java.lang.String |
debugPrint()
Convenience method to show the current client pool.
|
protected void |
finalize()
Clean-up method to help the gc.
|
ClientWrapper |
getFreeClient(java.lang.String url)
Provides an open client for the network, recycled from the pool if possible (convenience).
|
com.lf.commons.lang.ManagedObject[] |
getRegisteredObjects()
Provides the currently managed objects.
|
static ClientPool |
getSharedInstance()
Provides the shared instance of the factory implementation.
|
boolean |
hasSharedInstance(java.lang.Object id)
Create the factory shared object, recycle if already existing.
|
void |
release(java.lang.Object id)
Releases the given shared objects immediately (free clients here).
|
void |
releaseByStrategy()
Release managed shared objects according to the configured strategy (free clients here).
|
void |
releaseForced()
Releases all managed shared objects immediately (free clients here).
|
java.lang.Object |
request(java.lang.Object id)
Provides an open client for the network, recycled from the pool (same as
getFreeClient() ). |
java.lang.Object |
set(java.lang.Object id,
java.lang.Object obj)
Sets an object for an existing managed object.
|
boolean |
unlockClient(ClientWrapper client)
Releases an occupied client so that it can be re-used.
|
protected static ClientPool sharedInstance
ClientPool
instance.protected static com.lf.commons.lang.strategy.TimeoutStrategy STRATEGY
protected java.util.Hashtable<java.lang.String,java.util.Vector<com.lf.commons.lang.ManagedObject>> cachePool
ClientWrapper
.protected void finalize() throws java.lang.Throwable
finalize
in class com.lf.commons.lang.ManagedFactory
java.lang.Throwable
- Error indicationpublic static ClientPool getSharedInstance()
public java.lang.Object request(java.lang.Object id)
getFreeClient()
).
Here, a free network client can be requested. If none is available the method returns null
.
The provided network client is locked here automatically and must be unlocked explicitely to be recycled.
If it returns null
you have to create a new client and set it here using addClient()
.
This is necessary since we do not have required parameters like file system options here.
request
in class com.lf.commons.lang.ManagedFactory
id
- The factory-unique identifier of the shared object (String
here, unique URL)null
if none could be created (ClientWrapper
here)getFreeClient(String)
public ClientWrapper getFreeClient(java.lang.String url)
url
- The client URL including login, port etc.null
if an error occurredjava.lang.NullPointerException
- If parameters are null
public void addClient(ClientWrapper client)
client
- Client to be addedjava.lang.NullPointerException
- If parameters are null
public boolean unlockClient(ClientWrapper client)
client
- Client to be releasedjava.lang.NullPointerException
- If parameters are null
public boolean canRelease(java.lang.Object id)
canRelease
in class com.lf.commons.lang.ManagedFactory
id
- The factory-unique identifier of the shared objectpublic void release(java.lang.Object id)
release
in class com.lf.commons.lang.ManagedFactory
id
- The factory-unique identifier of the shared objectjava.lang.NullPointerException
- If a parameter is null
public void releaseForced()
release()
methods
of the factory class and is used always if the application reaches a certain amount
of consumed memory. In critical situations the application can use this method in
order to keep it running or at least store the current configurations or data portions
safely (panic mode).
releaseForced
in class com.lf.commons.lang.ManagedFactory
public void releaseByStrategy()
releaseByStrategy
in class com.lf.commons.lang.ManagedFactory
public void cleanup(java.lang.Object id)
cleanup
in class com.lf.commons.lang.ManagedFactory
id
- The factory-unique identifier of the shared objectpublic boolean hasSharedInstance(java.lang.Object id)
hasSharedInstance
in class com.lf.commons.lang.ManagedFactory
id
- The factory-unique identifier of the shared objectpublic com.lf.commons.lang.ManagedObject[] getRegisteredObjects()
getRegisteredObjects
in class com.lf.commons.lang.ManagedFactory
public java.lang.Object set(java.lang.Object id, java.lang.Object obj)
set
in class com.lf.commons.lang.ManagedFactory
id
- The factory-unique identifier of the shared objectobj
- The new objectnull
java.lang.NullPointerException
- If a parameter is null
public java.lang.String debugPrint()
Copyright © 2005-2014 Leisenfels UG. All rights reserved.