public WriteRequest unmarshall(JsonUnmarshallerContext context) throws Exception {
    WriteRequest writeRequest = new WriteRequest();

    int originalDepth = context.getCurrentDepth();
    int targetDepth = originalDepth + 1;

    JsonToken token = context.currentToken;
    if (token == null) token = context.nextToken();

    while (true) {
      if (token == null) break;

      if (token == FIELD_NAME || token == START_OBJECT) {
        if (context.testExpression("PutRequest", targetDepth)) {
          context.nextToken();
          writeRequest.setPutRequest(PutRequestJsonUnmarshaller.getInstance().unmarshall(context));
        }
        if (context.testExpression("DeleteRequest", targetDepth)) {
          context.nextToken();
          writeRequest.setDeleteRequest(
              DeleteRequestJsonUnmarshaller.getInstance().unmarshall(context));
        }
      } else if (token == END_ARRAY || token == END_OBJECT) {
        if (context.getCurrentDepth() <= originalDepth) break;
      }

      token = context.nextToken();
    }

    return writeRequest;
  }
Example #2
0
 public CompletableFuture<Boolean> writeStream(
     long address, Map<UUID, Long> streamAddresses, ByteBuf buffer) {
   WriteRequest wr = new WriteRequest(WriteMode.REPLEX_STREAM, streamAddresses, buffer);
   wr.setLogicalAddresses(streamAddresses);
   wr.setGlobalAddress(address);
   return router.sendMessageAndGetCompletable(CorfuMsgType.WRITE.payloadMsg(wr));
 }
Example #3
0
 /**
  * Asynchronously write to the logging unit.
  *
  * @param address The address to write to.
  * @param streams The streams, if any, that this write belongs to.
  * @param rank The rank of this write (used for quorum replication).
  * @param buffer The object, post-serialization, to write.
  * @param backpointerMap The map of backpointers to write.
  * @return A CompletableFuture which will complete with the WriteResult once the write completes.
  */
 public CompletableFuture<Boolean> write(
     long address, Set<UUID> streams, long rank, ByteBuf buffer, Map<UUID, Long> backpointerMap) {
   WriteRequest wr = new WriteRequest(WriteMode.NORMAL, null, buffer);
   wr.setStreams(streams);
   wr.setRank(rank);
   wr.setBackpointerMap(backpointerMap);
   wr.setGlobalAddress(address);
   return router.sendMessageAndGetCompletable(CorfuMsgType.WRITE.payloadMsg(wr));
 }
Example #4
0
 /**
  * Asynchronously write to the logging unit.
  *
  * @param address The address to write to.
  * @param streams The streams, if any, that this write belongs to.
  * @param rank The rank of this write (used for quorum replication).
  * @param writeObject The object, pre-serialization, to write.
  * @param backpointerMap The map of backpointers to write.
  * @return A CompletableFuture which will complete with the WriteResult once the write completes.
  */
 public CompletableFuture<Boolean> write(
     long address,
     Set<UUID> streams,
     long rank,
     Object writeObject,
     Map<UUID, Long> backpointerMap) {
   ByteBuf payload = ByteBufAllocator.DEFAULT.buffer();
   Serializers.getSerializer(CORFU).serialize(writeObject, payload);
   WriteRequest wr = new WriteRequest(WriteMode.NORMAL, null, payload);
   wr.setStreams(streams);
   wr.setRank(rank);
   wr.setBackpointerMap(backpointerMap);
   wr.setGlobalAddress(address);
   return router.sendMessageAndGetCompletable(CorfuMsgType.WRITE.payloadMsg(wr));
 }
Example #5
0
  private void doNextWrite() {
    WriteRequest writeRequest;
    synchronized (writeRequests) {
      writeRequest = writeRequests.peek();
    }

    if (writeRequest != null) {
      try {
        if (channelPutValueField == null) throw new RuntimeException("No 'value' field");

        fromObject(channelPutValueField, writeRequest.getNewValue());
        channelPut.put(false);
      } catch (Exception ex) {
        writeRequests.poll();
        writeRequest.getCallback().channelWritten(ex);
      }
    }
  }
Example #6
0
  /* (non-Javadoc)
   * @see org.epics.pvaccess.client.ChannelPutRequester#putDone(org.epics.pvdata.pv.Status)
   */
  @Override
  public void putDone(Status status) {
    reportStatus("Failed to put value", status);

    WriteRequest writeRequest;
    synchronized (writeRequests) {
      writeRequest = writeRequests.poll();
    }

    if (writeRequest != null) {
      if (status.isSuccess()) {
        writeRequest.getCallback().channelWritten(null);
      } else {
        writeRequest.getCallback().channelWritten(new Exception(status.getMessage()));
      }

      doNextWrite();
    }
  }