Package org.togglz.core.proxy
Class ByteBuddyProxyFactory
- java.lang.Object
-
- org.togglz.core.proxy.ByteBuddyProxyFactory
-
public class ByteBuddyProxyFactory extends Object
Produces switching proxy implementations which delegate invocation to one of two objects depending on the state of the specifiedFeature.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,Featurestate 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 toTogglzSwitchable.update(Object).Performance
Following gives approximate invocation overhead of using aFeature-controlled proxy vs direct calls.Direct Call 100% Passive ByteBuddy Proxy 70% Active ByteBuddy Proxy 15% JDK Proxy 10% - See Also:
TogglzSwitchable
-
-
Constructor Summary
Constructors Constructor Description ByteBuddyProxyFactory()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> TpassiveProxyFor(Feature feature, Class<? super T> interfaceClass, T active, T inactive)Generate a passiveFeatureproxy.static <T> TpassiveProxyFor(Feature feature, Class<? super T> interfaceClass, T active, T inactive, FeatureManager featureManager)Generate a passiveFeatureproxy.static <T> TproxyFor(Feature feature, Class<? super T> interfaceClass, T active, T inactive)Generate an activeFeatureproxy.static <T> TproxyFor(Feature feature, Class<? super T> interfaceClass, T active, T inactive, FeatureManager featureManager)Generate an activeFeatureproxy.
-
-
-
Method Detail
-
passiveProxyFor
public static <T> T passiveProxyFor(Feature feature, Class<? super T> interfaceClass, T active, T inactive)
Generate a passiveFeatureproxy.- See Also:
ByteBuddyProxyFactory
-
passiveProxyFor
public static <T> T passiveProxyFor(Feature feature, Class<? super T> interfaceClass, T active, T inactive, FeatureManager featureManager)
Generate a passiveFeatureproxy.- See Also:
ByteBuddyProxyFactory
-
proxyFor
public static <T> T proxyFor(Feature feature, Class<? super T> interfaceClass, T active, T inactive)
Generate an activeFeatureproxy.- See Also:
ByteBuddyProxyFactory
-
proxyFor
public static <T> T proxyFor(Feature feature, Class<? super T> interfaceClass, T active, T inactive, FeatureManager featureManager)
Generate an activeFeatureproxy.- See Also:
ByteBuddyProxyFactory
-
-