版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2026年延边职业技术学院单招职业适应性测试模拟试题及答案解析
- 中医理疗对慢性肺气肿的改善
- 心理创伤与康复护理
- 免疫第三章免疫器官
- 慢性疼痛管理方法探索
- 医疗机构成本控制与预算优化
- 医学伦理与法律法规研究进展
- 内分泌系统疾病护理与管理
- 2026北京房山区教育委员会所属事业单位招聘专业技术人员120人(一)备考笔试题库及答案解析
- 2025海南航空审计监察负责人岗位招聘1人备考笔试题库及答案解析
- 2025~2026学年上海市闵行区莘松中学八年级上学期期中语文试卷
- 医院拟就业协议书
- 2026届四川南充市高考一诊地理试卷试题(含答案详解)
- 2026年郑州澍青医学高等专科学校单招职业技能测试必刷测试卷带答案
- 2025年山东省烟台市辅警招聘公安基础知识考试题库及答案
- (一诊)达州市2026届高三第一次诊断性测试英语试题(含标准答案)
- 2025年贵阳市公安辅警招聘知识考试题库及答案
- 交管12123驾照学法减分题库500题(含答案解析)
- 金属补偿器培训
- 消防应急预案修订记录(3篇)
- (2026年)实施指南《JBT 13675-2019 筒式磨机 铸造衬板 技术条件》
评论
0/150
提交评论