|
||||||||||
PREV PACKAGE NEXT PACKAGE | FRAMES NO FRAMES |
See:
Description
Interface Summary | |
---|---|
HotSwappingInvoker.CycleCheck | Internal interface used to detect cyclic swapping activity. |
Swappable | Interface implemented by all proxy instances created by HotSwappingInvoker . |
Class Summary | |
---|---|
HotSwapping<T> | Factory for proxy instances that allow to exchange the delegated instance. |
HotSwapping.HotSwappingBuild<T> | |
HotSwapping.HotSwappingBuildOrMode<T> | |
HotSwapping.HotSwappingWith<T> | |
HotSwappingInvoker<T> | A DelegatingInvoker implementation that allows the exchange of the delegate. |
A toy to hot swap instances.
The package provides a proxy factory creating proxies, that can hot
swap instances. Main component is the HotSwapping toy, a
utility class creating these proxies. Such a proxy contains an instance
of a HotSwappingInvoker
that
delegates all calls. The implementation subclasses the Delegating toy. The
proxy itself implements the additional Swappable interface
that
can be utilized to exchange the delegate without further notice for any
other object using that instance.
Following example demonstrates this with a PrintWriter, that will not take any notice, that his delegated OutputStream will be hot swapped for every line separating odd and even lines:
ByteArrayOutputStream outStreamOdd = new ByteArrayOutputStream(); ByteArrayOutputStream outStreamEven = new ByteArrayOutputStream(); OutputStream out = HotSwapping.proxy(OutputStream.class) .with(null) .build(new CglibProxyFactory()); PrintWriter writer = new PrintWriter(out); for (int i = 0; i < 10; ++i) { Swappable swappable = Swappable.class.cast(out); if (i % 2 > 0) { swappable.hotswap(outStreamEven); } else { swappable.hotswap(outStreamOdd); } writer.println("Line " + (i + 1)); writer.flush(); } System.out.println(); System.out.println("Odd lines output:"); System.out.println(outStreamOdd.toString()); System.out.println("Even lines output:"); System.out.println(outStreamEven.toString());
Note that the first delegate is even the null object.
|
||||||||||
PREV PACKAGE NEXT PACKAGE | FRAMES NO FRAMES |