Interface RecyclerInterface<R extends RecyclableInterface<R,P>,P extends RecyclerRequestInterface>
-
- Type Parameters:
R- Recyclable typeP- Request type
- All Superinterfaces:
Freeable
- All Known Implementing Classes:
BasicRecycler
public interface RecyclerInterface<R extends RecyclableInterface<R,P>,P extends RecyclerRequestInterface> extends Freeable
Interface implemented by all recyclers. A recycler manages a pool of live (used) recyclable objects and a pool of available (ready to be recycled) recyclable objects.- Author:
- royer
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description voidaddListener(RecyclerListenerInterface pRecyclerListener)Adds a recycler listener to this recycler.voidclearLive()Clears the list of live objects and frees them if the 'autofree' flag is setvoidclearReleased()Clears the list of available objects and frees them if the 'autofree' flag is set.longcomputeAvailableMemorySizeInBytes()Returns the calculated total size in bytes of available objects.longcomputeLiveMemorySizeInBytes()Returns the calculated total size in bytes of live objects.longensurePreallocated(long pNumberofPrealocatedRecyclablesNeeded, P pRecyclerRequest)Ensures that a given number of recyclable objects are available.Rget(boolean pWaitForLiveRecyclablesToComeBack, long pWaitTime, TimeUnit pTimeUnit, P pRecyclerRequest)Requests a recyclable object (all other get methods delegate to this one).intgetMaxNumberOfAvailableObjects()Returns the maximum number of available objects allowed.intgetMaxNumberOfLiveObjects()Returns the maximum number of live objects allowed.intgetNumberOfAvailableObjects()Returns the current number of recyclable objects available for recycling.longgetNumberOfFailedRequests()Returns the number of failed requests.intgetNumberOfLiveObjects()Returns the current number of live objects - these are objects that are curently in use and thus not available for recycling.RgetOrFail(P pRecyclerRequest)Attempts to get a recyclable object from this recycler for a given request.RgetOrWait(long pWaitTime, TimeUnit pTimeUnit, P pRecyclerRequest)Waits for a given amount of time to return a recyclable object given a request.voidprintDebugInfo()Prints debug infovoidrelease(R pObject)Releases the given objectvoidremoveListener(RecyclerListenerInterface pRecyclerListener)Remioves a recycler listener to this recycler.-
Methods inherited from interface net.haesleinhuepf.clij.coremem.rgc.Freeable
complainIfFreed, free, isFree
-
-
-
-
Method Detail
-
ensurePreallocated
long ensurePreallocated(long pNumberofPrealocatedRecyclablesNeeded, P pRecyclerRequest)Ensures that a given number of recyclable objects are available.- Parameters:
pNumberofPrealocatedRecyclablesNeeded- number of preallocated recyclablespRecyclerRequest- request to use for instanciating the recyclable objects- Returns:
- effective number of recyclable objects allocated.
-
getOrFail
R getOrFail(P pRecyclerRequest)
Attempts to get a recyclable object from this recycler for a given request. This call might fail in which case a null reference is returned.- Parameters:
pRecyclerRequest- request- Returns:
- null if failed to get a recyclable.
-
getOrWait
R getOrWait(long pWaitTime, TimeUnit pTimeUnit, P pRecyclerRequest)
Waits for a given amount of time to return a recyclable object given a request.- Parameters:
pWaitTime- wait timepTimeUnit- wait time unitpRecyclerRequest- request- Returns:
- null if fails to get a new recyclable object before timeout
-
get
R get(boolean pWaitForLiveRecyclablesToComeBack, long pWaitTime, TimeUnit pTimeUnit, P pRecyclerRequest)
Requests a recyclable object (all other get methods delegate to this one).- Parameters:
pWaitForLiveRecyclablesToComeBack- as it names suggest, this flag causes this call to wait until an object is available.pWaitTime- wait timepTimeUnit- wait time unitpRecyclerRequest- request- Returns:
- null if fails or timeout
-
getMaxNumberOfLiveObjects
int getMaxNumberOfLiveObjects()
Returns the maximum number of live objects allowed.- Returns:
- maximum number of live objects allowed
-
getNumberOfLiveObjects
int getNumberOfLiveObjects()
Returns the current number of live objects - these are objects that are curently in use and thus not available for recycling.- Returns:
- number of live objects
-
getMaxNumberOfAvailableObjects
int getMaxNumberOfAvailableObjects()
Returns the maximum number of available objects allowed.- Returns:
- max number of available objects
-
getNumberOfAvailableObjects
int getNumberOfAvailableObjects()
Returns the current number of recyclable objects available for recycling.- Returns:
- number of available recyclable objects
-
getNumberOfFailedRequests
long getNumberOfFailedRequests()
Returns the number of failed requests.- Returns:
- number of failed requests
-
computeLiveMemorySizeInBytes
long computeLiveMemorySizeInBytes()
Returns the calculated total size in bytes of live objects.- Returns:
- total siee of live objects in bytes
-
computeAvailableMemorySizeInBytes
long computeAvailableMemorySizeInBytes()
Returns the calculated total size in bytes of available objects.- Returns:
- calculated total size in bytes
-
release
void release(R pObject)
Releases the given object- Parameters:
pObject- recyclable object to release
-
clearReleased
void clearReleased()
Clears the list of available objects and frees them if the 'autofree' flag is set.
-
clearLive
void clearLive()
Clears the list of live objects and frees them if the 'autofree' flag is set
-
addListener
void addListener(RecyclerListenerInterface pRecyclerListener)
Adds a recycler listener to this recycler.- Parameters:
pRecyclerListener- recycler listener
-
removeListener
void removeListener(RecyclerListenerInterface pRecyclerListener)
Remioves a recycler listener to this recycler.- Parameters:
pRecyclerListener- recycler listener
-
printDebugInfo
void printDebugInfo()
Prints debug info
-
-