public abstract class Resource extends Object implements IResource
MyResourceFactory factory = new MyResourceFactory();
ResourcePool pool = new ResourcePool(factory, 10, 50);
MyResource resource = pool.getResource();
try {
...
}finally {
resource.release();
}
Constructor and Description |
---|
Resource() |
Modifier and Type | Method and Description |
---|---|
boolean |
acquire()
Atomically acquires a free resource.
|
abstract void |
clear()
Cleans the resource of its contents so it can be returned to the pool.
|
boolean |
isAcquired()
An indication if this resource is currently acquired.
|
boolean |
isFromPool()
An indication if this resource originated from the pool or was allocated on the fly.
|
void |
release()
Atomically sets this resource as free; usually when returning a resource to the pool.
|
void |
setAcquired(boolean acquired)
An indication if this resource is acquired.
|
void |
setFromPool(boolean fromPool)
An indication if this resource originated from the pool or was allocated on the fly.
|
public void setFromPool(boolean fromPool)
IResource
setFromPool
in interface IResource
fromPool
- true
if originated from the pool; false
if not part
of the pool.public boolean isFromPool()
IResource
isFromPool
in interface IResource
true
if originated from the pool; false
if allocated.public boolean acquire()
IResource
public void setAcquired(boolean acquired)
IResource
setAcquired
in interface IResource
acquired
- true
if resource is acquired. false
if resource is
not acquired.public boolean isAcquired()
IResource
IResource.acquire()
, or by use of it's status indicator IResource.setAcquired(boolean)
.isAcquired
in interface IResource
true
if resource is acquired. false
if not yet acquired.public void release()
IResource
Before releasing the resource back into the pool,
is invoked.IResource.clear()
public abstract void clear()
IResource
You may use the
IResource.isFromPool()
indication to decide of a special action before returning a resource to
the pool, or discard any actions on resources not returning to the pool.
clear
in interface IResource
IResource.release()
Copyright © GigaSpaces.