@@ -50,9 +50,9 @@ public void onTransportMessage(String senderEndpointAddress,
5050
5151 Object pdu = _messageSerializer .serializeFrom (message );
5252 if (pdu instanceof RpcCallRequestPdu ) {
53- handleCallRequestPdu ((RpcCallRequestPdu )pdu );
53+ handleCallRequestPdu (senderEndpointAddress , targetEndpointAddress , (RpcCallRequestPdu )pdu );
5454 } else if (pdu instanceof RpcCallResponsePdu ) {
55- handleCallResponsePdu ((RpcCallResponsePdu )pdu );
55+ handleCallResponsePdu (senderEndpointAddress , targetEndpointAddress , (RpcCallResponsePdu )pdu );
5656 } else {
5757 assert (false );
5858 }
@@ -81,7 +81,7 @@ public void unregisteRpcServiceEndpoint(RpcServiceEndpoint rpcEndpoint) {
8181 _serviceEndpoints .remove (rpcEndpoint );
8282 }
8383 }
84-
84+
8585 @ Override
8686 public RpcClientCall newCall (String sourceAddress , String targetAddress ) {
8787 long callTag = getNextCallTag ();
@@ -124,11 +124,42 @@ protected synchronized long getNextCallTag() {
124124 return tag ;
125125 }
126126
127- private void handleCallRequestPdu (RpcCallRequestPdu pdu ) {
128- // ???
127+ private void handleCallRequestPdu (String sourceAddress , String targetAddress , RpcCallRequestPdu pdu ) {
128+ try {
129+ RpcServerCall call = new RpcServerCallImpl (this , sourceAddress , targetAddress , pdu );
130+
131+ // TODO, we are trying to avoid locking when calling into callbacks
132+ // this can be optimized later
133+ List <RpcServiceEndpoint > endpoints = new ArrayList <RpcServiceEndpoint >();
134+ synchronized (_serviceEndpoints ) {
135+ endpoints .addAll (_serviceEndpoints );
136+ }
137+
138+ for (RpcServiceEndpoint endpoint : endpoints ) {
139+ if (RpcServiceDispatcher .dispatch (endpoint , call ))
140+ return ;
141+ }
142+
143+ RpcCallResponsePdu responsePdu = new RpcCallResponsePdu ();
144+ responsePdu .setCommand (pdu .getCommand ());
145+ responsePdu .setRequestStartTick (pdu .getRequestStartTick ());
146+ responsePdu .setRequestTag (pdu .getRequestTag ());
147+ responsePdu .setResult (RpcCallResponsePdu .RESULT_HANDLER_NOT_EXIST );
148+ sendRpcPdu (targetAddress , sourceAddress , _messageSerializer .serializeTo (RpcCallResponsePdu .class , responsePdu ));
149+
150+ } catch (Throwable e ) {
151+
152+ RpcCallResponsePdu responsePdu = new RpcCallResponsePdu ();
153+ responsePdu .setCommand (pdu .getCommand ());
154+ responsePdu .setRequestStartTick (pdu .getRequestStartTick ());
155+ responsePdu .setRequestTag (pdu .getRequestTag ());
156+ responsePdu .setResult (RpcCallResponsePdu .RESULT_HANDLER_EXCEPTION );
157+
158+ sendRpcPdu (targetAddress , sourceAddress , _messageSerializer .serializeTo (RpcCallResponsePdu .class , responsePdu ));
159+ }
129160 }
130161
131- private void handleCallResponsePdu (RpcCallResponsePdu pdu ) {
162+ private void handleCallResponsePdu (String sourceAddress , String targetAddress , RpcCallResponsePdu pdu ) {
132163 RpcClientCallImpl call = null ;
133164
134165 synchronized (this ) {
0 commit comments