/**
  * Calls a method remotely over the channel. Does nothing if {@link #isDroppedOut()} flag is set.
  *
  * @param id The ID of the method.
  * @param messageNumber The message number.
  * @param args The arguments.
  */
 protected void callRemoteMethod(final short id, final long messageNumber, final Object... args) {
   if (!cluster.channel.isConnected()) {
     return;
   }
   MethodCall call = createMethodCall(id, messageNumber, args);
   try {
     dispatcher.callRemoteMethods(null, call, ASYNC_REQUEST_OPTIONS);
     LOGGER.info(
         "Method called: "
             + methods.findMethod(id).getName()
             + " "
             + Arrays.toString(call.getArgs()));
   } catch (Exception e) {
     throw new RuntimeException(
         "Cannot call "
             + methods.findMethod(id)
             + " with parameters "
             + Arrays.toString(call.getArgs()),
         e);
   }
 }
Ejemplo n.º 2
0
 public Buffer objectToBuffer(Object obj) throws Exception {
   MethodCall call = (MethodCall) obj;
   ByteBuffer buf;
   switch (call.getId()) {
     case START:
     case GET_CONFIG:
       buf = ByteBuffer.allocate(Global.BYTE_SIZE);
       buf.put((byte) call.getId());
       return new Buffer(buf.array());
     case SET_OOB:
     case SET_SYNC:
       return new Buffer(booleanBuffer(call.getId(), (Boolean) call.getArgs()[0]));
     case SET_NUM_MSGS:
     case SET_NUM_THREADS:
     case SET_MSG_SIZE:
     case SET_ANYCAST_COUNT:
       return new Buffer(intBuffer(call.getId(), (Integer) call.getArgs()[0]));
     case GET:
       return new Buffer(longBuffer(call.getId(), (Long) call.getArgs()[0]));
     case PUT:
       Long long_arg = (Long) call.getArgs()[0];
       byte[] arg2 = (byte[]) call.getArgs()[1];
       buf =
           ByteBuffer.allocate(
               Global.BYTE_SIZE + Global.INT_SIZE + Global.LONG_SIZE + arg2.length);
       buf.put((byte) call.getId())
           .putLong(long_arg)
           .putInt(arg2.length)
           .put(arg2, 0, arg2.length);
       return new Buffer(buf.array());
     case SET_READ_PERCENTAGE:
       Double double_arg = (Double) call.getArgs()[0];
       buf = ByteBuffer.allocate(Global.BYTE_SIZE + Global.DOUBLE_SIZE);
       buf.put((byte) call.getId()).putDouble(double_arg);
       return new Buffer(buf.array());
     default:
       throw new IllegalStateException("method " + call.getMethod() + " not known");
   }
 }