Package org.togglz.core.proxy
Class ByteBuddyProxyFactory
java.lang.Object
org.togglz.core.proxy.ByteBuddyProxyFactory
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 TogglzSwitchableimplements 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 aFeature-controlled proxy vs direct calls.
| Direct Call | 100% |
| Passive ByteBuddy Proxy | 70% |
| Active ByteBuddy Proxy | 15% |
| JDK Proxy | 10% |
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <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> TGenerate an activeFeatureproxy.static <T> TproxyFor(Feature feature, Class<? super T> interfaceClass, T active, T inactive, FeatureManager featureManager) Generate an activeFeatureproxy.
-
Constructor Details
-
ByteBuddyProxyFactory
public ByteBuddyProxyFactory()
-
-
Method Details
-
passiveProxyFor
public static <T> T passiveProxyFor(Feature feature, Class<? super T> interfaceClass, T active, T inactive) Generate a passiveFeatureproxy.- See Also:
-
passiveProxyFor
public static <T> T passiveProxyFor(Feature feature, Class<? super T> interfaceClass, T active, T inactive, FeatureManager featureManager) Generate a passiveFeatureproxy.- See Also:
-
proxyFor
public static <T> T proxyFor(Feature feature, Class<? super T> interfaceClass, T active, T inactive) Generate an activeFeatureproxy.- See Also:
-
proxyFor
public static <T> T proxyFor(Feature feature, Class<? super T> interfaceClass, T active, T inactive, FeatureManager featureManager) Generate an activeFeatureproxy.- See Also:
-