Have you ever developed code that uses java.lang.reflect.Proxy
and thought:
"That CGLIB library sure is cool. I wish I could leverage both standard proxies and CGLIB proxies without changing my code".
With ProxyToys you can! ProxyToys is to proxy generation what Jakarta Commons Logging is to logging - an thin implementation neutral API for Proxy creation. Whether to use standard proxies or CGLIB is a one-line code change.
API Compatible proxy factory providers:
- Standard proxies of the JDK
- CGLIB implementation
ProxyToys provides a collection of toys acting as factories for creating "special" proxies such as:
- Decorators - for simple AOP-like chained method interception
- Delegates - for method invocation on a delegate object, that might have different type
- Dispatcher proxy - single proxy instance dispatching method calls to different object with separate types
- Echo proxy - for tracing method calls
- Failover objects - fails over to a next object in case of exception
- Future objects - execute method calls asynchronously
- Hot swapping proxy - allows implementation hiding that can be swapped, and mutual dependencies
- Multicasting objects - for multicasting a method invocation to multiple objects
- Null objects - for default implementations of classes that do nothing at all
- Pool - for a pool implementation with proxied objects that return automatically to the pool
- Privilege - execute method calls as privileged actions in a controlled environment
ProxyToys is a compact library. If you choose not to use the CGLIB features it requires no additional libraries.