版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
中山火亭
SI:NYAT-SENITNITEB81TY
DistributedComputing
Technology
中山火孽Introduction
SUNYAT-SENUNIVERSITY
万海
WHWanHai@126.com
课件放于计算机系网络硬盘
2
中山火厚Review
SCNYAT-SENLNIVEKS1TY
SSocketAPI
UDP-datagramsockets
TCP-streamsockets
SClient-ServerModel
protocol/servicesession
interprocesscommunicationsandeventsynchronization
protocoldatarepresentation
Client-serverusingConnectionlessDatagramSocket
Client-serverusingconnection-orientedDatagramSocket
IterativeserversVs.Concurrentservers
Statefulserverversusstatelessserver
中山火厚
SUNYAT-SENLNIVEKS1TY
1.DistributedObjects
中山火孽0
SUNYAT-SENUNIVERSITY
1.DistributedObjects
1.1MessagePassingvs.DistributedObjects
1.2TheDistributedObjectsParadigm
1.3FromRPCtoRemoteMethodInvocation
1.4JavaRemoteMethodInvocation
中山大擘AConcurrent,Connection-orientedServer
8CNYAT-SENVX1VKKS1TY
中山火孽MessagePassingversusDistributedObjects
SUNYAT-SENUNIVERSITY
BThemessage-passingparadigmisanaturalmodelfor
distributedcomputing,inthesensethatitmimicsinterhuman
communications.Itisanappropriateparadigmfornetwork
serviceswhereprocessesinteractwitheachotherthroughthe
exchangesofmessages.
QHowever,theabstractionprovidedbythisparadigmdoesnot
meettheneedsofthecomplexityofsophisticatednetwork
applications.
MessagePassingversusDistributedObjects-2
中山火孽0
SUNYAT-SENUNIVERSITY
BMessagepassingrequirestheparticipatingprocessestobe
tightly-coupled:throughouttheirinteraction,theprocesses
mustbeindirectcommunicationwitheachother.If
communicationislostbetweentheprocesses(duetofailures
inthecommunicationlink,inthesystems,orinoneofthe
processes),thecollaborationfails.
aThemessage-passingparadigmisdata-oriented.Each
messagecontainsdatamarshalledinamutuallyagreedupon
format,andisinterpretedasarequestorresponseaccording
totheprotocol.Thereceivingofeachmessagetriggersan
actioninthereceivingprocess.
E3Itisinadequateforcomplexapplicationsinvolvingalargemix
ofrequestsandresponses.Insuchanapplication,thetaskof
interpretingthemessagescanbecomeoverwhelming.
8
Thedistributedobjectparadigm
中山火孽0
SUNYAT-SENUNIVERSITY
HThedistributedobjectparadigmisaparadigmthatprovides
abstractionsbeyondthoseofthemessage-passingmodel.Asits
nameimplies,theparadigmisbasedonobjectsthatexistina
distributedsystem.
SInobject-orientedprogramming,supportedbyanobject-
orientedprogramminglanguagesuchasJava,objectsareused
torepresentanentitysignificanttoanapplication.Eachobject
encapsulates:
thestateordataoftheentity:inJava,suchdataiscontainedin
theinstancevariablesofeachobject;
theoperationsoftheentity,throughwhichthestateoftheentity
canbeaccessedorupdated.
object-orientedprogramming
中山火孽0
SUNYAT-SENUNIVERSITY
Toillustrate,considerobjectsoftheDatagramMessageclass.
Eachobjectinstantiatedfromthisclasscontainsthreestate
dataitems:amessage,thesender'saddress,andthesender's
portnumber.Inaddition,eachobjectcontainsthree
operations:
■amethodputVal,whichallowsthevaluesofthesedata
itemstobemodified,
■agetMessagemethod,whichallowsthecurrentvalueofthe
messagetoberetrieved,and
■agetAddressmethod,whichallowsthesender'saddressto
beretrieved.
LocalObjectsvs.DistributedObjects
中山火孽0
SUNYAT-SENUNIVERSITY
E2Localobjectsarethosewhosemethodscanonlybeinvoked
byalocalprocess,aprocessthatrunsonthesame
computeronwhichtheobjectexists.
HAdistributedobjectisonewhosemethodscanbeinvoked
byaremoteprocess,aprocessrunningonacomputer
connectedviaanetworktothecomputeronwhichthe
objectexists.
中山火孽TheDistributedObjectParadigm
SUNYAT-SENUNIVERSITY
Inadistributedobjectparadigm,networkresourcesarerepresentedbydistributedobjects.To
requestservicefromanetworkresource,aprocessinvokesoneofitsoperationsormethods,
passingdataasparameterstothemethod.Themethodisexecutedontheremotehost,and
theresponseissentbacktotherequestingprocessasareturnvalue.
HostAHostB
objectstatedataitem
i:objectoperation
oadistributedobject
12
MessagePassingversusDistributedObjects-3
中山火孽0
SUNYAT-SENUNIVERSITY
Comparedtothemessage-passingparadigm,whichisdata-
oriented,thedistributedobjectsparadigmisaction-oriented:the
focusisontheinvocationoftheoperations,whilethedata
passedtakesonasecondaryrole.Althoughlessintuitiveto
human-beings,thedistributed-objectparadigmismorenatural
toobject-orientedsoftwaredevelopment.
中山火孽0
SUNYAT-SENUNIVERSITY
1.DistributedObjects
1.1MessagePassingvs.DistributedObjects
1.2TheDistributedObjectsParadigm
1.3FromRPCtoRemoteMethodInvocation
1.4JavaRemoteMethodInvocation
AnArchetypalDistributedObjectsSystem
中山火厚
SCNYAT-SENLNIVEKS1TY
*physicaldatapath
logicaldatapath
DistributedObjectSystem
中山火孽0
SUNYAT-SENUNIVERSITY
HAdistributedobjectisprovided,orexported,byaprocess,here
calledtheobjectserver.Afacility,herecalledanobjectregistry,
mustbepresentinthesystemarchitectureforthedistributed
objecttoberegistered.
HToaccessadistributedobject,aprocess-anobjectclient-looks
uptheobjectregistryforareferencetotheobjectThis
referenceisusedbytheobjectclienttomakecallstothe
methods.
Areferenceisa“handle“foranobject;itisarepresentationthrough
whichanobjectcanbelocatedinthecomputerwheretheobjectresides.
DistributedObjectSystem-2
中山火孽0
SUNYAT-SENUNIVERSITY
Logically,theobjectclientmakesacalldirectlytoaremotemethod.
Inreality,thecallishandledbyasoftwarecomponent,calledaclient
proxy,whichinteractswhichthesoftwareontheclienthostthatprovides
theruntimesupportforthedistributedobjectsystem.
Theruntimesupportisresponsiblefortheinterprocesscommunication
neededtotransmitthecalltotheremotehost,includingthemarshalling
oftheargumentdatathatneedstobetransmittedtotheremoteobject.
DistributedObjectSystem-3
中山火孽0
SUNYAT-SENUNIVERSITY
QAsimilararchitectureisrequiredontheserverside,wheretheruntime
supportforthedistributedobjectsystemhandlesthereceivingofmessages
andtheunmarshallingofdata,andforwardsthecalltoasoftwarecomponent
calledtheserverproxy.
E3Theserverproxyinterfaceswiththedistributedobjecttoinvokethemethod
calllocally,passingintheunmarshalleddataforthearguments.
HThemethodcallresultsintheperformanceofsometasksontheserverhost.
Theoutcomeoftheexecutionofthemethod,includingthemarshalleddata
forthereturnvalue,isforwardedbytheserverproxytotheclientproxy,via
theruntimesupportandnetworksupportonbothsides.
中山火孽DistributedObjectSystems/Protocols
SUNYAT-SENUNIVERSITY
Thedistributedobjectparadigmhasbeenwidelyadoptedin
distributedapplications,forwhichalargenumberof
mechanismsbasedontheparadigmareavailable.Amongthe
mostwellknownofsuchmechanismsare:
〜JavaRemoteMethodInvocation(RMI),
〜theCommonObjectRequestBrokerArchitecture(CORBA)
systems,
〜theDistributedComponentObjectModel(DCOM),
〜mechanismsthatsupporttheSimpleObjectAccessProtocol
(SOAP).
Ofthese,themoststraightforwardistheJavaRMI
中山火孽0
SUNYAT-SENUNIVERSITY
1.DistributedObjects
1.1MessagePassingvs.DistributedObjects
1.2TheDistributedObjectsParadigm
1.3FromRPCtoRemoteMethodInvocation
1.4JavaRemoteMethodInvocation
20
中山火孽RemoteProcedureCalls(RPC)
SUNYAT-SENUNIVERSITY
QRemoteMethodInvocationhasitsorigininaparadigmcalledRemoteProcedureCall
QIntheremoteprocedurecallmodel,aprocedurecallismadebyoneprocesstoanother,
withdatapassedasarguments.Uponreceivingacall,theactionsencodedinthe
procedureareexecuted,thecallerisnotifiedofthecompletionofthecall,andareturn
value,ifany,istransmittedfromthecalleetothecaller.
ProcessA
»executionflow
LocalProcedureCallandRemoteProcedureCall
中山火孽
hostA0
SUNYAT-SENUNIVERSITY
Alocalprocedurecall
hostB
hostA
1.procionhostAmakesacall4.TheproxyonhostB
toproc2onhostB.unmarshallsthedata
2.Iheruntimesupportmapsreceivedandissuesa
thecalltoacalltotheproxycalltoproc2.
onhostA.5.Thecodeinproc2is
3.Theproxymarshallsthedataexecutedandreturns
andmakesanIPCcalltoatotheproxyonhostB.
proxyonhostB.6.Theproxymarshalls
thereturnvalueand
7.TheproxyreceivedthereturnmakesanIPCcallto
value,unmarshallsthedata,theproxyonhostA.
andforwardsthereturnvalue
toprod,whichresumesits
executionflow.
Aremoteprocedurecall
(thereturnexecutionpathisnotshown)
■22
RemoteProcedureCalls(RPC)-2
中山火孽0
SUNYAT-SENUNIVERSITY
E3Sinceitsintroductionintheearly1980s,theRemoteProcedureCallmodel
hasbeenwidelyinuseinnetworkapplications.
E3TherearetwoprevalentAPIsforthisparadigm.
theOpenNetworkComputingRemoteProcedureCall,evolved
fromtheRPCAPIoriginatedfromSunMicrosystemsintheearly
1980s.
Theotherwell-knownAPIistheOpenGroupDistributed
ComputingEnvironment(DCE)RPC.
E3BothAPIsprovideatool,rpcgen,fortransformingremoteprocedurecalls
tolocalprocedurecallstothestub.
中山火孽0
SUNYAT-SENUNIVERSITY
1.DistributedObjects
1.1MessagePassingvs.DistributedObjects
1.2TheDistributedObjectsParadigm
1.3FromRPCtoRemoteMethodInvocation
1.4JavaRemoteMethodInvocation
24
中山火孽RemoteMethodInvocation
SUNYAT-SENUNIVERSITY
HRemoteMethodInvocation(RMI)isanobject-oriented
implementationoftheRemoteProcedureCallmodel.It
isanAPIforJavaprogramsonly.
BUsingRMI,anobjectserverexportsaremoteobjectand
registersitwithadirectoryservice.Theobjectprovides
remotemethods,whichcanbeinvokedinclient
programs.
SSyntactically:
Aremoteobjectisdeclaredwitharemoteinterface,an
extensionoftheJavainterface.
Theremoteinterfaceisimplementedbytheobjectserver.
Anobjectclientaccessestheobjectbyinvokingtheremote
methodsassociatedwiththeobjectsusingsyntaxprovided
forremotemethodinvocations.
25
中山火孽TheJavaRMIArchitecture
SUNYAT-SENUNIVERSITY
>logicaldatapath
>physicaldatapath
26
ObjectRegistry
中山火孽0
SUNYAT-SENUNIVERSITY
HTheRMIAPIallowsanumberofdirectoryservicestobe
usedforregisteringadistributedobject.
HWewilluseasimpledirectoryservicecalledtheRMI
registry,rmiregistry9whichisprovidedwiththeJava
SoftwareDevelopmentKit(SDK?.TheRMIRegistryis
aservicewhoseserver,whenactive,runsontheobject
server5shostmachine,byconventionandbydefaultonthe
TCPport1099.
OnesuchserviceistheJavaNamingandDirectoryInterface(JNDI),which
ismoregeneralthantheRMIregistry,inthesensethatitcanbeusedby
applicationsthatdonotusetheRMIAPI.
TheJavaSDKiswhatyoudownloadtoyourmachinetoobtaintheuseof
theJavaclasslibrariesandtoolssuchasthejavacompilerjavac.
27
Theinteractionbetweenthestubandtheskeleton
中山火孽0
SUNYAT-SENUNIVERSITY
中山火厚TheAPIfortheJavaRMI
8CNYAT-SENLNIVEKS1TY
HTheRemoteInterface
ElTheServer-sideSoftware
TheRemoteInterfaceImplementation
StubandSkeletonGenerations
TheObjectServer
HTheClient-sideSoftware
TheRemoteInterface
中山火孽0
SUNYAT-SENUNIVERSITY
HAJavainterfaceisaclassthatservesasatemplatefor
otherclasses:itcontainsdeclarationsorsignaturesof
methodswhoseimplementationsaretobesuppliedby
classesthatimplementstheinterface.
HAjavaremoteinterfaceisaninterfacethatinheritsfrom
theJavaRemoteclass,whichallowstheinterfacetobe
implementedusingRMIsyntax.OtherthantheRemote
extensionandtheRemoteexceptionthatmustbespecified
witheachmethodsignature,aremoteinterfacehasthe
samesyntaxasaregularorlocalJavainterface.
中山火厚Asampleremoteinterface
8CNYAT-SENLNIVEKS1TY
//file:Somelnterface.java
//tobeimplementedbyaJavaRMIserverclass,
importjava.rmi.*
publicinterfaceSomelnterfaceextendsRemote{
//signatureoffirstremotemethod
publicStringsomeMethodl()
throwsjava.rmi.RemoteException;
//signatureofsecondremotemethod
publicintsomeMethod2(float)throws
java.rmi.RemoteException;
//signatureofotherremotemethodsmayfollow
Asampleremoteinterface-2
中山火孽0
SUNYAT-SENUNIVERSITY
HThejava.rmi.RemoteExceptionmustbelistedinthethrow
clauseofeachmethodsignature.
E3Thisexceptionisraisedwhenerrorsoccurduringthe
processingofaremotemethodcall,andtheexceptionis
requiredtobecaughtinthemethodcaller'sprogram.
E3Causesofsuchexceptionsincludeexceptionsthatmay
occurduringinterprocesscommunications,suchasaccess
failuresandconnectionfailures,aswellasproblems
uniquetoremotemethodinvocations,includingerrors
resultingfromtheobject,thestub,ortheskeletonnot
beingfound.
StubandSkeletonGenerations
中山火孽0
SUNYAT-SENUNIVERSITY
InRMI,eachdistributedobjectrequiresaproxyeachfortheobject
serverandtheobjectclient,knownsastheobjecfsskeletonandstub
respectively.Theseproxiesaregeneratedfromtheimplementationof
aremoteinterfaceusingatoolprovidedwiththeJavaSDK:theRMI
compilerrmic.
rmic<classnameoftheremoteinterfaceimplementation>
Forexample:
rmicSomelmpl
Asaresultofthecompilation,twoproxyfileswillbegenerated,each
prefixedwiththeimplementationclassname:
Somelmpl_skel.class
Somelmpl_stub.class.
Thestubfilefortheobject
中山火孽0
SUNYAT-SENUNIVERSITY
E2Thestubfilefortheobject,aswellastheremoteinterface
file,mustbesharedwitheachobjectclient-thesefileare
requiredfortheclientprogramtocompile.
E2Acopyofeachfilemaybeprovidedtotheobjectclientby
hand.Inaddition,theJavaRMIhasafeaturecalled6istub
downloading^whichallowsastubfiletobeobtainedbya
clientdynamically.
中山火孽TheObjectServer
SUNYAT-SENUNIVERSITY
Theobjectserverclassisaclasswhosecodeinstantiatesand
exportsanobjectoftheremoteinterfaceimplementation.Figure10
showsatemplatefortheobjectserverclass.
importjava.rmi.*;
publicclassSomeServer{
publicstaticvoidmain(Stringargs[]){
try(
//codeforportnumbervaluetobesupplied
SomelmplexportedObj=newSomelmpl();
(RMIPortNum);
//registertheobjectunderthename''some"
registryURL="rmi://localhost:"+portNtim+"/some";
Naming.rebind(registryURL,exportedObj);
System.out.printin("SomeServerready.");
}//endtry
}//endmain
35
中山火孽TheObjectServer-2
SUNYAT-SENUNIVERSITY
//ThismethodstartsaRMIregistryonthelocalhost,ifit
//doesnotalreadyexistsatthespecifiedportnumber.
privatestaticvoidintRMIPortNum)
throwsRemoteException{
try(
Registryregistry=LocateRegistry.getRegistry(RMIPortNum);
registry.list();
//Theabovecallwillthrowanexception
//iftheregistrydoesnotalreadyexist
}
catch(RemoteExceptionex){
//Novalidregistryatthatport.
System.out.printin(
"RMIregistrycannotbelocatedatport"+RMIPortNum);
Registryregistry=LocateRegistry.createRegistry(RMIPortNum);
System.out.printin(
"RMIregistrycreatedatport"+RMIPortNum);
)
}//endstartRegistry
中山火孽TheObjectServer-3
SUNYAT-SENUNIVERSITY
Inourobjectservertemplate,thecodeforexportinganobjectisas
follows:
//registertheobjectunderthename''some"
registryURL="rmi://localhost:"+portNum+
"/some";
Naming.rebind(registryURL,exportedObj);
TheNamingclassprovidesmethodsforstoringandobtaining
referencesfromtheregistry.Inparticular,therebindmethodallowan
objectreferencetobestoredintheregistrywithaURLintheformof
rmi://<hostname>:<portnumber>/<referencename>
Therebindmethodwilloverwriteanyreferenceintheregistrybound
withthegivenreferencename.Iftheoverwritingisnotdesirable,
thereisalsoaZ?//7(ymethod.
Thehostnameshouldbethenameoftheserver,orsimply“localhost”.
Thereferencenameisanameofyourchoice,andshouldbeuniquein
theregistry.
37
中山火孽TheRMIRegistry
SUNYAT-SENUNIVERSITY
HAserverexportsanobjectbyregisteringitbyasymbolicnamewithaserver
knownastheRMIregistry.
//CreateanobjectoftheInterface
Somelnterfacelobj=newSomelnterfaceC'Server1,5);
//Registertheobject;rebindwilloverwirteexisting//
registrationbysamename-bind()willnot.
Naming.rebind(t4Server1,,,obj);
QAserver,calledtheRMIRegistry,isrequiredtorunonthehostoftheserverwhich
exportsremoteobjects.
HTheRMIRegistryisaserverlocatedatport1099bydefault
QItcanbeinvokeddynamicallyintheserverclass:
importjava.rmi.registry.LocateRegistry;
LocateRegistry.createRegistry(1099);
TheRMIRegistry-2
中山火孽0
SUNYAT-SENUNIVERSITY
TAlternatively,anRMIregistrycanbeactivatedby
handusingthermiregistryutilitywhichcomes
withtheJavaSoftwareDevelopmentKit(SDK),
asfollows:
rmiregistry<portnumber>
wheretheportnumberisaTCPportnumber.If
noportnumberisspecified,portnumber1099is
assumed.
STheregistrywillruncontinuouslyuntilitisshut
down(viaCTRL-C,forexample)
39
TheObjectServer-5
中山火孽0
SUNYAT-SENUNIVERSITY
HWhenanobjectserverisexecuted,theexportingofthe
distributedobjectcausestheserverprocesstobeginto
listenandwaitforclientstoconnectandrequestthe
serviceoftheobject.
HAnRMIobjectserverisaconcurrentserver:each
requestfromanobjectclientisservicedusinga
separatethreadoftheserver.Notethatifaclient
processinvokesmultipleremotemethodcalls,these
callsw川beexecutedconcurrentlyunlessprovisionsare
madeintheclientprocesstosynchronizethecalls.
40
中山火孽TheClient-sideSoftware
SUNYAT-SENUNIVERSITY
Theprogramfortheclientclassislikeanyother
Javaclass.
ThesyntaxneededforRMIinvolves
locatingtheRMIRegistryintheserverhost,
and
lookinguptheremotereferencefortheserver
object;thereferencecanthenbecasttothe
remoteinterfaceclassandtheremotemethods
invoked.
41
中山火孽TheClient-sideSoftware-2
SUNYAT-SENUNIVERSITY
importjava.rmi.*;
publicclassSomeClient{
publicstaticvoidmain(Stringargs[]){
try(
StringregistryURL=
"rmi://localhost:"+portNum+"/some";
Somelnterfaceh=
(Somelnterface)Naming.lookup(registryURL);
//invoketheremotemethod(s)
Stringmessage=h.methodi();
System.out.printin(message);
//method2canbeinvokedsimilarly
}//endtry
catch(Exceptione){
System.out.printIn("ExceptioninSomeClient:"+e);
}
}//endmain
//Definitionforothermethodsoftheclass,ifany.
}//endclass
Lookinguptheremoteobject
中山火孽0
SUNYAT-SENUNIVERSITY
ThelookupmethodoftheNamingclassisused
toretrievetheobjectreference,ifany,previously
storedintheregistrybytheobjectserver.Note
thattheretrievedreferencemustbecasttothe
remoteinterface(notitsimplementation)class.
StringregistryURL=
"rmi://localhost:n+portNum+"/some";
Somelnterfaceh=
(Somelnterface)Naming.lookup(registryURL);
43
InvokingtheRemoteMethod
中山火孽0
SUNYAT-SENUNIVERSITY
Theremoteinterfacereferencecanbeusedtoinvokeany
ofthemethodsintheremoteinterface,asinthe
example:
Stringmessage=h.methodi();
System.out.printin(message);
HNotethatthesyntaxfortheinvocationoftheremote
methodsisthesameasforlocalmethods.
HItisacommonmistaketocasttheobjectretrievedfrom
theregistrytotheinterfaceimplementationclassorthe
serverobjectclass.Insteaditshouldbecastasthe
interfaceclass.
中山火厚
8CNYAT-SENLNIVEKS1TY
StepsforbuildinganRMIapplication
Algorithmfordevelopingtheserver-sidesoftware
中山火孽
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 学习部工作计划范文
- 吉林彩色透水沥青施工方案
- 合肥阳台防水补漏施工方案
- 加油站围墙拆除施工方案
- 2024高一体育教师教学工作计划范文
- 2024部队财务工作计划范文
- 扶贫办工作总结和工作计划
- 2024秋季幼儿园保教工作计划范文
- 《科普健康知识讲座》课件
- 《纳米材料》课件
- 《岁末年初重点行业领域安全生产提示》专题培训
- 手术室的人文关怀
- 2024合作房地产开发协议
- 农贸市场通风与空调设计方案
- 第25课《周亚夫军细柳》复习课教学设计+2024-2025学年统编版语文八年级上册
- 2024年广东省深圳市中考英语试题含解析
- 部编版小学五年级上册道德与法治单元检测试卷含答案(全册)
- GB/T 16288-2024塑料制品的标志
- 四年级英语上册 【月考卷】第三次月考卷(Unit 5-Unit 6) (含答案)(人教PEP)
- 中国近代史纲要试题及答案(全套)
- 第七单元 条形统计图 条形统计图(一) (同步练习)-2024-2025学年人教版数学四年级上册
评论
0/150
提交评论