예제 #1
0
  /**
   * Setup response for the IPC Call.
   *
   * @param response buffer to serialize the response into
   * @param call {@link Call} to which we are setting up the response
   * @param status {@link Status} of the IPC call
   * @param rv return value for the IPC Call, if the call was successful
   * @param errorClass error class, if the the call failed
   * @param error error message, if the call failed
   * @throws IOException
   */
  private void setupResponse(
      ByteArrayOutputStream response,
      Call call,
      Status status,
      IOReadableWritable rv,
      String errorClass,
      String error)
      throws IOException {
    response.reset();
    DataOutputStream out = new DataOutputStream(response);
    out.writeInt(call.id); // write call id
    out.writeInt(status.state); // write status

    if (status == Status.SUCCESS) {
      if (rv == null) {
        out.writeBoolean(false);
      } else {
        out.writeBoolean(true);
        StringRecord.writeString(out, rv.getClass().getName());
        rv.write(out);
      }

    } else {
      StringRecord.writeString(out, errorClass);
      StringRecord.writeString(out, error);
    }
    call.setResponse(ByteBuffer.wrap(response.toByteArray()));
  }
예제 #2
0
 protected void customRun() throws InterruptedException {
   if (outRunnable.reconnection.get()) {
     Thread.sleep(10L);
     return;
   }
   Packet packet;
   try {
     Connection oldConnection = connection;
     connection = client.connectionManager.getConnection();
     if (restoredConnection(oldConnection, connection)) {
       if (outRunnable.sendReconnectCall(connection)) {
         logger.log(Level.FINEST, "restoredConnection");
         if (oldConnection != null) {
           redoUnfinishedCalls(oldConnection);
         }
       }
       return;
     }
     if (connection == null) {
       outRunnable.clusterIsDown(oldConnection);
       Thread.sleep(10);
     } else {
       packet = reader.readPacket(connection);
       //                logger.log(Level.FINEST, "Reading " + packet.getOperation() + " Call id: "
       // + packet.getCallId());
       this.lastReceived = System.currentTimeMillis();
       Call call = callMap.remove(packet.getCallId());
       if (call != null) {
         call.received = System.nanoTime();
         call.setResponse(packet);
       } else {
         if (packet.getOperation().equals(ClusterOperation.EVENT)) {
           client.getListenerManager().enqueue(packet);
         }
         if (packet.getCallId() != -1) {
           logger.log(
               Level.SEVERE,
               "In Thread can not handle: " + packet.getOperation() + " : " + packet.getCallId());
         }
       }
     }
   } catch (Throwable e) {
     logger.log(
         Level.FINEST, "InRunnable [" + connection + "] got an exception:" + e.toString(), e);
     outRunnable.clusterIsDown(connection);
   }
 }