コード例 #1
0
 private void logYamlToStandardOut(@NotNull WireIn in) {
   if (YamlLogging.showServerReads) {
     try {
       LOG.info("\nServer Receives:\n" + Wires.fromSizePrefixedBlobs(in.bytes()));
     } catch (Exception e) {
       LOG.info("\n\n" + Bytes.toString(in.bytes()));
     }
   }
 }
コード例 #2
0
 @Override
 public void readMarshallable(@NotNull WireIn wire) throws IllegalStateException {
   wire.read(() -> "wireType").asEnum(WireType.class, wt -> wireType = wt);
   wire.read(() -> "port").int32(this, (o, i) -> o.port = i);
   wire.read(() -> "logTCPMessages")
       .asEnum(YamlLogging.YamlLoggingLevel.class, this, (o, b) -> o.logTCPMessages = b);
   wire.read(() -> "heartbeatIntervalTicks").int32(this, (o, i) -> o.heartbeatIntervalTicks = i);
   wire.read(() -> "heartbeatIntervalTimeout")
       .int32(this, (o, i) -> o.heartbeatIntervalTimeout = i);
 }
コード例 #3
0
 private void logToBuffer(@NotNull WireIn in, StringBuilder logBuffer) {
   if (YamlLogging.showServerReads) {
     logBuffer.setLength(0);
     try {
       logBuffer.append("\nServer Receives:\n" + Wires.fromSizePrefixedBlobs(in.bytes()));
     } catch (Exception e) {
       logBuffer.append("\n\n" + Bytes.toString(in.bytes()));
     }
   }
 }
コード例 #4
0
 private void readTid(@NotNull WireIn metaDataWire) {
   ValueIn valueIn = metaDataWire.readEventName(eventName);
   if (CoreFields.tid.contentEquals(eventName)) {
     tid = valueIn.int64();
     eventName.setLength(0);
   } else tid = -1;
 }
コード例 #5
0
  /** peeks the csp or if it has a cid converts the cid into a Csp and returns that */
  private void readCsp(@NotNull final WireIn wireIn) {
    final StringBuilder keyName = Wires.acquireStringBuilder();

    cspText.setLength(0);
    final ValueIn read = wireIn.readEventName(keyName);
    if (csp.contentEquals(keyName)) {
      read.textTo(cspText);

    } else if (cid.contentEquals(keyName)) {
      final long cid = read.int64();
      final CharSequence s = mapWireHandler.getCspForCid(cid);
      cspText.append(s);
    }
  }
コード例 #6
0
  public static void rawReadData(@NotNull WireIn wireIn, @NotNull ReadMarshallable dataConsumer) {
    final Bytes<?> bytes = wireIn.bytes();
    int header = bytes.readInt();
    assert Wires.isReady(header) && Wires.isData(header);
    final int len = Wires.lengthOf(header);

    long limit0 = bytes.readLimit();
    long limit = bytes.readPosition() + (long) len;
    try {
      bytes.readLimit(limit);
      dataConsumer.readMarshallable(wireIn);
    } finally {
      bytes.readLimit(limit0);
    }
  }
コード例 #7
0
  public static boolean readData(
      @NotNull WireIn wireIn,
      @Nullable ReadMarshallable metaDataConsumer,
      @Nullable ReadMarshallable dataConsumer) {
    final Bytes<?> bytes = wireIn.bytes();
    boolean read = false;
    while (bytes.readRemaining() >= 4) {
      long position = bytes.readPosition();
      int header = bytes.readVolatileInt(position);
      if (!isKnownLength(header)) return read;
      bytes.readSkip(4);
      final boolean ready = Wires.isReady(header);
      final int len = Wires.lengthOf(header);
      if (Wires.isData(header)) {
        if (dataConsumer == null) {
          return false;

        } else {
          ((InternalWireIn) wireIn).setReady(ready);
          bytes.readWithLength(len, b -> dataConsumer.readMarshallable(wireIn));
          return true;
        }
      } else {

        if (metaDataConsumer == null) {
          // skip the header
          bytes.readSkip(len);
        } else {
          // bytes.readWithLength(len, b -> metaDataConsumer.accept(wireIn));
          // inlined to avoid garbage
          if ((long) len > bytes.readRemaining()) throw new BufferUnderflowException();
          long limit0 = bytes.readLimit();
          long limit = bytes.readPosition() + (long) len;
          try {
            bytes.readLimit(limit);
            metaDataConsumer.readMarshallable(wireIn);
          } finally {
            bytes.readLimit(limit0);
            bytes.readPosition(limit);
          }
        }

        if (dataConsumer == null) return true;
        read = true;
      }
    }
    return read;
  }
コード例 #8
0
  public static boolean readData(
      long offset,
      @NotNull WireIn wireIn,
      @Nullable ReadMarshallable metaDataConsumer,
      @Nullable ReadMarshallable dataConsumer) {
    final Bytes bytes = wireIn.bytes();

    long position = bytes.readPosition();
    long limit = bytes.readLimit();
    try {
      bytes.readLimit(bytes.isElastic() ? bytes.capacity() : bytes.realCapacity());
      bytes.readPosition(offset);
      return readData(wireIn, metaDataConsumer, dataConsumer);
    } finally {
      bytes.readLimit(limit);
      bytes.readPosition(position);
    }
  }
コード例 #9
0
 @Override
 public void readMarshallable(@NotNull WireIn wire) throws IORuntimeException {
   wire.read(() -> "text")
       .text(this, (t, v) -> t.text = v)
       .read(() -> "wireType")
       .object(WireType.class, this, (t, v) -> t.wireType = v)
       .read(() -> "listA")
       .sequence(
           this,
           (t, v) -> {
             t.clearListA();
             while (v.hasNextSequenceItem()) v.marshallable(addListA());
             Thread.yield();
           })
       .read(() -> "listB")
       .sequence(
           this,
           (t, v) -> {
             t.clearListB();
             while (v.hasNextSequenceItem()) v.marshallable(addListB());
           });
 }
コード例 #10
0
 @Override
 public void readMarshallable(WireIn wireIn) throws IllegalStateException {
   this.type = OperationType.valueOf(wireIn.read(() -> "type").text());
   this.wrapped = wireIn.read(() -> "wrapped").object(Object.class);
 }
コード例 #11
0
  @Override
  protected void process(
      @NotNull final WireIn in,
      @NotNull final WireOut out,
      @NotNull final SessionDetailsProvider sessionDetails) {

    if (!YamlLogging.showHeartBeats) {
      // save the previous message (the meta-data for printing later)
      // if the message turns out not to be a system message
      prevLogMessage.setLength(0);
      prevLogMessage.append(currentLogMessage);
      currentLogMessage.setLength(0);
      logToBuffer(in, currentLogMessage);
    } else {
      // log every message
      logYamlToStandardOut(in);
    }

    if (sessionProvider != null) sessionProvider.set(sessionDetails);

    in.readDocument(
        this.metaDataConsumer,
        (WireIn wire) -> {
          try {

            if (LOG.isDebugEnabled()) LOG.debug("received data:\n" + wire.bytes().toHexString());

            if (isSystemMessage) {
              systemHandler.process(in, out, tid, sessionDetails, getMonitoringMap());
              if (!systemHandler.wasHeartBeat()) {
                if (!YamlLogging.showHeartBeats) {
                  logBufferToStandardOut(prevLogMessage.append(currentLogMessage));
                }
              }
              return;
            }

            if (!YamlLogging.showHeartBeats) {
              logBufferToStandardOut(prevLogMessage.append(currentLogMessage));
            }

            Map<String, UserStat> userMonitoringMap = getMonitoringMap();
            if (userMonitoringMap != null) {
              UserStat userStat = userMonitoringMap.get(sessionDetails.userId());
              if (userStat == null) {
                throw new AssertionError("User should have been logged in");
              }
              // Use timeInMillis
              userStat.setRecentInteraction(LocalTime.now());
              userStat.setTotalInteractions(userStat.getTotalInteractions() + 1);
              userMonitoringMap.put(sessionDetails.userId(), userStat);
            }

            if (wireAdapter != null) {

              if (viewType == MapView.class) {
                mapWireHandler.process(in, out, (MapView) view, tid, wireAdapter, requestContext);
                return;
              }

              if (viewType == EntrySetView.class) {
                entrySetHandler.process(
                    in,
                    out,
                    (EntrySetView) view,
                    wireAdapter.entryToWire(),
                    wireAdapter.wireToEntry(),
                    HashSet::new,
                    tid);
                return;
              }

              if (viewType == KeySetView.class) {
                keySetHandler.process(
                    in,
                    out,
                    (KeySetView) view,
                    wireAdapter.keyToWire(),
                    wireAdapter.wireToKey(),
                    HashSet::new,
                    tid);
                return;
              }

              if (viewType == ValuesCollection.class) {
                valuesHandler.process(
                    in,
                    out,
                    (ValuesCollection) view,
                    wireAdapter.keyToWire(),
                    wireAdapter.wireToKey(),
                    ArrayList::new,
                    tid);
                return;
              }

              if (viewType == ObjectKVSSubscription.class) {
                subscriptionHandler.process(
                    in,
                    requestContext,
                    publisher,
                    assetTree,
                    tid,
                    outWire,
                    (SubscriptionCollection) view);
                return;
              }

              if (viewType == TopologySubscription.class) {
                topologySubscriptionHandler.process(
                    in,
                    requestContext,
                    publisher,
                    assetTree,
                    tid,
                    outWire,
                    (TopologySubscription) view);
                return;
              }

              if (viewType == Reference.class) {
                referenceHandler.process(
                    in, publisher, tid, (Reference) view, cspText, outWire, wireAdapter);
                return;
              }

              if (viewType == TopicPublisher.class) {
                topicPublisherHandler.process(
                    in, publisher, tid, outWire, (TopicPublisher) view, wireAdapter);
                return;
              }

              if (viewType == Publisher.class) {
                publisherHandler.process(
                    in, publisher, tid, (Publisher) view, outWire, wireAdapter);
                return;
              }

              if (viewType == Replication.class) {
                replicationHandler.process(
                    in, publisher, tid, outWire, hostIdentifier, (Replication) view, eventLoop);
                return;
              }
            }

            if (endsWith(cspText, "?view=queue")) {
              // TODO add in chronicle queue
            }

          } catch (Exception e) {
            LOG.error("", e);
          } finally {
            if (sessionProvider != null) sessionProvider.remove();
          }
        });
  }
コード例 #12
0
 @Override
 public void readMarshallable(@NotNull WireIn wire) {
   wire.read(() -> "262").text(text);
 }
コード例 #13
0
        @Override
        public void readMarshallable(WireIn wire) throws IllegalStateException {
          @SuppressWarnings("ConstantConditions")
          final Bytes<?> outBytes = outWire.bytes();

          try {

            final StringBuilder eventName = Wires.acquireStringBuilder();
            @SuppressWarnings("ConstantConditions")
            final ValueIn valueIn = inWire.readEventName(eventName);

            outWire.writeDocument(
                true, w -> w.writeEventName(CoreFields.tid).int64(CollectionWireHandler.this.tid));

            outWire.writeDocument(
                false,
                out -> {

                  // note :  remove on the key-set returns a boolean and on the map returns the
                  // old value
                  if (EventId.remove.contentEquals(eventName)) {
                    outWire
                        .write(CoreFields.reply)
                        .bool(underlyingCollection.remove(fromWire.apply(valueIn)));
                    return;
                  }

                  // note :  remove on the key-set returns a boolean and on the map returns the
                  // old value
                  if (EventId.iterator.contentEquals(eventName)) {
                    final ValueOut valueOut = out.writeEventName(CoreFields.reply);
                    valueOut.sequence(v -> underlyingCollection.forEach(e -> toWire.accept(v, e)));
                    return;
                  }

                  if (EventId.numberOfSegments.contentEquals(eventName)) {
                    outWire.write(CoreFields.reply).int32(1);
                    return;
                  }

                  if (EventId.isEmpty.contentEquals(eventName)) {
                    outWire.write(CoreFields.reply).bool(underlyingCollection.isEmpty());
                    return;
                  }

                  if (EventId.size.contentEquals(eventName)) {
                    outWire.write(CoreFields.reply).int32(underlyingCollection.size());
                    return;
                  }

                  if (EventId.clear.contentEquals(eventName)) {
                    underlyingCollection.clear();
                    return;
                  }

                  if (EventId.contains.contentEquals(eventName)) {
                    outWire
                        .write(CoreFields.reply)
                        .bool(underlyingCollection.contains(fromWire.apply(valueIn)));
                    return;
                  }

                  if (EventId.add.contentEquals(eventName)) {
                    outWire
                        .write(CoreFields.reply)
                        .bool(underlyingCollection.add(fromWire.apply(valueIn)));
                    return;
                  }

                  if (EventId.remove.contentEquals(eventName)) {
                    outWire
                        .write(CoreFields.reply)
                        .bool(underlyingCollection.remove(fromWire.apply(valueIn)));
                    return;
                  }

                  if (EventId.containsAll.contentEquals(eventName)) {
                    outWire
                        .write(CoreFields.reply)
                        .bool(underlyingCollection.remove(collectionFromWire()));
                    return;
                  }

                  if (EventId.addAll.contentEquals(eventName)) {
                    outWire
                        .write(CoreFields.reply)
                        .bool(underlyingCollection.addAll(collectionFromWire()));
                    return;
                  }

                  if (EventId.removeAll.contentEquals(eventName)) {
                    outWire
                        .write(CoreFields.reply)
                        .bool(underlyingCollection.removeAll(collectionFromWire()));
                    return;
                  }

                  if (EventId.retainAll.contentEquals(eventName)) {
                    outWire
                        .write(CoreFields.reply)
                        .bool(underlyingCollection.retainAll(collectionFromWire()));
                    return;
                  }

                  throw new IllegalStateException("unsupported event=" + eventName);
                });
          } catch (Exception e) {
            LOG.error("", e);
          } finally {

            if (YamlLogging.showServerWrites) {
              long len = outBytes.writePosition();
              if (len >= SIZE_OF_SIZE) {
                String s = Wires.fromSizePrefixedBlobs(outBytes);

                LOG.info("server writes:\n\n" + s);
              }
            }
          }
        }