RPC IMPLEMENTATION STEPS - Computer Science · RPC AWARENESS IN APPLICATION: TWO EXTREMES RPC...
Transcript of RPC IMPLEMENTATION STEPS - Computer Science · RPC AWARENESS IN APPLICATION: TWO EXTREMES RPC...
RPC IMPLEMENTATION: BASIC
STEPS
Instructor: Prasun Dewan
Department of Computer Science
University of North Carolina at Chapel Hill
2
SIMULATING REMOTE PROCEDURE CALL
Port
(Mailbox)
Port
(Mailbox)
Process/
Thread
Process/
Thread
Process/
Thread
Process/
Thread
<method var><method var>
<params><params>
<method><method>
<params var><params var>
<params><params>
<method><method>
<method> (<params>)<method> (<params>)
<method><method>
<params><params>
Send expressions encoding method and parameters
These are assigned to corresponding remote variables
Side effect of assignment is to call method with parameters
Goal is to call a method with params
<method> (<params>)<method> (<params>)
vs. local call?vs. local call?
3
Activation Record (parameters, return
value, return address, and other info)
Activation Record (parameters, return
value, return address, and other info)
ACTIVATION RECORD VS. RPC MESSAGES
Activation Record (Parameters, return
value, return address, and other info)
Activation Record (Parameters, return
value, return address, and other info)
Calling
Process
Calling
Process
Call message (operation id, parameters,
source)
Call message (operation id, parameters,
source)
Return message (return value)
Return message (return value)
Called
process
Called
process
Activation Record (Parameters, return
value, return address, and other info)
Activation Record (Parameters, return
value, return address, and other info)
Stack
Stack
Call results in marshalling and unmarshalling of call/return value rather than push and pop of activation record on
stack
(Un)marshalling of call: translation between call and
message
4
DATA SET UP
Server exports external description of data (RA) port
Client determines external description
Statically or dynamicallyStatically or dynamically
Statically or dynamicallyStatically or dynamically
Server starts and makes data port connectable
Client starts and establishes connection
5
RPC SET UP
Server exports external description of calls serviced on RA (data) port
Client finds this information
Statically or dynamicallyStatically or dynamically
Statically or dynamicallyStatically or dynamically
6
PROCESSING OF CALL MESSAGE AND RETURN
VALUE
Generate call message for call using exported information
Process call message in caller process
Communicate call message on data port and handle errors
Process call message in callee process
Invoke called operation
7
PROCESSING OF CALL MESSAGE AND RETURN
VALUE
Possibly create return message in callee process
Communicate return message to caller process
Process return message in callee process and handle errors
Return value to caller operation
8
AUTOMATION OF REMOTE PROCEDURE CALL
Port
(Mailbox)
Port
(Mailbox)
Process/
Thread
Process/
Thread
Process/
Thread
Process/
Thread
<method var><method var>
<params><params>
<method><method>
<params var><params var>
<params><params>
<method><method>
<method> (<params>)<method> (<params>)
<method><method>
<params><params>
<method> (<params>)<method> (<params>)
RPC System@Calling SiteRPC System@Calling Site
RPC System @Callee SiteRPC System @Callee Site
App @ Calling SiteApp @ Calling Site
App @Calleee SiteApp @Calleee Site
Division of labor?Division of labor?
9
RPC AWARENESS IN APPLICATION: TWO
EXTREMES
RPC clients and servers handle all aspects of RPC and are completely aware of all of the steps listed below
RPC clients and servers are completely unaware of distribution details
Java RMI falls close to complete transparency Java RMI falls close to complete transparency
GIPC RMI supports a wider spectrum that falls closer and furtherGIPC RMI supports a wider spectrum that falls closer and further
Can one have complete transparency? (Answered at the end –actually deleted from this overview of basic steps)
Can one have complete transparency? (Answered at the end –actually deleted from this overview of basic steps)
10
RPC VS. RMI
RPC: O-O or Conventional
RMI: O-O
11
MAIN O-O EXAMPLES
Java RMI
GIPC RMI
Will use GIPC as an example of detailed implementationWill use GIPC as an example of detailed implementation
12
GIPC VS. RMI
Allow remote assignment and remote procedure call on same port
Allow remote assignment and remote procedure call on same port
Notion of connected client and server port visibleNotion of connected client and server port visible
Distinguishing between regular and RPC messages?Distinguishing between regular and RPC messages?
Calling
Process
Calling
Process
Call message (operation id, parameters,
source)
Call message (operation id, parameters,
source)
Return message (return value)
Return message (return value)
Called
process
Called
process
Non RPC MessageNon RPC Message
Non RPC MessageNon RPC Message
13
DISTINGUISHING RPC AND REGULAR MESSAGES
Use special GIPC types for RPC MessagesUse special GIPC types for RPC Messages
Applications cannot pass instances of these types directlyApplications cannot pass instances of these types directly
GIPC RPC traps instances of these types and passes others to application listeners of underlying data ports
GIPC RPC traps instances of these types and passes others to application listeners of underlying data ports
Should allow GIPC developers to change the nature and processing of of these messages without changing the complete
RPC system
Should allow GIPC developers to change the nature and processing of of these messages without changing the complete
RPC system
Nature of these messages?Nature of these messages?
14
PROCESSING OF CALL MESSAGE AND RETURN
VALUE
Generate call message for call using exported informationGenerate call message for call using exported information
Possibly create return message in callee processPossibly create return message in callee process
Calling
Process
Calling
Process
Call message (operation id, parameters,
source)
Call message (operation id, parameters,
source)
Return message (return value)
Return message (return value)
Called
process
Called
process
Non RPC MessageNon RPC Message
Non RPC MessageNon RPC Message
15
METHOD RETURN VALUE
RPCReturnValueRPCReturnValue Object returnValueObject returnValue
16
CALL MESSAGE
Call
<ObjectIDType>
Call
<ObjectIDType>
transient Method methodtransient Method method
ObjectIDType targetObjectObjectIDType targetObject
Object[] argsObject[] args
SerializableCallSerializableCall
extends <String>extends <String>
SerializedMethod serializedMethodSerializedMethod serializedMethod
SerializeMethodSerializeMethod
transient Method methodtransient Method method
String[] parameterTypeNamesString[] parameterTypeNames
String methodNameString methodName
String classNameString className
17
SERIALIZING A METHOD
Marshaller<ObjectIdType>
Marshaller<ObjectIdType>
Call<ObjectIdType> marshallCall(
ObjectIdType aTargetObject, Method
aMethod, Object[] anArgsList)
Call<ObjectIdType> marshallCall(
ObjectIdType aTargetObject, Method
aMethod, Object[] anArgsList)
Call
<ObjectIDType>
Call
<ObjectIDType> transient Method
serializableMethod
transient Method
serializableMethod
ObjectIDType
targetObject
ObjectIDType
targetObject
Object[] argsObject[] args
18
PORT VS. GIPC-RMI
Client ObjectClient Object Server ObjectServer Object
Server ProxyServer Proxy
m(p1, … pN)m(p1, … pN)
m(p1, … pN)m(p1, … pN)
Client PortClient Port
Server PortServer Port
Synchronization?Synchronization?
19
PROCESSING OF CALL MESSAGE AND RETURN
VALUE
Generate call message for call using exported informationGenerate call message for call using exported information
Process call message in caller processProcess call message in caller process
Communicate call message on data port and handle errorsCommunicate call message on data port and handle errors
Process call message in callee processProcess call message in callee process
Invoke called operationInvoke called operation
20
PROCESSING OF CALL MESSAGE AND RETURN
VALUE
Possibly create return message in callee processPossibly create return message in callee process
Communicate return message to caller processCommunicate return message to caller process
Process return message in callee process and handle errors Process return message in callee process and handle errors
Return value to caller operationReturn value to caller operation
21
OBJECT FORWARDERS AND SERIALIZERS
Sender <Object>
(Object Port)
Sender <Object>
(Object Port)
Sender<ByteBuffer>
(Buffer Skeleton)
Sender<ByteBuffer>
(Buffer Skeleton)
Receive Listener
<ByteBuffer> (Buffer
Skeleton)
Receive Listener
<ByteBuffer> (Buffer
Skeleton)
Receive
Notifier<Object>
Receive
Notifier<Object>
Send Forwarder
<Object, Object>
Send Forwarder
<Object, Object> ReceiveForwarder
<Object, Object>
ReceiveForwarder
<Object, Object>
Serializer
<Object, ByteBuffer>
Serializer
<Object, ByteBuffer> Deserializer
<ByteBuffer, Object>
Deserializer
<ByteBuffer, Object>
22
OBJECT FORWARDERS AND SERIALIZERS
Sender <Object>
(RPC Port)
Sender <Object>
(RPC Port)
Sender <Object>
(Object Port)
Sender <Object>
(Object Port)
Receive Listener
<Object> (RPC Port)
Receive Listener
<Object> (RPC Port)
Receive
Notifier<Object>
Receive
Notifier<Object>
Call Message and Return
Message SendTrapper
<Object, Object>
Call Message and Return
Message SendTrapper
<Object, Object>
Call Message and Return
Message ReceiveTrapper
<Object, Object>
Call Message and Return
Message ReceiveTrapper
<Object, Object>
Shared Data
Structures
Shared Data
Structures
Send trapper may need to block sender to implement synchronous operationSend trapper may need to block sender to implement synchronous operation
Send and receive trapper may need to share information about remote references sent and received
Send and receive trapper may need to share information about remote references sent and received
23
OBJECT FORWARDERS AND SERIALIZERS (REVIEW)
Sender <Object>
(RPC Port)
Sender <Object>
(RPC Port)
Sender <Object>
(Object Port)
Sender <Object>
(Object Port)
Receive Listener
<Object> (RPC Port)
Receive Listener
<Object> (RPC Port)
Receive
Notifier<Object>
Receive
Notifier<Object>
Call Message and Return
Message SendTrapper
<Object, Object>
Call Message and Return
Message SendTrapper
<Object, Object>
Call Message and Return
Message ReceiveTrapper
<Object, Object>
Call Message and Return
Message ReceiveTrapper
<Object, Object>
Coordinating
Shared Data
Structures
Coordinating
Shared Data
Structures
Send trapper may need to block sender to implement synchronous operationSend trapper may need to block sender to implement synchronous operation
24
OBJECT FORWARDERS AND SERIALIZERS (REVIEW)
Sender <Object>
(RPC Port)
Sender <Object>
(RPC Port)
Sender <Object>
(Object Port)
Sender <Object>
(Object Port)
Receive Listener
<Object> (RPC Port)
Receive Listener
<Object> (RPC Port)
Receive
Notifier<Object>
Receive
Notifier<Object>
Call Message and Return
Message SendTrapper
<Object, Object>
Call Message and Return
Message SendTrapper
<Object, Object>
Call Message and Return
Message ReceiveTrapper
<Object, Object>
Call Message and Return
Message ReceiveTrapper
<Object, Object>
SentCall
Completer
SentCall
Completer
SendTrapper and ReceiveTrapper at Caller Share an Instance of Synchronizing SentCallCompleter
SendTrapper and ReceiveTrapper at Caller Share an Instance of Synchronizing SentCallCompleter
Coordination between Caller and Called Site? Coordination between Caller and Called Site?
25
DUPLEX SENT CALL COMPLETER (PUBLIC AND
NON PUBLIC METHODS, NEW NAMES)
processReturnValue (String aSource, Object
aMessage);
processReturnValue (String aSource, Object
aMessage);
returnValueOfRemoteMethodCall() called, after call message sent: receive return value and block caller if necessary
returnValueOfRemoteMethodCall() called, after call message sent: receive return value and block caller if necessary
Object returnValueOfRemoteMethodCall
(String aRemoteEndPoint, Object aCall)
Object returnValueOfRemoteMethodCall
(String aRemoteEndPoint, Object aCall)
ADuplexSentCall CompleterADuplexSent
Call Completer
Object returnValueOfRemoteFunctionCall
(String aRemoteEndPoint, Object aCall)
Object returnValueOfRemoteFunctionCall
(String aRemoteEndPoint, Object aCall)
Object returnValueOfRemoteProcedureCall
(String aRemoteEndPoint, Object aCall)
Object returnValueOfRemoteProcedureCall
(String aRemoteEndPoint, Object aCall)Non blocking,
simply returns
Non blocking,
simply returns
Blocks for
return value
Blocks for
return value
UnblocksUnblocks
Renamed: returnValueOfRemoteFunction(Procedure)Call
getReturnValueOfRemoteFunction(Procedure)Call, processReturnValuereturnValueReceived
Renamed: returnValueOfRemoteFunction(Procedure)Call
getReturnValueOfRemoteFunction(Procedure)Call, processReturnValuereturnValueReceived
26
RPCReturnValue
Queue
(BoundedBuffer)
RPCReturnValue
Queue
(BoundedBuffer)
FUNCTION CALL SYNCHRONIZATION AND
MATCHED CLIENT/SERVER OBJECTS
ReceivedCall
Invoker
ReceivedCall
Invoker
Remote function call is blockingRemote function call is blocking
CallCall
Return
Val
Return
Val
CallCall
RemoteObjectRemoteObjectT m(…)T m(…)
ProxyProxyT m(…)T m(…)
SentCall
Completer
SentCall
Completer
Return
Val
Return
Val
get()get()put()put()
returnValueOfRemoteFunctionCall()returnValueOfRemoteFunctionCall()
process
Return
Value()
process
Return
Value()
handle
Function
Return()
handle
Function
Return()
messageReceived()message
Received()
MarshallerMarshallermarshall
Callmarshall
CallSendTrapperSendTrapper
send()send()
SendTrapperSendTrapper
send()send()
ReceiveTrapperReceiveTrapper
receive()receive()
ReceiveTrapperReceiveTrapper
receive()receive()
27
PROCEDURE CALL SYNCHRONIZATION AND
MATCHED CLIENT/SERVER OBJECTS
ReceivedCall
Invoker
ReceivedCall
Invoker
Remote procedure call is not blocking
Remote procedure call is not blocking
CallCall
CallCall
RemoteObjectRemoteObjectT m(…)T m(…)
ProxyProxyT m(…)T m(…)
SentCall
Completer
SentCall
CompleterreturnValueOfRemoteProcedureCall()returnValueOfRemoteProcedureCall()
handle
Procedure
Return()
handle
Procedure
Return()
messageReceived()message
Received()
MarshallerMarshallermarshall
Callmarshall
CallSendTrapperSendTrapper
send()send()
ReceiveTrapperReceiveTrapper
receive()receive()
28
SYNCHRONOUS CALLBACK IN REMOTE CALL
RPCMessageReceiver
RPCMessageReceiver messageReceived()messageReceived()
NIO
Selection
Thread
NIO
Selection
Thread
SelectorSelector
Remote function call is blockingRemote function call is blocking
select()select()
CallCall
Return
Val
Return
Val
CallCall
RemoteObjectRemoteObjectm1(…)m1(…)
ProxyProxy
T m2(…)T m2(…)
get()get()
RPCReturnValue
Queue
(BoundedBuffer)
RPCReturnValue
Queue
(BoundedBuffer)
put()put()
29
GIPC ASYNCHRONOUS INVOKER (FACTORY
SELECTED)
RPCMessageReceiver
RPCMessageReceiver messageReceived()messageReceived()
NIO
Selection
Thread
NIO
Selection
Thread
SelectorSelector
Remote function call is blockingRemote function call is blocking
get()get()
select()select()
RPCReturnValue
Queue
(BoundedBuffer)
RPCReturnValue
Queue
(BoundedBuffer)
CallCall
Return
Val
Return
Val
CallCall
put()put()
RemoteObjectRemoteObjectm1(…)m1(…)
ProxyProxy
T m2(…)T m2(…)
GIPC
Asynchronous
MethodInvoker
GIPC
Asynchronous
MethodInvoker
Factory determines if
asynchronous method
invoker is created
Factory determines if
asynchronous method
invoker is created
Id in Call and Return
Value?
Id in Call and Return
Value?
How many return
value queues and
queue size?
How many return
value queues and
queue size?
30
GLOBAL RECEIVED VALUE INSTEAD OF BUFFER
processReturnValue(String aSource, Object aMessage)processReturnValue(String aSource, Object aMessage)
wait()wait()
Clear and return received valueClear and return received value
Object returnValueOfRemoteFunctionCall( String aSource, Call aCall)Object returnValueOfRemoteFunctionCall( String aSource, Call aCall)
Received Return Value
Received Return Value
Store return valueStore return value
wait()wait()
Multiple calls
can be made
concurrently to a
server by
different threads
Multiple calls
can be made
concurrently to a
server by
different threads
31
GLOBAL BOUNDED BUFFER SERVERS
processReturnValue(String aSource, Object aMessage)processReturnValue(String aSource, Object aMessage)
return next value in global (synchronized) bounded buffer
return next value in global (synchronized) bounded buffer
Object returnValueOfRemoteFunctionCall( String aSource, Call aCall)Object returnValueOfRemoteFunctionCall( String aSource, Call aCall)
Put return value in global bounded buffer?
Put return value in global bounded buffer?
Calls return in
same order as
they wait
Calls return in
same order as
they wait
Concurrent calls
can be made to
different callees
Concurrent calls
can be made to
different callees
These would occur
in same order at a
particular callee
These would occur
in same order at a
particular callee
As long as caller
and callee sites
serialize them
As long as caller
and callee sites
serialize them
32
PER CALLEE BOUNDED BUFFER
processReturnValue(String aSource, Object aMessage)processReturnValue(String aSource, Object aMessage)
return next value in local bounded buffer
return next value in local bounded buffer
Object returnValueOfRemoteFunctionCall( String aSource, Call aCall)Object returnValueOfRemoteFunctionCall( String aSource, Call aCall)
Put return value in local bounded buffer
Put return value in local bounded buffer
Calls return in
same order as
they wait
Calls return in
same order as
they wait
Concurrent calls
can be made to
different callees
Concurrent calls
can be made to
different callees
These would occur
in same order at a
particular callee
These would occur
in same order at a
particular callee
As long as caller
and callee sites
serialize them
As long as caller
and callee sites
serialize them
Local bounded buffer lookup(aDestination)
Local bounded buffer lookup(aDestination)
Local bounded buffer lookup(aSource)
Local bounded buffer lookup(aSource)
33
METHOD RETURN VALUE
RPCReturnValueRPCReturnValue Object returnValueObject returnValue
No Id sent to match with callNo Id sent to match with call
34
SUMMARY OF METHOD CALL HANDLING
Synchronization needed between caller and callee.
In GIPC for function calls.
In RMI for both function and procedure calls.
Cannot use shared data structures for synchronization, so use internal messages generated by the RPC system:
AnRPCReturnValue in GIPC,
After sending call message caller invokes a method to wait for synchronization message from callee
In GIPC by blocking on a bounder buffer associated with the callee site
On receiving synchronization message, callee site produces the return value in the bounded buffer associated with callee site