Proxy4J

Tagged:  

Proxy4J is a Java library for creating proxies. The project has recently released a stable snapshot (I'm not going to consider it "1.0" until the remoting is done). I originally created Proxy4J as a spin-off from my development on Workhorse, mainly because I wasn't really satisfied with other libraries out there that do proxying (the Commons Proxy library was the closest I could find, but its inability to leverage Java 5+ made it a non-starter).

Proxy4J was designed to allow you to quickly create a proxy for any one of a number of common use cases:

  • Virtual Proxies. Also known as delegation proxies, these proxies simply pass the method invocation directly to the "real subject", which may have some indirection in how it is created or fetched (e.g. the classic lazy-loading proxy).
  • Invocation Handlers. These are a direct parallel to proxies in the JDK, with a slight twist to include type safety in the common case where only one interface is being proxied. Method calls on these proxies are passed to an invocation handler which decides how to handle the call.
  • Interceptors. These are proxies where one or more interceptors may get called prior to invoking the method on the "real subject". In Proxy4J interceptors are very granular and may be specified on a per-method basis.

Interceptors in particular are pretty slick: they allow you to keep a stack of MethodInterceptors (note that the library supports the AOP Alliance API), which are invoked in order prior to invoking the intercepted method. Proxy4J allows different underlying implementations, including CGLIB, Javassist, and the built-in proxying in the JDK itself.

Documentation for Proxy4J can be found here. You can also download the jar here.

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <pre> <div> <blockquote> <object> <embed> <img> <param>
  • Lines and paragraphs break automatically.
  • Web page addresses and e-mail addresses turn into links automatically.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Copy the characters (respecting upper/lower case) from the image.