Package com.zfabrik.resources
Interface IResourceHandle
public interface IResourceHandle
A 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
FieldsModifier and TypeFieldDescriptionstatic final shortDeprecated.static final shortReference mode soft, meaning the resource will be observed (but not necessarily kept) using a soft referencestatic final shortReference mode strong, meaning the resource will be observed (and kept) using a strong referencestatic final shortReference mode weak, meaning the resource will be observed (but not necessarily kept) using a weak reference -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds a dependency for this resource.voidadjust(long ttl, long exp, short rm) Adjust the life-cycle handling of the single resource<T> TRetrieve a resource representation adhering to the passed-on type reference.<T> TRetrieve a resource representation adhering to the passed-on type.voidAttach the handle to an object.voidDetach the handle from an object.Get the observer, an id to the handle that does not determine the handles life cycleGets resource infobooleanChecks whether this handle depends on the resource associated to the passed-in handle.voidinvalidate(boolean forced) Invalidate the resource.voidRemoves a dependency from this resource.
-
Field Details
-
WEAK
static final short WEAKReference mode weak, meaning the resource will be observed (but not necessarily kept) using a weak reference- See Also:
-
SOFT
static final short SOFTReference mode soft, meaning the resource will be observed (but not necessarily kept) using a soft reference- See Also:
-
STRONG
static final short STRONGReference mode strong, meaning the resource will be observed (and kept) using a strong reference- See Also:
-
HARD
Deprecated.userSTRONG- See Also:
-
-
Method Details
-
adjust
void adjust(long ttl, long exp, short rm) Adjust the life-cycle handling of the single resource- Parameters:
ttl- a time-to-live parameter.exp- an absolute point in time. When reaching exp, the resource will be automatically invalidated. Set toLong.MAX_VALUEby default.rm- the type of reference applied when holding onto the resource (seeWEAK,SOFT,STRONG).
-
invalidate
Invalidate the resource.- Parameters:
forced- iftruethe resource cannot veto by throwing a ResourceBusyException. Otherwise it can.- Throws:
ResourceBusyException
-
as
Retrieve a resource representation adhering to the passed-on type. For components default resolutions exist.- Parameters:
clz- the expected return type
-
as
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
Checks whether this handle depends on the resource associated to the passed-in handle. -
addDependency
Adds a dependency for this resource. The invalidation or termination of a dependency resource implies the invalidation of this resource -
removeDependency
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
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
Detach the handle from an object. Seeattach(Object).
-
STRONG