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 short
Deprecated.static final short
Reference mode soft, meaning the resource will be observed (but not necessarily kept) using a soft referencestatic final short
Reference mode strong, meaning the resource will be observed (and kept) using a strong referencestatic final short
Reference mode weak, meaning the resource will be observed (but not necessarily kept) using a weak reference -
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds a dependency for this resource.void
adjust
(long ttl, long exp, short rm) Adjust the life-cycle handling of the single resource<T> T
Retrieve a resource representation adhering to the passed-on type reference.<T> T
Retrieve a resource representation adhering to the passed-on type.void
Attach the handle to an object.void
Detach the handle from an object.Get the observer, an id to the handle that does not determine the handles life cycleGets resource infoboolean
Checks whether this handle depends on the resource associated to the passed-in handle.void
invalidate
(boolean forced) Invalidate the resource.void
Removes 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_VALUE
by default.rm
- the type of reference applied when holding onto the resource (seeWEAK
,SOFT
,STRONG
).
-
invalidate
Invalidate the resource.- Parameters:
forced
- iftrue
the 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 theTypeRef
API, 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