Package com.zfabrik.resources
Interface IResourceHandle
-
public interface IResourceHandleA resource handle is a nameless accessor to a resource managed by the resource management system.The handle can be used to add and remove dependencies of a resource, to adjust the life-cycle handling of a resource and generally to hold on to a resource.
Resources that are not managed by hard references will not be collected as long as an associated resource handle is held onto.
- Author:
- hb
-
-
Field Summary
Fields Modifier and Type Field Description static shortHARDDeprecated.userSTRONGstatic shortSOFTReference mode soft, meaning the resource will be observed (but not necessarily kept) using a soft referencestatic shortSTRONGReference mode strong, meaning the resource will be observed (and kept) using a strong referencestatic shortWEAKReference mode weak, meaning the resource will be observed (but not necessarily kept) using a weak reference
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description voidaddDependency(IResourceHandle rh)Adds a dependency for this resource.voidadjust(long ttl, long exp, short rm)Adjust the life-cycle handling of the single resource<T> Tas(TypeRef<T> typeRef)Retrieve a resource representation adhering to the passed-on type reference.<T> Tas(java.lang.Class<T> clz)Retrieve a resource representation adhering to the passed-on type.voidattach(java.lang.Object o)Attach the handle to an object.voiddetach(java.lang.Object o)Detach the handle from an object.IResourceObservergetObserver()Get the observer, an id to the handle that does not determine the handles life cycleIResourceInfogetResourceInfo()Gets resource infobooleanhasDependency(IResourceHandle rh)Checks whether this handle depends on the resource associated to the passed-in handle.voidinvalidate(boolean forced)Invalidate the resource.voidremoveDependency(IResourceHandle rh)Removes a dependency from this resource.
-
-
-
Field Detail
-
WEAK
static final short WEAK
Reference mode weak, meaning the resource will be observed (but not necessarily kept) using a weak reference- See Also:
- Constant Field Values
-
SOFT
static final short SOFT
Reference mode soft, meaning the resource will be observed (but not necessarily kept) using a soft reference- See Also:
- Constant Field Values
-
STRONG
static final short STRONG
Reference mode strong, meaning the resource will be observed (and kept) using a strong reference- See Also:
- Constant Field Values
-
HARD
@Deprecated static final short HARD
Deprecated.userSTRONG- See Also:
- Constant Field Values
-
-
Method Detail
-
adjust
void adjust(long ttl, long exp, short rm)Adjust the life-cycle handling of the single resource
-
invalidate
void invalidate(boolean forced) throws ResourceBusyExceptionInvalidate the resource.- Parameters:
forced- iftruethe resource cannot veto by throwing a ResourceBusyException. Otherwise it can.- Throws:
ResourceBusyException
-
as
<T> T as(java.lang.Class<T> clz)
Retrieve a resource representation adhering to the passed-on type. For components default resolutions exist.- Parameters:
clz- the expected return type
-
as
<T> T as(TypeRef<T> typeRef)
Retrieve a resource representation adhering to the passed-on type reference. For components default resolutions exist. The default implementation delegates toas(Class)whenever possible. Using theTypeRefAPI, it is possible to specify parameterized types in a type-safe manner. For example:lookup(new TypeRef<List<String>>(){});- Parameters:
typeRef- the expected return type specified viaTypeRef(that also supports parameterized types)
-
hasDependency
boolean hasDependency(IResourceHandle rh)
Checks whether this handle depends on the resource associated to the passed-in handle.
-
addDependency
void addDependency(IResourceHandle rh)
Adds a dependency for this resource. The invalidation or termination of a dependency resource implies the invalidation of this resource
-
removeDependency
void removeDependency(IResourceHandle rh)
Removes a dependency from this resource.
-
getResourceInfo
IResourceInfo getResourceInfo()
Gets resource info
-
getObserver
IResourceObserver getObserver()
Get the observer, an id to the handle that does not determine the handles life cycle
-
attach
void attach(java.lang.Object o)
Attach the handle to an object. That means, as long as the object is held by some reference, the handle and accordingly the resource not be collected. This is a good way of propagating the singleton aspect of the handle and the resource implementation to its emitted objects.
-
detach
void detach(java.lang.Object o)
Detach the handle from an object. Seeattach(Object).
-
-