Class ByteBuddyProxyFactory


  • public class ByteBuddyProxyFactory
    extends Object
    Produces switching proxy implementations which delegate invocation to one of two objects depending on the state of the specified Feature.

    Generated Code

    Assuming a user interface ...
     public interface UserDAO { User findById(int id); }
    ... proxyFor(org.togglz.core.Feature, java.lang.Class<? super T>, T, T) will generate classes equivalent to the following source code ...
     public class X extends TogglzSwitchable implements UserDAO {
       public X(FeatureManager featureManager, Feature feature, UserDAO active, UserDAO inactive) {
         super(featureManager, feature, active, inactive);
       }
       public User findById(int id) {
         super.checkTogglzState();
         return delegate.findById(id);
       }
       public String toString() {
         super.checkTogglzState();
         return delegate.toString();
       }
     } 

    Active and Passive mode

    In "active" proxies, Feature state is checked as part of every method call which is invisible but also quite slow. It may also be functionally dangerous if the implementations are stateful and should not flipped in the middle of a "session".

    For these cases passiveProxyFor(...) will generate classes that never check the feature state themselves. To be updated they must be passed to TogglzSwitchable.update(Object).

    Performance

    Following gives approximate invocation overhead of using a Feature-controlled proxy vs direct calls.
    Direct Call 100%
    Passive ByteBuddy Proxy 70%
    Active ByteBuddy Proxy 15%
    JDK Proxy 10%
    See Also:
    TogglzSwitchable