org.neo4j.kernel.ha
Class DelegateInvocationHandler<T>

java.lang.Object
  extended by org.neo4j.kernel.ha.DelegateInvocationHandler<T>
All Implemented Interfaces:
InvocationHandler

public class DelegateInvocationHandler<T>
extends Object
implements InvocationHandler

InvocationHandler for dynamic proxies that delegate calls to a given backing implementation. This is mostly used to present a single object to others, while being able to switch implementation at runtime. There are concepts of snapshot(Object) and #cement(Object) in here, which serves different purposes:

  1. snapshot(Object): acquire the actual delegate at this particular point in time, pulling it out from the proxy and using it directly. This is used for acquiring a snapshot and keep using that particular instance, even if a new delegate is assigned for this handler.
  2. #cement(Object): acquire a proxy that will have its delegate assigned the next call to setDelegate(Object). This is useful if one DelegateInvocationHandler depends on another which will have its delegate set later than this one.


Constructor Summary
DelegateInvocationHandler(Class<T> interfaceClass)
           
 
Method Summary
 T cement()
          Cements this delegate, i.e.
 void harden()
          Updates cemented delegates with the current delegate, making it concrete.
 Object invoke(Object proxy, Method method, Object[] args)
           
 void setDelegate(T delegate)
          Updates the delegate for this handler, also hardens instances cemented from the last call to setDelegate(Object).
static
<T> T
snapshot(T proxiedInstance)
          Takes a snapshot of the current delegate and returns that.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DelegateInvocationHandler

public DelegateInvocationHandler(Class<T> interfaceClass)
Method Detail

setDelegate

public void setDelegate(T delegate)
Updates the delegate for this handler, also hardens instances cemented from the last call to setDelegate(Object). This call will also dereference the Concrete, such that future calls to harden() cannot affect any reference received from cement() prior to this call.

Parameters:
delegate - the new delegate to set.

harden

public void harden()
Updates cemented delegates with the current delegate, making it concrete. Callers of #cement(Object) in between this call and the previous call to setDelegate(Object) will see the current delegate.


invoke

public Object invoke(Object proxy,
                     Method method,
                     Object[] args)
              throws Throwable
Specified by:
invoke in interface InvocationHandler
Throws:
Throwable

cement

public T cement()
Cements this delegate, i.e. returns an instance which will have its delegate assigned and hardened later on so that it never will change after that point.


snapshot

public static <T> T snapshot(T proxiedInstance)
Takes a snapshot of the current delegate and returns that.


toString

public String toString()
Overrides:
toString in class Object


Copyright © 2002-2014 The Neo4j Graph Database Project. All Rights Reserved.