課件放于計算機系網(wǎng)絡硬盤_第1頁
課件放于計算機系網(wǎng)絡硬盤_第2頁
課件放于計算機系網(wǎng)絡硬盤_第3頁
課件放于計算機系網(wǎng)絡硬盤_第4頁
課件放于計算機系網(wǎng)絡硬盤_第5頁
已閱讀5頁,還剩80頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權,請進行舉報或認領

文檔簡介

中山火亭

SI:NYAT-SENITNITEB81TY

DistributedComputing

Technology

中山火孽Introduction

SUNYAT-SENUNIVERSITY

萬海

WHWanHai@126.com

課件放于計算機系網(wǎng)絡硬盤

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“l(fā)ocalhost”.

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. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經(jīng)權益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
  • 6. 下載文件中如有侵權或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

最新文檔

評論

0/150

提交評論