书签 分享 收藏 举报 版权申诉 / 32
上传文档赚钱

类型分布式计算原理与应用(Distributed-Computing)第八章课件.ppt

  • 上传人(卖家):晟晟文业
  • 文档编号:4574741
  • 上传时间:2022-12-20
  • 格式:PPT
  • 页数:32
  • 大小:300.50KB
  • 【下载声明】
    1. 本站全部试题类文档,若标题没写含答案,则无答案;标题注明含答案的文档,主观题也可能无答案。请谨慎下单,一旦售出,不予退换。
    2. 本站全部PPT文档均不含视频和音频,PPT中出现的音频或视频标识(或文字)仅表示流程,实际无音频或视频文件。请谨慎下单,一旦售出,不予退换。
    3. 本页资料《分布式计算原理与应用(Distributed-Computing)第八章课件.ppt》由用户(晟晟文业)主动上传,其收益全归该用户。163文库仅提供信息存储空间,仅对该用户上传内容的表现方式做保护处理,对上传内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知163文库(点击联系客服),我们立即给予删除!
    4. 请根据预览情况,自愿下载本文。本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
    5. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007及以上版本和PDF阅读器,压缩文件请下载最新的WinRAR软件解压。
    配套讲稿:

    如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。

    特殊限制:

    部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。

    关 键  词:
    分布式 计算 原理 应用 Distributed Computing 第八 课件
    资源描述:

    1、12/20/2022Distributed Computing,M.L.Liu1Advanced Remote Method InvocationsM.L.Liu12/20/2022Distributed Computing,M.L.Liu2RMI Advanced topicsnThe Java RMI API has a rich collection of features.nWe will look at some of RMIs more interesting advanced features,namely:n stub downloadingnsecurity managern

    2、client callback.nAlthough these features are not inherent to the distributed object paradigm,they are helpful mechanisms and can be useful to application developers.12/20/2022Distributed Computing,M.L.Liu3The Java RMI ArchitectureC lientServerstubrem ote reference layertransport layerskeletonrem ote

    3、 reference layertransport layerl;ogical data pathphysical data pathsupports the interface withthe application programm aps the platform-independent stub/skeletonlayer to the platform-dependent transportlayer;carries out rem ote reference protocolssets up,m aintains,and shuts downconnections;and carr

    4、ies out thetransport protocol12/20/2022Distributed Computing,M.L.Liu4Java RMI Client Server InteractionClient hostServer hostRMI registrySomeServer.classSomeInterface_stub.classSomeInterface_skel.classClient.classSomeInterface_stub.class12341.Client looks up the interface object in the RMIregistry o

    5、n the server host.2.The RMIRegistry returns a remote reference to the interface object.3.If the interface objects stub is not on the client host and if it is so arranged by the server,the stub is downloaded from an HTTP server.4.Via the server stub,the client process interacts with the skeleton of t

    6、he interface object to access the methods in the server object.HTTP hostX12/20/2022Distributed Computing,M.L.Liu5RMI Stub DownloadingnRMI is designed to allow stubs to be made available to the client dynamically.Doing so allows changes to be made in the remote methods without affecting the client pr

    7、ogram.nThe stub can be filed with an web server and be downloaded using HTTP.nSecurity measures are needed to prevent both the client side and the server side:nA java security policy file needs to be set on the server host and also on the client host.nA Java Security Manager should be instantiated i

    8、n both the client and server programs.12/20/2022Distributed Computing,M.L.Liu6Stub downloadingnIf the stub is to be downloaded from a remote server,transfer the stub class to the appropriate directory on that server,e.g.,www.csc.calpoly.edu/mliu/www,and make sure that the access permission to the fi

    9、le is set.nWhen activating the server,specify command options:java -Djava.rmi.serve.codebase=/-Djava.rmi.server.hostname=-Djava.security.policy=where is the URL for the stub class,e.g.,http:/www.csc.calpoly.edu/mliu/class is the name of the host on which the server runs,and specifies where the secur

    10、ity policy file for this application is to be found,e.g.,java.security if you have a file by that name in the directory where the server class is.12/20/2022Distributed Computing,M.L.Liu7The java.policy filenThe RMI security manager does not permit network access.The RMI security manager does not per

    11、mit network access.Exceptions can be made via the specification in a java.policy file.Exceptions can be made via the specification in a java.policy file.grant grant /permits socket access to all common TCP ports,including the /permits socket access to all common TCP ports,including the defaultdefaul

    12、t /RMI registry port(1099)need for both the client and the /RMI registry port(1099)need for both the client and the server.server.permission .SocketPermission permission .SocketPermission *:1024-65535,:1024-65535,connect,accept,resolve;connect,accept,resolve;/permits socket access to port 80,the def

    13、ault HTTP port /permits socket access to port 80,the default HTTP port neededneeded /by client to contact an HTTP server for stub downloading /by client to contact an HTTP server for stub downloading permission .SocketPermission permission .SocketPermission *:80,connect;:80,connect;nThis file can be

    14、 filed in the same directory as the server class file.This file can be filed in the same directory as the server class file.nWhen activiating When activiating the client,a java.policy file also should be the client,a java.policy file also should be specified:specified:java-Djava.security.policy=java

    15、.policy SomeClient java-Djava.security.policy=java.policy SomeClientnSee See http:/ and and http:/ Computing,M.L.Liu8File Placementsjava.policySomeClient.classjava.polcySomeServer.classSomeInterface_stub.classSomeInterface.Skeleton.classSomeInterface_stub.classClient hostclient directoryServer hosts

    16、erver directoryHTTP Server12/20/2022Distributed Computing,M.L.Liu9RMI Security ManagernSince RMI involves access to/from a foreign host,and possibly object downloading,it is important for both the server and the client to protect its system from malicious access.nThe RMISecurityManager is a class pr

    17、ovided Java,and can be instantiated in both the client and the server for limiting access priviledges.nYou can write your own security manager,if so desired.try System.setSecurityManager(new RMISecurityManager();catch 12/20/2022Distributed Computing,M.L.Liu10Algorithm for building an RMI Application

    18、Server side:1.Open a directory for all the files to be generated for this application.2.Specify the remote-server interface,and compile it to generate the interface class file.3.Build the remote server class by implementing the interface,and compile it using javac.4.Use rmic to process the server cl

    19、ass to generate a stub.class file and a skelton.class file:rmic SomeServer5.If stub downloading is desired,copy the stub file to an appropriate directory on the HTTP host.6.Activate the RMIRegistry,if it has not already been activated.7.Set up a java.policy file.8.Activate the server,specifying(i)th

    20、e codebase if stub downloading is desired,(ii)the server host name,and(iii)the security policy file.12/20/2022Distributed Computing,M.L.Liu11Alogorithm for building an RMI ApplicationClient side:1.Open a directory for all the files to be generated for this application.2.Implement the client program

    21、or applet,and compile it to generate the client class.3.If stub downloading is not in effect,copy the server interface stub class file by hand.4.Set up a java.policy file.5.Activate the client,specifying(i)the server host name,and(ii)the security policy file.12/20/2022Distributed Computing,M.L.Liu12

    22、RMI Callbacks12/20/2022Distributed Computing,M.L.Liu13IntroductionnIn the client server model,the server is passive:the IPC is initiated by the client;the server waits for the arrival of requests and provides responses.nSome applications require the server to initiate communication upon certain even

    23、ts.Examples applications are:n monitoringn gamesn auctioningn voting/pollingn chat-toomn message/bulletin boardn groupware12/20/2022Distributed Computing,M.L.Liu14Polling vs.CallbackIn the absence of callback,a client will have to poll a passive server repeatedly if it needs to be notified that an e

    24、vent has occurred at the server end.ServerClient.PollingServerClientCallbackA client issues a request to theserver repeatedly until thedesired response is obtained.A client registers itself with theserver,and wait until the servercalls back.a remote method call12/20/2022Distributed Computing,M.L.Liu

    25、15Two-way communicationsnSome applications require that both sides may initiate IPC.nUsing sockets,duplex communication can be achieved by using two sockets on either side.nWith connection-oriented sockets,each side acts as both a client and a server.requestresponserequestresponseProcess 1Process 11

    26、2/20/2022Distributed Computing,M.L.Liu16RMI CallbacksnA callback client registers itself with an RMI server.nThe server makes a callback to each registered client upon the occurrence of a certain event.The callback listC1C2C3C4C5callbackServerClientsRMI calls12/20/2022Distributed Computing,M.L.Liu17

    27、Callback Client-Server InteractionsClient hostServer hostRMI registrySomeServer.classSomeInterface_stub.classSomeInterface_skel.classClient.class121.Client looks up the interface object in the RMIregistry on the server host.2.The RMIRegistry returns a remote reference to the interface object.3.Via t

    28、he server stub,the client process invokes a remote method to register itself for callback,passing a remote reference to itself to the server.The server saves the reference in its callback list.4.Via the server stub,the client process interacts with the skeleton of the interface object to access the

    29、methods in the interface object.5.When the anticipated event takes place,the server makes a callback to each registered client via the callback interface stub on the server side and the callback interface skeleton on the client side.XCallbackInterface_skel.classCallbackInterface_stub.class53,412/20/

    30、2022Distributed Computing,M.L.Liu18Callback application filesClient.classClientInterface.classServerInterface.classClientImpl.classServerImpl_Stub.classClientImpl_skel.classObject client hostobject client directoryServer.classServerInterface.classClientInterface.classServerImpl.classClientImpl_Stub.

    31、classServerImpl_skel.classObject server hostobject server directory12/20/2022Distributed Computing,M.L.Liu19RMI Callback file placementsjava.policySomeClient.classjava.polcySomeServer.classSomeInterface_stub.classSomeInterface.Skeleton.classSomeInterface_stub.classClient hostclient directoryServer h

    32、ostserver directoryHTTP ServerCallbackInterface_stub.classCallbackInterface_skel.class12/20/2022Distributed Computing,M.L.Liu20The Hello Application with CallbacksayHello()HelloInterfaceUnicastRemoteObjectHelloImplHelloServerlistRegistry()startRegistry()serverregistryclientrebind()lookup()sayHello()

    33、sequence diagramUML diagramnotifyMe()CallbackClientInterfaceUnicastRemoteObjectC allbackC lientm plC allbackC lientaddCallback()notifyMe()12/20/2022Distributed Computing,M.L.Liu21RMI Callback InterfacenThe server provides a remote method which allows a client to register itself for callbacks.nA Remo

    34、te interface for the callback is needed,in addition to the server-side interface.nThe interface specifies a method for accepting a callback from the server.nThe client program is a subclass of RemoteObject and implements the callback interface,including the callback method.nThe client registers itse

    35、lf for callback in its main method.nThe server invokes the clients remote method upon the occurrence of the anticipated event.12/20/2022Distributed Computing,M.L.Liu22Remote Interface for Serverpublic interface HelloInterface extends Remote /remote method public String sayHello()throws java.rmi.Remo

    36、teException;/method to be invoked by a client to add itself to the callback list public void addCallback(HelloCallbackInterface CallbackObject)throws java.rmi.RemoteException;12/20/2022Distributed Computing,M.L.Liu23Remote Interface for Callback Client/an interface specifying a callback methodpublic

    37、 interface HelloCallbackInterface extends java.rmi.Remote /method to be called by the server on callback public void callMe(String message )throws java.rmi.RemoteException;12/20/2022Distributed Computing,M.L.Liu24HelloServer,with callbackpublic class HelloServer extends UnicastRemoteObject implement

    38、s HelloInterface static int RMIPort;/vector for store list of callback objects private static Vector callbackObjects;public HelloServer()throws RemoteException super();/instantiate a Vector object for storing callback objects callbackObjects=new Vector();/method for client to call to add itself to i

    39、ts callback public void addCallback(HelloCallbackInterface CallbackObject)/store the callback object into the vector System.out.println(Server got an addCallback call.);callbackObjects.addElement(CallbackObject);12/20/2022Distributed Computing,M.L.Liu25 HelloServer,with callback-2public static void

    40、main(String args)registry=LocateRegistry.createRegistry(RMIPort);callback();/end main private static void callback()for(int i=0;i callbackObjects.size();i+)System.out.println(Now performing the+i+th callbackn);/convert the vector object to a callback object HelloCallbackInterface client=(HelloCallba

    41、ckInterface)callbackObjects.elementAt(i);client.callMe(Server calling back to client +i);12/20/2022Distributed Computing,M.L.Liu26Alogorithm for building an RMI Callback ApplicationServer side:1.Open a directory for all the files to be generated for this application.2.Specify the remote-server inter

    42、face,and compile it to generate the interface class file.3.Build the remote server class by implementing the interface,and compile it using javac.4.Use rmic to process the server class to generate a stub.class file and a skelton.class file:rmic SomeServer5.If stub downloading is desired,copy the stu

    43、b file to an appropriate directory on the HTTP host.6.Activate the RMIRegistry,if it has not already been activated.7.Set up a java.policy file.8.Activate the server,specifying(i)the codebase if stub downloading is desired,(ii)the server host name,and(iii)the security policy file.9.Obtain the Callba

    44、ckInterface.Compile it with javac,then use rmic to generate the stub file for the callback.12/20/2022Distributed Computing,M.L.Liu27Alogorithm for building an RMI Callback ApplicationClient side:1.Open a directory for all the files to be generated for this application.2.Implement the client program

    45、or applet,and compile it to generate the client class.3.If stub downloading is not in effect,copy the server interface stub class file by hand.4.Implement the callback interface.Compile it using javac,then using rmic to generate a stub class and a skeleton class for it.5.Set up a java.policy file.6.

    46、Activate the client,specifying(i)the server host name,and(ii)the security policy file.12/20/2022Distributed Computing,M.L.Liu28HelloClient,with callback HelloClient()/constructor System.setSecurityManager(new RMISecurityManager();/export this object as a remote object UnicastRemoteObject.exportObjec

    47、t(this);/Registry registry=LocateRegistry.getRegistry(localhost,RMIPort);h=(HelloInterface)registry.lookup(helloLiu);h.addCallback(this);/end constructor /call back method-this displays the message sent by the server public void callMe(String message)System.out.println(Call back received:+message);p

    48、ublic static void main(String args)/HelloClient client =new HelloClient();/while(true);/end while /end main/end HelloClient class12/20/2022Distributed Computing,M.L.Liu29HelloServer,HelloClientUnicastRemoteObjectHelloInterfacesayHelloHelloServerRMIPortsayHelloClass Diagram for HelloServerHelloClient

    49、RMIregistryHelloServergetRegistrysayHelloEvent diagram for the Hello applicationaddCallbackUnicastRemoteObjectCallbackInterfacesayHelloRMIPortsayHelloClass Diagram for HelloClientHelloClientcallMeaddCallbackcallMe12/20/2022Distributed Computing,M.L.Liu30Summary-1nClient callback:Client callback:nCli

    50、ent callback is useful for an application where the clients desire to be notified by the server of the occurrence of some event.nClient callback allows an object server to make remote method call to a client via a reference to a client remote interface.12/20/2022Distributed Computing,M.L.Liu31Summar

    展开阅读全文
    提示  163文库所有资源均是用户自行上传分享,仅供网友学习交流,未经上传用户书面授权,请勿作他用。
    关于本文
    本文标题:分布式计算原理与应用(Distributed-Computing)第八章课件.ppt
    链接地址:https://www.163wenku.com/p-4574741.html

    Copyright@ 2017-2037 Www.163WenKu.Com  网站版权所有  |  资源地图   
    IPC备案号:蜀ICP备2021032737号  | 川公网安备 51099002000191号


    侵权投诉QQ:3464097650  资料上传QQ:3464097650
       


    【声明】本站为“文档C2C交易模式”,即用户上传的文档直接卖给(下载)用户,本站只是网络空间服务平台,本站所有原创文档下载所得归上传人所有,如您发现上传作品侵犯了您的版权,请立刻联系我们并提供证据,我们将在3个工作日内予以改正。

    163文库