Allow remote calls to be made on the default channel

instead of just custom channels.  Custom channels are
0-max channel while -1 indicates the default send().
experimental
Paul Speed 10 years ago
parent dd65580bf3
commit 96dab5f561
  1. 23
      jme3-networking/src/main/java/com/jme3/network/service/rpc/RpcConnection.java

@ -116,7 +116,11 @@ public class RpcConnection {
if( log.isLoggable(Level.FINEST) ) { if( log.isLoggable(Level.FINEST) ) {
log.log(Level.FINEST, "Sending:{0} on channel:{1}", new Object[]{msg, channel}); log.log(Level.FINEST, "Sending:{0} on channel:{1}", new Object[]{msg, channel});
} }
connection.send(channel, msg); if( channel >= 0 ) {
connection.send(channel, msg);
} else {
connection.send(msg);
}
return holder.getResponse(); return holder.getResponse();
} }
@ -159,6 +163,14 @@ public class RpcConnection {
handlers.remove(objId); handlers.remove(objId);
} }
protected void send( byte channel, RpcResponseMessage msg ) {
if( channel >= 0 ) {
connection.send(channel, msg);
} else {
connection.send(msg);
}
}
/** /**
* Called internally when an RpcCallMessage is received from * Called internally when an RpcCallMessage is received from
* the remote connection. * the remote connection.
@ -170,15 +182,16 @@ public class RpcConnection {
} }
RpcHandler handler = handlers.get(msg.getObjectId()); RpcHandler handler = handlers.get(msg.getObjectId());
try { try {
if( handler == null ) {
throw new RuntimeException("Handler not found for objectID:" + msg.getObjectId());
}
Object result = handler.call(this, msg.getObjectId(), msg.getProcedureId(), msg.getArguments()); Object result = handler.call(this, msg.getObjectId(), msg.getProcedureId(), msg.getArguments());
if( !msg.isAsync() ) { if( !msg.isAsync() ) {
RpcResponseMessage response = new RpcResponseMessage(msg.getMessageId(), result); send(msg.getChannel(), new RpcResponseMessage(msg.getMessageId(), result));
connection.send(msg.getChannel(), response);
} }
} catch( Exception e ) { } catch( Exception e ) {
if( !msg.isAsync() ) { if( !msg.isAsync() ) {
RpcResponseMessage response = new RpcResponseMessage(msg.getMessageId(), e); send(msg.getChannel(), new RpcResponseMessage(msg.getMessageId(), e));
connection.send(msg.getChannel(), response);
} else { } else {
log.log(Level.SEVERE, "Error invoking async call for:" + msg, e); log.log(Level.SEVERE, "Error invoking async call for:" + msg, e);
} }

Loading…
Cancel
Save