您的位置:首页 > 其它

设计技巧27:代理 Proxy 为另外一个对象提供替身或者站位符以控制对对象的访问

2013-10-16 17:33 302 查看
RMI:Remote Method Invocation 一般对象的调用是在同一个虚拟机的堆上,如果要在不同的虚拟机上调用对象就要利用RMI技术 Client  (RMI Stub)    (RMI Skeleton) Service对象 public interface MyRemote enxtends Remote{//继承自Remote接口,定义远程调用的方法 String sayHello() throws RemoteExcepion;} public class RemoteImpl implements MyRemote{//方法实现 public String sayHelle() throws RemoteExcetion( returen "hello";} public static void test(){ MyRemote service = new RemoteIml(); Naming.rebind("Say helle",service);//绑定} 执行rmic 产生Stub 和Skeleton 类执行 rmiregistry执行 java RemoteImpl 客户端 通过网络下载传入或者别的方式获取得到Stub类 public class test{public static void test(){MyRemote myRemote =(MyRemote) Naming.lookup("rmi:// ip"/名字)meRemote.sayHello();//远程方法调用  必须在启动服务前开启rmiregistry必须把参数和返回值做成可序列化的客户端必须要有Stub类
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐