Java Code Examples for org.msgpack.core.MessageUnpacker#unpackLong()

The following examples show how to use org.msgpack.core.MessageUnpacker#unpackLong() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MaestroDeserializer.java    From maestro-java with Apache License 2.0 6 votes vote down vote up
private static MaestroData deserializeData(final MessageUnpacker unpacker) throws IOException, MalformedNoteException {
    final long tmpCommand = unpacker.unpackLong();
    final MaestroCommand command = MaestroCommand.from(tmpCommand);

    switch (Objects.requireNonNull(command)) {
        case MAESTRO_NOTE_LOG: {
            LogResponseJoiner instance = LogResponseJoiner.getInstance();

            return instance.join(new LogResponse(unpacker));
        }
        default: {
            logger.error("Type unknown: {}", command.getClass());
            throw new MalformedNoteException("Invalid response command: " + tmpCommand);
        }
    }
}
 
Example 2
Source File: MaestroDeserializer.java    From maestro-java with Apache License 2.0 5 votes vote down vote up
private static MaestroNotification deserializeNotification(final MessageUnpacker unpacker)
        throws IOException, MalformedNoteException
{
    final long tmpCommand = unpacker.unpackLong();
    final MaestroCommand command = MaestroCommand.from(tmpCommand);

    switch (Objects.requireNonNull(command)) {
        case MAESTRO_NOTE_NOTIFY_FAIL: {
            return new TestFailedNotification(unpacker);
        }
        case MAESTRO_NOTE_NOTIFY_SUCCESS: {
            return new TestSuccessfulNotification(unpacker);
        }
        case MAESTRO_NOTE_ABNORMAL_DISCONNECT: {
            return new AbnormalDisconnect(unpacker);
        }
        case MAESTRO_NOTE_NOTIFY_DRAIN_COMPLETE: {
            return new DrainCompleteNotification(unpacker);
        }
        case MAESTRO_NOTE_NOTIFY_TEST_STARTED: {
            return new TestStartedNotification(unpacker);
        }
        default: {
            throw new MalformedNoteException("Invalid notification command: " + tmpCommand);
       }
    }
}
 
Example 3
Source File: UserCommand1Request.java    From maestro-java with Apache License 2.0 5 votes vote down vote up
public UserCommand1Request(MessageUnpacker unpacker) throws IOException {
    super(MaestroCommand.MAESTRO_NOTE_USER_COMMAND_1, unpacker);

    if (unpacker.hasNext()) {
        this.option = unpacker.unpackLong();
    }

    if (unpacker.hasNext()) {
        this.payload = unpacker.unpackString();
    }
}
 
Example 4
Source File: StatsResponse.java    From maestro-java with Apache License 2.0 5 votes vote down vote up
public StatsResponse(final MessageUnpacker unpacker) throws IOException {
    super(MaestroCommand.MAESTRO_NOTE_STATS, unpacker);

    childCount = unpacker.unpackInt();
    roleInfo = unpacker.unpackString();
    statsType = unpacker.unpackShort();

    timestamp = unpacker.unpackString();
    count = unpacker.unpackLong();
    rate = unpacker.unpackDouble();
    latency = unpacker.unpackDouble();
}
 
Example 5
Source File: Deserializer.java    From tinkergraph-gremlin with Apache License 2.0 5 votes vote down vote up
/**
 * format: `Map<Label, Array<EdgeId>>`
 */
private Map<String, long[]> unpackEdgeIdsByLabel(MessageUnpacker unpacker) throws IOException {
  int labelCount = unpacker.unpackMapHeader();
  Map<String, long[]> edgeIdsByLabel = new THashMap<>(labelCount);
  for (int i = 0; i < labelCount; i++) {
    String label = unpacker.unpackString();
    int edgeIdsCount = unpacker.unpackArrayHeader();
    long[] edgeIds = new long[edgeIdsCount];
    for (int j = 0; j < edgeIdsCount; j++) {
      edgeIds[j] = unpacker.unpackLong();
    }
    edgeIdsByLabel.put(label, edgeIds);
  }
  return edgeIdsByLabel;
}
 
Example 6
Source File: MaestroDeserializer.java    From maestro-java with Apache License 2.0 4 votes vote down vote up
private static MaestroResponse deserializeResponse(final MessageUnpacker unpacker)
        throws IOException, MalformedNoteException
{
    final long tmpCommand = unpacker.unpackLong();
    final MaestroCommand command = MaestroCommand.from(tmpCommand);

    switch (Objects.requireNonNull(command)) {
        case MAESTRO_NOTE_OK: {
            return new OkResponse(unpacker);
        }
        case MAESTRO_NOTE_PING: {
            return new PingResponse(unpacker);
        }
        case MAESTRO_NOTE_INTERNAL_ERROR: {
            return new InternalError(unpacker);
        }
        case MAESTRO_NOTE_PROTOCOL_ERROR: {
            return new ProtocolError();
        }
        case MAESTRO_NOTE_STATS: {
            return new StatsResponse(unpacker);
        }
        case MAESTRO_NOTE_GET: {
            return new GetResponse(unpacker);
        }
        case MAESTRO_NOTE_USER_COMMAND_1: {
            return new UserCommand1Response(unpacker);
        }
        case MAESTRO_NOTE_START_WORKER:
        case MAESTRO_NOTE_STOP_WORKER:
        case MAESTRO_NOTE_START_INSPECTOR:
        case MAESTRO_NOTE_STOP_INSPECTOR:
        case MAESTRO_NOTE_SET:
        case MAESTRO_NOTE_HALT:
        case MAESTRO_NOTE_START_AGENT:
        case MAESTRO_NOTE_STOP_AGENT:{
            logger.warn("Unexpected maestro command for a response: {}", tmpCommand);
            throw new MalformedNoteException("Invalid response command: " + tmpCommand);
        }
        default: {
            logger.error("Type unknown: {}", command.getClass());
            throw new MalformedNoteException("Invalid response command: " + tmpCommand);
        }
    }

}
 
Example 7
Source File: MaestroDeserializer.java    From maestro-java with Apache License 2.0 4 votes vote down vote up
private static MaestroRequest deserializeRequest(final MessageUnpacker unpacker) throws IOException, MalformedNoteException {
    final long tmpCommand = unpacker.unpackLong();
    final MaestroCommand command = MaestroCommand.from(tmpCommand);

    switch (Objects.requireNonNull(command)) {
        case MAESTRO_NOTE_PING: {
            return new PingRequest(unpacker);
        }
        case MAESTRO_NOTE_STATS: {
            return new StatsRequest(unpacker);
        }
        case MAESTRO_NOTE_START_WORKER: {
            return new StartWorker(unpacker);
        }
        case MAESTRO_NOTE_STOP_WORKER: {
            return new StopWorker(unpacker);
        }
        case MAESTRO_NOTE_START_INSPECTOR: {
            return new StartInspector(unpacker);
        }
        case MAESTRO_NOTE_STOP_INSPECTOR: {
            return new StopInspector(unpacker);
        }
        case MAESTRO_NOTE_SET: {
            return new SetRequest(unpacker);
        }
        case MAESTRO_NOTE_HALT: {
            return new Halt(unpacker);
        }
        case MAESTRO_NOTE_GET: {
            return new GetRequest(unpacker);
        }
        case MAESTRO_NOTE_START_AGENT: {
            return new StartAgent(unpacker);
        }
        case MAESTRO_NOTE_STOP_AGENT: {
            return new StopAgent(unpacker);
        }
        case MAESTRO_NOTE_USER_COMMAND_1: {
            return new UserCommand1Request(unpacker);
        }
        case MAESTRO_NOTE_AGENT_SOURCE: {
            return new AgentSourceRequest(unpacker);
        }
        case MAESTRO_NOTE_LOG: {
            return new LogRequest(unpacker);
        }
        case MAESTRO_NOTE_DRAIN: {
            return new DrainRequest(unpacker);
        }
        case MAESTRO_NOTE_GROUP_JOIN: {
            return new GroupJoinRequest(unpacker);
        }
        case MAESTRO_NOTE_GROUP_LEAVE: {
            return new GroupLeaveRequest(unpacker);
        }
        case MAESTRO_NOTE_ROLE_ASSIGN: {
            return new RoleAssign(unpacker);
        }
        case MAESTRO_NOTE_ROLE_UNASSIGN: {
            return new RoleUnassign(unpacker);
        }
        case MAESTRO_NOTE_START_TEST: {
            return new StartTestRequest(unpacker);
        }
        case MAESTRO_NOTE_STOP_TEST: {
            return new StopTestRequest(unpacker);
        }
        default: {
            throw new MalformedNoteException("Invalid request command: " + tmpCommand);
        }
    }
}
 
Example 8
Source File: PingResponse.java    From maestro-java with Apache License 2.0 4 votes vote down vote up
public PingResponse(final MessageUnpacker unpacker) throws IOException {
    super(MaestroCommand.MAESTRO_NOTE_PING, unpacker);

    elapsed = unpacker.unpackLong();
}
 
Example 9
Source File: PingRequest.java    From maestro-java with Apache License 2.0 4 votes vote down vote up
public PingRequest(MessageUnpacker unpacker) throws IOException {
    super(MaestroCommand.MAESTRO_NOTE_PING, unpacker);

    sec = unpacker.unpackLong();
    usec = unpacker.unpackLong();
}
 
Example 10
Source File: PackedBuffer.java    From incubator-retired-htrace with Apache License 2.0 4 votes vote down vote up
/**
 * Read a span.  Used in unit tests.  Not optimized.
 */
static Span readSpan(MessageUnpacker unpacker) throws IOException {
  int numEntries = unpacker.unpackMapHeader();
  MilliSpan.Builder builder = new MilliSpan.Builder();
  while (--numEntries >= 0) {
    String key = unpacker.unpackString();
    if (key.length() != 1) {
      throw new IOException("Unknown key " + key);
    }
    switch (key.charAt(0)) {
      case 'a':
        builder.spanId(readSpanId(unpacker));
        break;
      case 'b':
        builder.begin(unpacker.unpackLong());
        break;
      case 'e':
        builder.end(unpacker.unpackLong());
        break;
      case 'd':
        builder.description(unpacker.unpackString());
        break;
      case 'r':
        builder.tracerId(unpacker.unpackString());
        break;
      case 'p':
        int numParents = unpacker.unpackArrayHeader();
        SpanId[] parents = new SpanId[numParents];
        for (int i = 0; i < numParents; i++) {
          parents[i] = readSpanId(unpacker);
        }
        builder.parents(parents);
        break;
      case 'n':
        int mapEntries = unpacker.unpackMapHeader();
        HashMap<String, String> entries =
            new HashMap<String, String>(mapEntries);
        for (int i = 0; i < mapEntries; i++) {
          String k = unpacker.unpackString();
          String v = unpacker.unpackString();
          entries.put(k, v);
        }
        builder.traceInfo(entries);
        break;
      case 't':
        int listEntries = unpacker.unpackArrayHeader();
        ArrayList<TimelineAnnotation> list =
            new ArrayList<TimelineAnnotation>(listEntries);
        for (int i = 0; i < listEntries; i++) {
          int timelineObjectSize = unpacker.unpackMapHeader();
          long time = 0;
          String msg = "";
          for (int j = 0; j < timelineObjectSize; j++) {
            String tlKey = unpacker.unpackString();
            if (tlKey.length() != 1) {
              throw new IOException("Unknown timeline map key " + tlKey);
            }
            switch (tlKey.charAt(0)) {
              case 't':
                time = unpacker.unpackLong();
                break;
              case 'm':
                msg = unpacker.unpackString();
                break;
              default:
                throw new IOException("Unknown timeline map key " + tlKey);
            }
          }
          list.add(new TimelineAnnotation(time, msg));
        }
        builder.timeline(list);
        break;
      default:
        throw new IOException("Unknown key " + key);
    }
  }
  return builder.build();
}