ProxyģʽÒÔ¼°java¶¯Ì¬´úÀíʵÏÖ
Ò». Proxyģʽ¶¨Òå:
ΪÆäËû¶ÔÏóÌṩһÖÖ´úÀíÒÔ¿ØÖÆÕâ¸ö¶ÔÏóµÄ·ÃÎÊ.
¶þ.ģʽ½â˵
Proxy´úÀíģʽÊÇÒ»ÖֽṹÐÍÉè¼Æģʽ,Ö÷Òª½â¾öµÄÎÊÌâÊÇ:ÔÚÖ±½Ó·ÃÎʶÔÏóʱ´øÀ´µÄÎÊÌâ,±ÈÈç˵:Òª·ÃÎʵĶÔÏóÔÚÔ¶³ÌµÄ»úÆ÷ÉÏ.
ÔÚÃæÏò¶ÔÏóϵͳÖÐ,ÓÐЩ¶ÔÏóÓÉÓÚijЩÔÒò(±ÈÈç¶ÔÏó´´½¨¿ªÏúºÜ´ó,»òÕßijЩ²Ù×÷ÐèÒª°²È«¿ØÖÆ,»òÕßÐèÒª½ø³ÌÍâµÄ·ÃÎÊ),
Ö±½Ó·ÃÎÊ»á¸øʹÓÃÕß»òÕßϵͳ½á¹¹´øÀ´ºÜ¶àÂé·³,ÎÒÃÇ¿ÉÒÔÔÚ·ÃÎʴ˶ÔÏóʱ¼ÓÉÏÒ»¸ö¶Ô´Ë¶ÔÏóµÄ·ÃÎʲã,Õâ¸ö·ÃÎʲãÒ²½Ð´úÀí¡£
ProxyģʽÊÇ×î³£¼ûµÄģʽ,ÔÚÎÒÃÇÉú»îÖд¦´¦¿É¼û,±ÈÈçÏÖÔÚÓиöʲô¸ç,ÌرðµÄ»ð,µ«ÊÇÐÔ±ðÒ»°ãÈË¿´²»³öÀ´,ÄãÈ¥ÎÊ"Ëû",È˼ÒÊÇ
´óÍó,²»ºÍÄãÖ±½Ó¶Ô»°,Ö»Óо¼ÍÈ˳öÃæ,Õâ¸ö¾¼ÍÈ˾ͿÉÒÔ¿´³ÉËûµÄ´úÀí.
Èý.½á¹¹Í¼
´«Í³µÄ½á¹¹Í¼ÈçÏÂ:
java¶¯Ì¬´úÀí½á¹¹Í¼ÈçÏÂ:
ËÄ.ʵÏÖ:
public interface Person {
public void ownSex();
public String isBoolean(String str);
}
public class SpringBrother implements Person {
public void ownSex() {
System.out.println("Female!");
}
public String isBoolean(String str) {
return "yes!";
}
}
public class MyInvocationHandler implements InvocationHandler {
private Object proxied = null; //±»´úÀíµÄ¶ÔÏó.
public MyInvocationHandler(Object proxied){
this.proxied = proxied;
}
public Object invoke(Object proxy, Method method, Object[] args)
throws Throwable {
System.out.println("---------- proxy: ----------\n" + proxy.getClass()
+ "\nmethod: " + method + "\nargs: " + args);
Object oo = method.invoke(proxied, args);// ·ÃÎʵײ㷽·¨,ÕâÀïÊÇmain·½·¨ÖеÄownSex»òÕßisBoolean,·µ»Ø·µ»ØÖµ
if(args!=null && args.length!=0){
for(Object o : args){
System.out.println(o);
}
}
if(!(oo==null)){
System.out.println(oo);
}
return null;
}
public static void main(String[] args) {
Person person = (Person)Proxy.newProxyInstance(MyInvocationHandler.class.getClassLoader(),
new Class[]{Person.class}, new MyInvocationHandler(new SpringBrother()));
person.ownSex();
person.isBoolean("is Female!
Ïà¹ØÎĵµ£º
Ò»£º×¼±¸ www.savarese.org download
1. rocksaw-1.0.0-src.tar.gz
2. vserv-tcpip-0.9.2-src.tar.gz
¶þ£º±àÒëÔ´ÎļþµÃµ½jar°ü ʹÓÃAnt
1. build vserv-tcpip-0.9.2-src
ÔÚvserv-tcpip-0.9.2Ŀ¼ÏÂÃ潨һ¸ötestsĿ¼£¬È»ºóÔÚcmd´°¿ÚϽøÈë ......
ʹÓÃjinvokeµ÷ÓÃwindowsAPI¡£jnaʹÓñȽÏÂé·³£¬ÐèҪдc´úÂëºÍ²ÎÊýת»»£¬jinvokeµÄʹÓþÍÏñjdkÖеİüÒ»Ñù¡£
¹ÙÍøʹÓòο¼£ºhttp://www.jinvoke.com/calling-the-win32-api-from-java
Ò»¸öµ¯³ö¿òµÄÀý×Ó£¨ÕâÖÖ´úÂëÓÃÓÚµ÷ÓÃÈκÎdll£¬²»Ö»ÊÇwindowsµÄ£¬Ò²¿ÉÒÔÊÇ×Ô¼ºÐ´µÄdll£©
import com.jinvoke.JInvoke;
import com.jinvok ......
ÎÒÃǾ³£»áÓÃSystem.currentTimeMillis()ÔÚʼþ¿ªÊ¼Ç°ºÍ½áÊøºóÉèÖÃÒ»¸ö¿ªÊ¼Ê±¼äºÍ½áÊøʱ¼ä£¬ÓÃËûÃǵIJî×÷Ϊ³ÌÐòÖ´ÐеÄʱ¼ä¡£
ÎÒÃDz»·Á¶¨ÒåÒ»¸ö½Ó¿ÚÓÃjava»Øµ÷À´ÊµÏÖ¶¯Ì¬¼ÆËã¡£
½Ó¿Ú¶¨Ò壺
package com.hd123.h5.ejb.verctrl;
public interface CallBack {
public void callBack();
}
È»ºóÊÇʵÏÖÕâ¸ö½Ó¿Ú
pac ......
ʹÓÃJava±àдTelnet¿Í»§¶Ë
2009-12-24
Kagula
»·¾³
[1]Eclipse3.4.2
[2]JDK 1.6.x
[3] jta26.jar
¿É´ÓÏÂÃæÍøÖ·ÏÂÔØÕâ¸öJar°ü
http://javassh.org/space/start
¸ÅÒª
ͨ¹ýÁ½¸öÀý×Ó£¬½éÉÜTelnet¿Í»§¶ËµÄ±àд
ÕýÎÄ
Àý×ÓÒ»£ºÏòOPhoneÐéÄâ»ú·¢ËÍÒ ......