public class ClientPool extends Object
Standard VFS lacks support for connection pooling. For every resolve a new connection over FTP, SFTP etc. is established. This is OK for single files being resolved but not suitable for FTP client applications. If a FTP or SFTP connection has been established once it is cached and re-used whenever an appropriate network file is being resolved.
This pool mechanism is appropriate for stateful protocols like FTP, FTPS, and SFTP (not for HTTP).
Helpful commands to monitor incoming FTP/SFTP connections under Linux:
while (true) ; do clear;ps aux|grep vsftp ; sleep 1; done
while (true) ; do clear;ps aux|grep sshd: ; sleep 1; done
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(Object id)
Checks whether a factory shared object can be released or not.
|
void |
cleanup(Object id)
Perform optional cleanup tasks like closing network connections or disposing dialogs.
|
String |
debugPrint()
Convenience method to show the current client pool.
|
ClientWrapper |
getFreeClient(String url)
Provides an open client for the network, recycled from the pool if possible (convenience).
|
void |
getRegisteredObjects()
Provides the currently managed objects.
|
static ClientPool |
getSharedInstance()
Provides the shared instance of the factory implementation.
|
boolean |
hasSharedInstance(Object id)
Create the factory shared object, recycle if already existing.
|
void |
release(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).
|
Object |
request(Object id)
Provides an open client for the network, recycled from the pool (same as
getFreeClient() ). |
Object |
set(Object id,
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.
|
public static ClientPool getSharedInstance()
public Object request(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.
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(String url)
url
- The client URL including login, port etc.null
if an error occurredNullPointerException
- If parameters are null
public void addClient(ClientWrapper client)
The new client is locked automatically here.
client
- Client to be addedNullPointerException
- If parameters are null
public boolean unlockClient(ClientWrapper client)
client
- Client to be releasedNullPointerException
- If parameters are null
public boolean canRelease(Object id)
id
- The factory-unique identifier of the shared objectpublic void release(Object id)
id
- The factory-unique identifier of the shared objectNullPointerException
- If a parameter is null
public void releaseForced()
This functionality can be used in order to make as much of occupied memory as possible
available again. Normally this method calls the various 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).
public void releaseByStrategy()
For applications it may be useful to flush its caches but keep certain objects/resources untouched since they will be needed in the future or the recreation would be expensive (e.g. when contents must be loaded from a database or from the internet).
This method should be used by a periodically executed release task in order to release all shared objects with timeout strategy.
public void cleanup(Object id)
id
- The factory-unique identifier of the shared objectpublic boolean hasSharedInstance(Object id)
id
- The factory-unique identifier of the shared objectpublic void getRegisteredObjects()
public Object set(Object id, Object obj)
id
- The factory-unique identifier of the shared objectobj
- The new objectnull
NullPointerException
- If a parameter is null
public String debugPrint()
Copyright © 2005-2024 Leisenfels GmbH. All rights reserved.