|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object i3.dragos.gm.core.WrapperBooster
public class WrapperBooster
A Wrapper
enhancer to be used by core graph model implementations.
WrapperBooster is not intended for use by extensions or applications, only by back-end implementations!
But since it implements the Wrapper interface, it may also be used as a simple caching wrapper, which might make sense if the back-end does not employ caching (be it through WrapperBooster or a custom mechanism). However, the "switchable wrapping" feature should not be used on any level above the back-end, unless you are absolutely sure you understand all interactions and can foresee or control any future modifications that might be affected by this!
It provides improved performance and ease of use through the following mechanisms:
It makes sense to build certain methods upon others. But according to the general contract, these methods return wrapped entities, entity classes or attributes. To avoid the associated overhead, you can either write non-wrapping variants for internal use only, which bloats the interface and code, or you can simply use WrapperBooster, which allows you to switch off wrapping temporarily.
The recommended way to do so is:
WrapperBooster wb = ...; // force the mode you need boolean wrappingActive = wb.(de)activateWrapping(); // perform your operations [...] // restore the previous mode wb.setWrapping(wrappingActive);
WrapperBooster keeps a cache of objects it has wrapped, and always consults this
cache first, calling the actual wrappers only if necessary. While the direct runtime
effects may be negligible depending on the number and complexity of the wrappers,
the main effect is that a lot less copies (as defined by equals(Object)
)
of a single object are created, resulting in less memory usage / GC activity.
WrapperBooster makes using proxies
easier, by allowing a "pre-wrapper" to be set, which will be called before
the actual wrapper. See the "Guide to Wrappers" for more information.
You should try to follow these suggestions (doc comments ommited):
// make sure to initialize these two so they are never null! private Wrapper wrapper; private WrapperBooster wrapperBooster; public Wrapper getWrapper() { return wrapper; } // public so it can be accessed by the schema public WrapperBooster getWrapperBooster() { return wrapperBooster; } public void setWrapper(Wrapper w) { this.wrapper = w; // save reference to the old WrapperBooster WrapperBooster oldWrapperBooster = this.wrapperBooster; // create and set the new WrapperBooster // add your preWrapper as a parameter here if you need one this.wrapperBooster = new WrapperBooster(w); // clear caches of old WrapperBooster (if any) to free memory if (null != oldWrapperBooster) { oldWrapperBooster.clearCaches(); } }
Use it just like you would use the ordinary wrapper. Instead of
graphPool.getWrapper().wrapGraphEntity(g);you would write
graphPool.getWrapperBooster().wrapGraphEntity(g);
If you want to call another method internally and do not need its results in a wrapped form, use
graphPool.getWrapperBooster().deactivateWrapping(); CollectionNote that this also affects the pre-wrapper, which is deactivated, too! If you need a different behaviour, it should be easy to add an additional flag to WrapperBooster.= someMethod(); graphPool.getWrapperBooster().activateWrapping();
null
parameters
For your convenience, WrapperBooster allows null
parameters
to the various Wrapper methods. In these cases, null
is returned.
To allow multi-threaded applications, the wrapping status is tracked independently for each thread.
Constructor Summary | |
---|---|
WrapperBooster(Wrapper boostedWrapper)
Creates a new WrapperBooster. |
|
WrapperBooster(Wrapper boostedWrapper,
Wrapper preWrapper)
Creates a new WrapperBooster. |
Methods inherited from class java.lang.Object |
---|
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public WrapperBooster(Wrapper boostedWrapper) throws DragosException
boostedWrapper
- the boosted wrapper
DragosException
- in case of internal errors (especially during cache initialization).public WrapperBooster(Wrapper boostedWrapper, Wrapper preWrapper) throws DragosException
boostedWrapper
- the boosted wrapperpreWrapper
- the pre-wrapper (may be null
)
DragosException
- in case of internal errors (especially during cache initialization).Method Detail |
---|
public boolean activateWrapping()
true
if wrapping was active before, false
otherwise.public boolean deactivateWrapping()
true
if wrapping was active before, false
otherwise.public void setWrapping(boolean active)
activateWrapping()
or
deactivateWrapping()
. It has no effect
if the requested wrapping mode is already set.
active
- true
if wrapping shall be activated, false
otherwise.public void clearCaches() throws DragosException
It should be called on an old WrapperBooster after replacing it to free the resources for the caches (which otherwise will not happen until the WrapperBooster is garbage collected).
DragosException
- DragosException in case of internal errors.protected void finalize() throws java.lang.Throwable
We can only do this here, not even in an explicit user-invoked method before, because of multi-threading concerns: If another thread already has a reference to a cache, is suspended while the cache is removed, and tries to retrieve an object from it later, it would catch an Exception.
finalize
in class java.lang.Object
java.lang.Throwable
- in case of internal errors.public boolean isWrappingActive()
true
if wrapping is activated for this thread.public GraphEntity wrapGraphEntity(GraphEntity g) throws DragosException
Wrapper
interface, this
implementation allows null
values (for which
it will return null
).
wrapGraphEntity
in interface Wrapper
g
- The GraphEntity to wrap, may be null
.
DragosException
- in case of errors during wrapping.public Edge wrapEdge(Edge g) throws DragosException
Wrapper.wrapGraphEntity(GraphEntity)
to avoid casting.
In contrast to the general Wrapper
interface, this
implementation allows null
values (for which
it will return null
).
wrapEdge
in interface Wrapper
g
- The GraphEntity to wrap, may be null
.
Wrapper.wrapGraphEntity(GraphEntity)
for details
DragosException
- in case of errors during wrapping.public Graph wrapGraph(Graph g) throws DragosException
Wrapper.wrapGraphEntity(GraphEntity)
to avoid casting.
In contrast to the general Wrapper
interface, this
implementation allows null
values (for which
it will return null
).
wrapGraph
in interface Wrapper
g
- The GraphEntity to wrap, may be null
.
Wrapper.wrapGraphEntity(GraphEntity)
for details
DragosException
- in case of errors during wrapping.public Node wrapNode(Node g) throws DragosException
Wrapper.wrapGraphEntity(GraphEntity)
to avoid casting.
In contrast to the general Wrapper
interface, this
implementation allows null
values (for which
it will return null
).
wrapNode
in interface Wrapper
g
- The GraphEntity to wrap, may be null
.
Wrapper.wrapGraphEntity(GraphEntity)
for details
DragosException
- in case of errors during wrapping.public Relation wrapRelation(Relation g) throws DragosException
Wrapper.wrapGraphEntity(GraphEntity)
to avoid casting.
In contrast to the general Wrapper
interface, this
implementation allows null
values (for which
it will return null
).
wrapRelation
in interface Wrapper
g
- The GraphEntity to wrap, may be null
.
Wrapper.wrapGraphEntity(GraphEntity)
for details
DragosException
- in case of errors during wrapping.public RelationEnd wrapRelationEnd(RelationEnd g) throws DragosException
Wrapper.wrapGraphEntity(GraphEntity)
to avoid casting.
In contrast to the general Wrapper
interface, this
implementation allows null
values (for which
it will return null
).
wrapRelationEnd
in interface Wrapper
g
- The GraphEntity to wrap, may be null
.
Wrapper.wrapGraphEntity(GraphEntity)
for details
DragosException
- in case of errors during wrapping.public GraphEntityClass wrapGraphEntityClass(GraphEntityClass g) throws DragosException
Wrapper
interface, this
implementation allows null
values (for which
it will return null
).
wrapGraphEntityClass
in interface Wrapper
g
- The GraphEntityClass to wrap, may be null
.
DragosException
- in case of errors during wrapping.public EdgeClass wrapEdgeClass(EdgeClass g) throws DragosException
Wrapper.wrapGraphEntityClass(GraphEntityClass)
to avoid casting.
In contrast to the general Wrapper
interface, this
implementation allows null
values (for which
it will return null
).
wrapEdgeClass
in interface Wrapper
g
- The GraphEntityClass to wrap, may be null
.
Wrapper.wrapGraphEntityClass(GraphEntityClass)
for details
DragosException
- in case of errors during wrapping.public GraphClass wrapGraphClass(GraphClass g) throws DragosException
Wrapper.wrapGraphEntityClass(GraphEntityClass)
to avoid casting.
In contrast to the general Wrapper
interface, this
implementation allows null
values (for which
it will return null
).
wrapGraphClass
in interface Wrapper
g
- The GraphEntityClass to wrap, may be null
.
Wrapper.wrapGraphEntityClass(GraphEntityClass)
for details
DragosException
- in case of errors during wrapping.public NodeClass wrapNodeClass(NodeClass g) throws DragosException
Wrapper.wrapGraphEntityClass(GraphEntityClass)
to avoid casting.
In contrast to the general Wrapper
interface, this
implementation allows null
values (for which
it will return null
).
wrapNodeClass
in interface Wrapper
g
- The GraphEntityClass to wrap, may be null
.
Wrapper.wrapGraphEntityClass(GraphEntityClass)
for details
DragosException
- in case of errors during wrapping.public RelationClass wrapRelationClass(RelationClass g) throws DragosException
Wrapper.wrapGraphEntityClass(GraphEntityClass)
to avoid casting.
In contrast to the general Wrapper
interface, this
implementation allows null
values (for which
it will return null
).
wrapRelationClass
in interface Wrapper
g
- The GraphEntityClass to wrap, may be null
.
Wrapper.wrapGraphEntityClass(GraphEntityClass)
for details
DragosException
- in case of errors during wrapping.public RelationEndClass wrapRelationEndClass(RelationEndClass g) throws DragosException
Wrapper.wrapGraphEntityClass(GraphEntityClass)
to avoid casting.
In contrast to the general Wrapper
interface, this
implementation allows null
values (for which
it will return null
).
wrapRelationEndClass
in interface Wrapper
g
- The GraphEntityClass to wrap, may be null
.
Wrapper.wrapGraphEntityClass(GraphEntityClass)
for details
DragosException
- in case of errors during wrapping.public Attribute wrapAttribute(Attribute a) throws DragosException
Wrapper
interface, this
implementation allows null
values (for which
it will return null
).
wrapAttribute
in interface Wrapper
a
- The Attribute to wrap, may be null
.
DragosException
- in case of errors during wrapping.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |