Package com.j_spaces.kernel.pool
Interface IResource
- All Known Subinterfaces:
IMemoryAwareResource,MarshObjectConvertorResource
- All Known Implementing Classes:
BaseClientPeer,BlobStoreUnpinMultiplePacket,BusPacket,ByteBufferRedoLogFileStorage.ByteArrayResource,CheckXtnStatusInTmBusPackect,CommitBusPacket,CompressedMarshObjectConvertor,ConnectionResource,ConnectionResource,CPeer,EntryArrivedPacket,EntryExpiredBusPacket,EntryTakenPacket,EntryUnmatchedPacket,EntryUpdatedPacket,MarshObjectConvertor,PacketSerializer.InputStreamsResource,ReadWriteLockResource,RemoteEventBatchBusPacket,RemoteEventBusPacket,RemoveWaitingForInfoSABusPacket,Resource,RollbackBusPacket,TraceableResource,UpdateOrWriteBusPacket
public interface IResource
A resource interface required by a
ResourcePool. Resource is the default
implementation. IResource may be used when dealing with hierarchy constraints.
Usage: extend your resource class from Resource public class myResource
extends Resource {...} or if you have hierarchy constraints, implement IResource.
- Since:
- 6.0.2
- Version:
- 1.0
- Author:
- moran
-
Method Summary
Modifier and TypeMethodDescriptionbooleanacquire()Atomically acquires a free resource.voidclear()Cleans the resource of its contents so it can be returned to the pool.booleanAn indication if this resource is currently acquired.booleanAn indication if this resource originated from the pool or was allocated on the fly.voidrelease()Atomically sets this resource as free; usually when returning a resource to the pool.voidsetAcquired(boolean acquired) An indication if this resource is acquired.voidsetFromPool(boolean fromPool) An indication if this resource originated from the pool or was allocated on the fly.
-
Method Details
-
isFromPool
boolean isFromPool()An indication if this resource originated from the pool or was allocated on the fly. The latter, will not return to the pool.- Returns:
trueif originated from the pool;falseif allocated.
-
setFromPool
void setFromPool(boolean fromPool) An indication if this resource originated from the pool or was allocated on the fly. The latter, will not return to the pool.- Parameters:
fromPool-trueif originated from the pool;falseif not part of the pool.
-
isAcquired
boolean isAcquired()An indication if this resource is currently acquired. Usually a resource becomes acquired after a call toacquire(), or by use of it's status indicatorsetAcquired(boolean).- Returns:
trueif resource is acquired.falseif not yet acquired.
-
setAcquired
void setAcquired(boolean acquired) An indication if this resource is acquired.- Parameters:
acquired-trueif resource is acquired.falseif resource is not acquired.
-
acquire
boolean acquire()Atomically acquires a free resource. But, due to race conditions, it may fail.- Returns:
trueif acquire succeeded;falseotherwise (may have already been acquired by another thread).
-
release
void release()Atomically sets this resource as free; usually when returning a resource to the pool.Before releasing the resource back into the pool,
is invoked.clear()- Throws:
RuntimeException- if this Resource was already free.
-
clear
void clear()Cleans the resource of its contents so it can be returned to the pool.You may use the
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.- See Also:
-