public interface IResourceHandle
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.
Modifier and Type | Field | Description |
---|---|---|
static short |
HARD |
Deprecated.
user
STRONG |
static short |
SOFT |
Reference mode soft, meaning the resource will be observed
(but not necessarily kept) using a soft reference
|
static short |
STRONG |
Reference mode strong, meaning the resource will be observed
(and kept) using a strong reference
|
static short |
WEAK |
Reference mode weak, meaning the resource will be observed
(but not necessarily kept) using a weak reference
|
Modifier and Type | Method | Description |
---|---|---|
void |
addDependency(IResourceHandle rh) |
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 |
as(TypeRef<T> typeRef) |
Retrieve a resource representation adhering to the passed-on type reference.
|
<T> T |
as(java.lang.Class<T> clz) |
Retrieve a resource representation adhering to the passed-on type.
|
void |
attach(java.lang.Object o) |
Attach the handle to an object.
|
void |
detach(java.lang.Object o) |
Detach the handle from an object.
|
IResourceObserver |
getObserver() |
Get the observer, an id to the handle that does not determine the handles life cycle
|
IResourceInfo |
getResourceInfo() |
Gets resource info
|
boolean |
hasDependency(IResourceHandle rh) |
Checks whether this handle depends on the resource associated to the passed-in handle.
|
void |
invalidate(boolean forced) |
Invalidate the resource.
|
void |
removeDependency(IResourceHandle rh) |
Removes a dependency from this resource.
|
static final short WEAK
static final short SOFT
static final short STRONG
@Deprecated static final short HARD
STRONG
void adjust(long ttl, long exp, short rm)
void invalidate(boolean forced) throws ResourceBusyException
forced
- if true
the resource cannot veto by throwing a ResourceBusyException. Otherwise it can.ResourceBusyException
<T> T as(java.lang.Class<T> clz)
clz
- the expected return type<T> T as(TypeRef<T> typeRef)
as(Class)
whenever possible.
Using the TypeRef
API, it is possible to specify parameterized types in a type-safe manner. For example:
lookup(new TypeRef<List<String>>(){});
typeRef
- the expected return type specified via TypeRef
(that also supports parameterized types)boolean hasDependency(IResourceHandle rh)
void addDependency(IResourceHandle rh)
void removeDependency(IResourceHandle rh)
IResourceInfo getResourceInfo()
IResourceObserver getObserver()
void attach(java.lang.Object o)
void detach(java.lang.Object o)
attach(Object)
.