输入资料的关键词,譬如"雅思":   热门关键词
热门搜索:2010 司法考试 MP3 注册会计师 考研 考研英语 万国 公务员 司法考试 众合

投递新闻 您所在的位置:鲤鱼首页 >全国计算机等级考试NCRE新闻 >Simple-levelDynamicProxy(2)

Simple-levelDynamicProxy(2)

时间:2009-11-08    来源:网络综合     (精品全国计算机等级考试NCRE资料,点击即可下)

您知道吗?鲤鱼网被评为2009年度互联网考生最喜欢网站。


【网络综合 - 全国计算机等级考试(NCRE)指南】:
/**
  *
  */
  package poxy;
  import java.lang.reflect.InvocationHandler;
  import java.lang.reflect.InvocationTargetException;
  import java.lang.reflect.Method;
  import java.lang.reflect.Proxy;
  import java.util.*;
  import callback.PrimitiveUtil;
  /**
  * More industrial-level dynamic proxy , which main detach the Invocation handler and the real instance of a proxy class,
  * which can store many proxy handler with them listener, this is very useful.
  * Mean while, it also can work in multi thread env, so you can use it with Thread pool and Scheduler!
  **
  */
  public class IndustrialDynamicProxy {
  /*
  * container of iface & his InvocationHandler
  * Note: work in multithread env
  */
  private Map _iface2Handler = new HashMap();
  /*
  * Generates the ’caller’ side of the caller/listener relationship.
  */
  public Object generateCaller(Class iFace, CallBackType type) {
  CallBackHanlder newHandler;
  Object proxy=null;
  //check iface
  if(!iFace.isInterface()){
  throw new IllegalArgumentException("Class [" + iFace.getName() + "] is not an interface");
  }
  //generate a new handler
  newHandler = new CallBackHanlder(type);
  //generate the face’s proxy
  proxy = Proxy.newProxyInstance(iFace.getClassLoader(),
  new Class[] { iFace },
  newHandler);
  //register iface & proxy
  synchronized(_iface2Handler){
  if(_iface2Handler.containsKey(iFace)){
  throw new IllegalArgumentException("Caller already generated " + " for interface [" +iFace.getName() + "]");
  }
  _iface2Handler.put(iFace, newHandler);
  }
  return proxy;
  }


第一页 1 最后一页

Copyright©2009 iliyu.com All Rights Reserved 鲤鱼网

&bnsp;
s