版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、1) arith. java public interface arith extends java.rmi.remote int add(int a, int b) throws java.rmi.remoteexception;2) arith工mpljavapublic class arithlmpl extends unicastremoteobject implements arith private string objectname;public arithlmpl(string s) throws remoteexception super();objectname = s;p
2、ublic int add(int a , int b )int c = new int10;for (int i = 0; i < 10; i+)ci = ai + bi;return c;public static void main(string args)rmisecuritymanager sm=new rmisecuritymanager();system.setsecuritymanager(sm);tryarithlmpl obj=new arithlmpl(narithservern);/locateregistry.createregistry(3000);namin
3、g. rebind (arithappjava public class arithapp public static void main(string args) int a=l,2,3,4,5,6,7,8,9,10; int b=l,2,3,4,5,6,7,8,9,10;int resunew int10; tryarith obj=(arith)naminglookup(hrmi:/127.0.0.1:1099/arithserverh); result=obj.add(a, b);catch(exception e)systemout.printin(narithappn+e.getm
4、essage();e.printstacktrace ();system, out .print ( "the sum=11); for(int i=0;i<resultlength;i+)system. out .print (result i + ”f,); system.outprintin (); rmi : /127.0.0.1:1099/arithserver n, ob j);systemout.printin(narithserver bound in registryh;catch(exception e)system out .print in ("
5、;arithlmpl. error: n+e .getmessage ();e.printstacktrace ();1) city2java public interface city2 extends remote int getpopulation() throws remoteexception;int gettemperature() throws remoteexception;2 ) cityfautory j avapublic interface cityfactory extends remotecity2impl getcityserver(string cityname
6、) throws remoteexception;3) city2工mpljavapublic class city2impl extends unicastremoteobject implements city2 private string cityname;publie city2impl() throws remoteexceptionsuper ();publie city2impl(string cityname) throws remoteexceptionsuper ();thiscityname=cityname;public int getpopulation() thr
7、ows remoteexceptionif(cityname.equals(ntorontoh) return 10;else if (cityname .equals (,ottawan) ) return 2;elsereturn 0;public int gettemperature() throws remoteexceptionreturn 1;5) city2app.javapublic class city2app public static void main(string args) remote obj=null;city2 ottawa=null;city2 toront
8、o=null;int ottawapopulation=0;int torontopopulation=0;t rynaming.lookup(n rmi:/1270.0.1:109 9/cityfactory h;catch(exception e)e.printstacktrace();tryottawa=new cityfactorylmpl () . getcityserver (l,ottawan); toronto=new cityfactorylmpl() .getcityserver(htoronto n);catch(remoteexception e)eprintstauk
9、trace();tryo11 awap opulation=ott awa.getpopulation(); torontopopulation=torontogetpopulation ();catch(remoteexception e)e.printstacktrace ();system. out. print in (11 the population of ottawais:n+ottawapopulation);system.out.printin("the population of torontois:n +torontopopulat ion);/1) callb
10、ack.javapublic interface callback void tempchanged(string cityname, int temp);2) callcityjavapublic interface callcity extends remoteint getpopulation(string cityname) throws remoteexception;int gettemperature(string cityname) throws remoteexception; void register(callback cb) throws remoteexception
11、;3) callcitytmpljavapublic class callcityimpl extends unicastremoteobject implements callcity vector list=new vector ();private string name;public callcityimpl(string name) throws remoteexceptionsuper ();this name=name;public int getpopulation(string cityname) throws remoteexception if (cityname equ
12、als (ntoronto11) ) return 10;jelse if (cityname .equals (f,ottawa”) return 2;elsereturn 0;public int gettemperature(string cityname) throws remoteexception return 1;public void register(callback cb)listaddelement(cb);public static void main(string args) system.setsecuritymanager(new rmisecuritymanag
13、er(); t rycallcitylmpl ob j=new callcitylmpl (l,callcityimpln);naming. rebind (n rmi : /127 0 0 1:1099/callcityimpln , ob j); system. out. print in (11 cityserver bo und in registry!11);catch(exception e) e.printstacktrace();4) callcityappj avapublic class callcityapp implements callback,serializabl
14、epublic static void main(string args) int pop = 0;try callcity obj = (callcity)naming. lookup (11 rmi: /127.0.0.1:1099/callcityimpln);pop = obj . getpopulation (ntoronto11); catch (exception e) eprintstauktrace();system.out.printin("the population of toronto is:n + pop);public void tempchanged(
15、string cityname, int temp)system out.printin(ndynamic update:n);system.out.printin("cityname:n+cityname);system.out.printin(n temp:n+temp);5) callcity2工mpljavapublic class callcity2lmpl extends unicastremoteobject implements callcityvector list=new vector();private string name;public callcity2i
16、mpl(string name) throws remoteexception super (); thisname=name;public int getpopulation(string cityname) throws remoteexception if(cityname.equals("toronto")return 10;else if (cityname .equals (,ottawan) ) return 2;else return 0;public int gettemperature(string cityname) throws remoteexce
17、ption return 1;public void register(callback cb)listaddelement(cb);public static void main(string args)system setsecuritymanager(new rmisecuritymanager();trycallcitylmpl ob j=new callcitylmpl (l,callcityimpln); naming. rebind (n rmi : /127 0 0 1:1099/callcityimpln , ob j); system.outprintin(”callcit
18、ylmpl. bound in registry!h);catch(exception e)e.printstacktrace();public void settemp(string cityname,int tmp)for(int i=0;i<listsize();i+)callback cb=(callback)listelementat (i);cbtempchanged(cityname, tmp);6) callcity2appjavapublic class callcity2app implements callback!public static void main(s
19、tring args)int pop=0;callback c=(callback) new callcityapp();callcity obj=null;tryobj=(callcity)naming.lookup(n rmi:/127.0.0.1:1099/callcityhmpu1); pop=ob j . getpopulation (htoronto11);catch(exception e)system.out.print "("arithapp exception:n+e.getmessage(); e.printstacktrace();tryobjregister(c);catch(remoteexception e) system .ou匕.println ("error11); e.printstacktrace();system.out.println(nthe population of toronto is:n + pop);public void tempchanged(string cityname, int temp)system.outprintin(ndynamic update:n)fsystem.outprintln
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 济南版小学四年级安全教育教案
- 小学足球教案全套-足球的教案
- 上海个人租房合同-火车站附近
- 临时用电安全协议书
- 乳制品冷藏保鲜合同
- 仓储物流联合经营合同
- 临时租赁设施租赁买卖协议
- 个人续租合同度假别墅
- 企业贷款合同模板玻璃行业
- 代理商合作协议模板
- 江西省萍乡市2024-2025学年高二上学期期中考试地理试题
- 2023年贵州黔东南州州直机关遴选公务员考试真题
- 4S店展厅改造装修合同
- 送货简易合同范本(2篇)
- 全国职业院校技能大赛赛项规程(高职)智能财税
- 七年级上册音乐教案 人音版
- 某小区住宅楼工程施工组织设计方案
- 3-4单元测试-2024-2025学年统编版语文六年级上册
- 北师版数学八年级上册 5.8三元一次方程组课件
- 2025届湖北省武汉市新洲一中阳逻校区高二上数学期末学业水平测试模拟试题含解析
- 眼镜验光员(高级)技能鉴定考试题及答案
评论
0/150
提交评论