|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.zfabrik.resources.provider.Resource
public abstract class Resource
Resource base class.
Resources model named, memory-managed objects that may have dependencies onto other resources and may have a non-trivial life cycle. For example all component factories are required to provide extensions of this class.
The resource management system is the underpinning of z2's on-demand behavior. The typical life cycle of a resource implementation instance looks as follows
as(Class) calls may occur. In order to provide the required result or to implement some side-effect, a
resource implementation may build up state and use other resources:
handle().addDependency(<handle of required resource>)See also
IResourceHandle.addDependency(IResourceHandle).
handle().attach(Object)if it is desired that the resource instance be kept as long as the returned objects (see
IResourceHandle.attach(Object)).
synchronized as invalidations may happen at any timehandle().adjust(long, long, short)See also
IResourceHandle.adjust(long, long, short).
Reasons for this vary. For example Web Applications require explicit "stop" calls, so that a resource representing a Web application may not be silently collected.
IResourceHandle.adjust(long, long, short)), the resource may be collected once no other reference holds on to a resource handle for it.
During invalidation, a resource should clean up any state built up since provisioning and return to a freshly provisioned status.
| Constructor Summary | |
|---|---|
Resource()
|
|
| Method Summary | ||
|---|---|---|
|
as(java.lang.Class<T> clz)
Retrieve a typed representation of the resource. |
|
IResourceHandle |
handle()
Return the handle for this resource. |
|
void |
init()
Called at initialization time with the resource management. |
|
void |
init(IResourceHandle c)
|
|
void |
invalidate()
This method gets called whenever a dependency resource has been invalidated or this resource needs to be invalidated. |
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public Resource()
| Method Detail |
|---|
public final void init(IResourceHandle c)
public void init()
public final IResourceHandle handle()
public void invalidate()
throws ResourceBusyException
This code should be executed in a life cycle code block of this resource instance, i.e. where dependencies are effectively managed, so that race conditions can be avoided.
State changing methods of a resource should always be synchronized (e.g. on this). This is
in particular true for cross-resource dependencies. In order to assure consistency under race conditions,
a dependent resource should first declare its dependency and then retrieve the resource implementation.
In case of failures, resources should clean up by calling handle().invalidate(true);
source -
ResourceBusyExceptionpublic <T> T as(java.lang.Class<T> clz)
clz - expected return type
null
if the type facade is not supported.
ResourceTypeNotAvailableException - if the type is supported but cannot be made
available due to an error situation
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||