Java類動態代理框架 Smartproxy

fmms 12年前發布 | 29K 次閱讀 Java Java開發

Smartproxy 是一個 Java 的動態類和實例代理框架,類似 java.lang.reflect.Proxy 類所作的工作,但無需調用 InvocationHandler 接口。Smartproxy 通過底層對象提供對抽象類方法的重載。Smartproxy 使用 BCEL 類庫。

  • Easy to use since there is not need to code an invocation handler, only the methods to be changed in the proxy.
  • Fast to execute since the smartproxy generated classes actually inherit from the abstract class and actually implement (in byte code) the delegation calls to the underlying object. As a result a proxy class generated by smartproxy is roughly equivalent to the same hand coded class while the jlrP generated classes are way slower (on a first test about 100 time slower on my machine).

示例代碼:

// Create the proxy factory for the set on interface/implementor.

ProxyFactory factory = ProxyFactory.getInstance(SimpleImplementor.class, SimpleInterface.class);

// Creates an underlying object.

SimpleInterface base = new SimpleBaseClass();

// Proxify the underlying object.

SimpleInterface proxified = (SimpleInterface) factory.createProxy(new Object[] { base });

項目主頁:http://www.baiduhome.net/lib/view/home/1326987539608

 本文由用戶 fmms 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!