




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、福州大学数学(shxu)与计算机科学学院上机实验报告专业和班级信息数学02班姓名詹小青成绩课程名称分布计算实验名称使用RMI实现Agent实验目的和要求 1、实验目的: (1)学习派生类的定义和使用; (2)理解派生类对基类成员的访问权 (3)理解派生类的构造函数与析构函数的定义与执行过程; (4)学习多继承类的定义和使用 2、实验要求: (1)定义一个派生类,并且创建该类的对象。 (2)体现出派生类构造函数与析构函数的调用。 (3)理解派生类的构造函数与析构函数的运行顺序。 (4)定义一个多继承的派生类,并且创建该类的对象。 实验内容和步骤1.实验内容:任务1. 根据agent示例目录中re
2、adme文件的说明,运行图8.8到8.12所描述的移动agent演示。描述并解释结果。任务2. 考虑下面所列的应用。描述怎样才能将这些范型(消息队列系统,移动agent和对象空间)应用到这些应用系统中。注意,本题不要求提供具体实现。你的描述应根据范型来分段,而不是根据特定的API。考虑的应用是:a. 监视通过运输工具运输到仓库和商店的货物b. 聊天室c. 在线拍卖d. 使你所在的大学向学生提供课程信息的服务。信息不断更新。2.实验基本步骤:(1)程序:AgentInterface程序:/ An interface for a transportable object /reprsenting
3、a mobile agentimport java.io.Serializable;public interface AgentInterface extends Serializable void execute(); Agent程序: /An implementation of a mobile agent import java.io.*; import java.util.*; import java.rmi.*; import java.rmi.registry.Registry; import java.rmi.registry.LocateRegistry; public cla
4、ss Agent implements AgentInterface int hostIndex; /which host to vist next String name;Vector hostList; /the itineararyint RMIPort=12345; public Agent(String myName,Vector theHostList,int theRMIPort) name=myName; hostList=theHostList; hostIndex=0; RMIPort=theRMIPort;/This method defines the tasks th
5、at the mobile agent is to perform once it has arrived at a server. public void execute() String thisHost,nextHost; sleep(2); /delay for visibility System.out.println(007 here!); thisHost=(String) hostList.elementAt(hostIndex); hostIndex+; if (hostIndexhostList.size() /if there is another host to vis
6、it nextHost=(String) hostList.elementAt(hostIndex); sleep(5); /delay for visibility try / Locate the RMI registry on the next host Registry registry=LocateRegistry.getRegistry(localhost,RMIPort); ServerInterface h=(ServerInterface) registry.lookup(nextHost); System.out.println(Lookup for +nextHost+
7、at +thisHost+ completed ); sleep(5); /Ask the server at the next host to receive this agent h.receive(this); /end try catch (Exception e) System.out.println(Exception in Agent execute: +e); /end if else /if all the stops have been made sleep(5); /delay for visibility System.out.println(Agent 007 has
8、 come home); sleep(5); /delay for 5 visibility / Method sleep suspends this objects execution for the specified number of seconds.static void sleep(double time) try Thread.sleep(long)(time*1000.0); catch (InterruptedException e) System.out.println(sleep exception); /end sleep /end class AgentServerI
9、nterface程序:/ An interface for a transportable object/ representing a mobile agent./M. Liuimport java.io.Serializable;public interface ServerInterface extends Serializable public void receive(Agent h) ;Server程序: import java.io.*;import .*;import java.rmi.*;import java.rmi.server.*;import java.rmi.reg
10、istry.Registry;import java.rmi.registry.LocateRegistry;public class Server static int RMIPort = 12345; String myName; public Server() throws RemoteException super(); public void receive(Agent h)throws RemoteException sleep(3); myName = ; System.out.println(Agent ++ arrived.); h.execute()
11、; public static void main(String args) InputStreamReader is = new InputStreamReader(System.in); BufferedReader br = new BufferedReader(is); try System.setSecurityManager(new RMISecurityManager(); Server h = new Server(); Registry registry = LocateRegistry.getRegistry(RMIPort); registry.rebind(myName
12、, registry); System.out.println(Agent +myName+ready.); catch(RemoteException e) System.out.println(Exception occured in AgentServer.main: +e); private static void sleep(int time) try Thread.sleep(time*1000); catch(InterruptedException e) System.out.println(sleep exception.); Client程序:/Client.java -c
13、lient program for lauching the mobile agent/M. Liu import java.io.*; import java.util.*; import java.rmi.*; import java.rmi.registry.Registry; import java.rmi.registry.LocateRegistry; public class Client static int RMIPort=12345; public static void main(String args) System.setSecurityManager(new RMI
14、SecurityManager(); try Registry registry=LocateRegistry.getRegistry(localhost,RMIPort); ServerInterface h=(ServerInterface) registry.lookup(server1); System.out.println(Lookup for server1 completed ); System.out.println(*Have a good trip,+ agent 007.); Vector hostList=new Vector(); hostList.addEleme
15、nt(server1); hostList.addElement(server2); hostList.addElement(server3); Agent a=new Agent(007,hostList,RMIPort); h.receive(a); System.out.println(*Nice job,agent 007); catch (Exception e) System.out.println(Exception in main:+e); /end main / end class(2)实验结果截图:研究与探讨考虑下面所列的应用。描述怎样才能将消息队列系统,移动agent和对象空间这些范型应用到这些应用系统中。考虑的应用是:a. 监视通过运输工具运输到仓库和商店的货物b. 聊天室c. 在线拍卖d. 使你所在的大学向学生提供课程信息的服务。信息不断更新。答:(1)监视通过运输工具运输到仓库和商店的货物。用消息队列系统实现
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 乙方赔偿合同标准文本
- 万科物业写字楼合同样本
- 个人销售用工合同样本
- 出国委托合同样本
- 冷物流运输合同样本
- 出售化肥合同样本
- gf合同标准文本编码规定
- 农场抵押合同标准文本
- 个人债务担保合同范例
- 出口退税采购合同样本
- 2024年黑龙江省齐齐哈尔市中考语文试卷附真题答案
- 中华护理学会成人肠内营养支持护理团标解读
- 地理加权回归分析技术综述
- 自然辩证法智慧树知到期末考试答案章节答案2024年浙江大学
- 特种设备检验申请单
- 养老院新员工安全培训
- 马渭丽《月光下的中国》
- AQ-T 1009-2021矿山救护队标准化考核规范
- DLT 5175-2021 火力发电厂热工开关量和模拟量控制系统设计规程-PDF解密
- Q-GDW 11711-2017 电网运行风险预警管控工作规范
- DB21-T 2808-2017郁金香种球扩繁技术规程
评论
0/150
提交评论