当前位置: 首页>>代码示例>>Java>>正文


Java TextFormat类代码示例

本文整理汇总了Java中com.google.protobuf.TextFormat的典型用法代码示例。如果您正苦于以下问题:Java TextFormat类的具体用法?Java TextFormat怎么用?Java TextFormat使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


TextFormat类属于com.google.protobuf包,在下文中一共展示了TextFormat类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: get

import com.google.protobuf.TextFormat; //导入依赖的package包/类
synchronized long get() throws IOException {
  try {
    currentStat = zkc.exists(path, false);
    if (currentStat == null) {
      return 0;
    } else {

      byte[] bytes = zkc.getData(path, false, currentStat);

      MaxTxIdProto.Builder builder = MaxTxIdProto.newBuilder();
      TextFormat.merge(new String(bytes, UTF_8), builder);
      if (!builder.isInitialized()) {
        throw new IOException("Invalid/Incomplete data in znode");
      }

      return builder.build().getTxId();
    }
  } catch (KeeperException e) {
    throw new IOException("Error reading the max tx id from zk", e);
  } catch (InterruptedException ie) {
    throw new IOException("Interrupted while reading thr max tx id", ie);
  }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:24,代码来源:MaxTxId.java

示例2: parseMessage

import com.google.protobuf.TextFormat; //导入依赖的package包/类
public ApplicationLog parseMessage(String messageString) throws InvalidProtocolBufferException, TextFormat
        .ParseException {
    LogMessages.Message.Builder builder = LogMessages.Message.newBuilder();
    TextFormat.merge(messageString, builder);
    LogMessages.Message message = builder.build();

    return createApplicationLog(message);
}
 
开发者ID:SAP,项目名称:cf-java-client-sap,代码行数:9,代码来源:LoggregatorMessageParser.java

示例3: findInCache

import com.google.protobuf.TextFormat; //导入依赖的package包/类
@Override public Optional<Group> findInCache(String cacheKey) {

    logger.info("{}", kvp("op", "findInCache", "group", cacheKey));

    @SuppressWarnings("unchecked")
    Optional<String> maybe = (Optional<String>) new RedisCacheCommand<Optional<String>>(
        "GroupCacheGet",
        () -> redisCache.get(cacheKey),
        Optional::empty,
        hystrixConfiguration,
        metrics).execute();

    if (maybe.isPresent()) {
      Group cached = GroupSupport.toGroup(maybe.get());
      logger.info("{} /group=[{}]",
          kvp("op", "findInCache", "key", cacheKey, "result", "cache_hit"),
          TextFormat.shortDebugString(cached));
      return Optional.of(cached);
    }

    logger.info("{}", kvp("op", "findInCache", "key", cacheKey, "result", "cache_miss"));

    return Optional.empty();
  }
 
开发者ID:dehora,项目名称:outland,代码行数:25,代码来源:DefaultGroupCache.java

示例4: findInCache

import com.google.protobuf.TextFormat; //导入依赖的package包/类
@Override public Optional<Feature> findInCache(String cacheKey) {
  //noinspection unchecked
  Optional<String> maybe = (Optional<String>) new RedisCacheCommand<Optional<String>>("CacheGet",
      () -> redisCache.get(cacheKey),
      Optional::empty,
      hystrixConfiguration,
      metrics).execute();

  if (maybe.isPresent()) {
    Feature cached = FeatureSupport.toFeature(maybe.get());
    logger.info("{} /feature=[{}]",
        kvp("op", "findInCache", "key", cacheKey, "result", "cache_hit"),
        TextFormat.shortDebugString(cached));
    return Optional.of(cached);
  }

  logger.info("{}", kvp("op", "findInCache", "key", cacheKey, "result", "cache_miss"));

  return Optional.empty();
}
 
开发者ID:dehora,项目名称:outland,代码行数:21,代码来源:DefaultFeatureCache.java

示例5: parseRequest

import com.google.protobuf.TextFormat; //导入依赖的package包/类
@Override public Request parseRequest(byte[] bytes) throws IOException {
  ByteString byteString = UnsafeByteOperations.unsafeWrap(bytes);
  CodedInputStream inputStream = byteString.newCodedInput();
  // Enable aliasing to avoid an extra copy to get at the serialized Request inside of the
  // WireMessage.
  inputStream.enableAliasing(true);
  WireMessage wireMsg = WireMessage.parseFrom(inputStream);

  String serializedMessageClassName = wireMsg.getName();

  try {
    RequestTranslator translator = getParserForRequest(serializedMessageClassName);

    // The ByteString should be logical offsets into the original byte array
    return translator.transform(wireMsg.getWrappedMessage());
  } catch (RuntimeException e) {
    if (LOG.isDebugEnabled()) {
      LOG.debug("Failed to parse request message '{}'", TextFormat.shortDebugString(wireMsg));
    }
    throw e;
  }
}
 
开发者ID:apache,项目名称:calcite-avatica,代码行数:23,代码来源:ProtobufTranslationImpl.java

示例6: mapToString

import com.google.protobuf.TextFormat; //导入依赖的package包/类
public static <K> String mapToString(
    Map<K, ? extends Message> map) {
  StringBuilder sb = new StringBuilder();
  boolean first = true;
  for (Map.Entry<K, ? extends Message> e : map.entrySet()) {
    if (!first) {
      sb.append("\n");
    }
    first = false;
    sb.append(e.getKey()).append(": ")
      .append(TextFormat.shortDebugString(e.getValue()));
  }
  return sb.toString();
}
 
开发者ID:naver,项目名称:hadoop,代码行数:15,代码来源:QuorumCall.java

示例7: getSegmentInfo

import com.google.protobuf.TextFormat; //导入依赖的package包/类
/**
 * @return the current state of the given segment, or null if the
 * segment does not exist.
 */
@VisibleForTesting
SegmentStateProto getSegmentInfo(long segmentTxId)
    throws IOException {
  EditLogFile elf = fjm.getLogFile(segmentTxId);
  if (elf == null) {
    return null;
  }
  if (elf.isInProgress()) {
    elf.scanLog();
  }
  if (elf.getLastTxId() == HdfsConstants.INVALID_TXID) {
    LOG.info("Edit log file " + elf + " appears to be empty. " +
        "Moving it aside...");
    elf.moveAsideEmptyFile();
    return null;
  }
  SegmentStateProto ret = SegmentStateProto.newBuilder()
      .setStartTxId(segmentTxId)
      .setEndTxId(elf.getLastTxId())
      .setIsInProgress(elf.isInProgress())
      .build();
  LOG.info("getSegmentInfo(" + segmentTxId + "): " + elf + " -> " +
      TextFormat.shortDebugString(ret));
  return ret;
}
 
开发者ID:naver,项目名称:hadoop,代码行数:30,代码来源:Journal.java

示例8: replayWALFlushCannotFlushMarker

import com.google.protobuf.TextFormat; //导入依赖的package包/类
private void replayWALFlushCannotFlushMarker(FlushDescriptor flush, long replaySeqId) {
  synchronized (writestate) {
    if (this.lastReplayedOpenRegionSeqId > replaySeqId) {
      LOG.warn(getRegionInfo().getEncodedName() + " : " + "Skipping replaying flush event :"
          + TextFormat.shortDebugString(flush) + " because its sequence id " + replaySeqId
          + " is smaller than this regions " + "lastReplayedOpenRegionSeqId of "
          + lastReplayedOpenRegionSeqId);
      return;
    }

    // If we were waiting for observing a flush or region opening event for
    // not showing partial
    // data after a secondary region crash, we can allow reads now. This event
    // means that the
    // primary was not able to flush because memstore is empty when we
    // requested flush. By the
    // time we observe this, we are guaranteed to have up to date seqId with
    // our previous
    // assignment.
    this.setReadsEnabled(true);
  }
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:23,代码来源:HRegion.java

示例9: register

import com.google.protobuf.TextFormat; //导入依赖的package包/类
@Override public Optional<Group> register(Group group) {
  logger.info("{} /group[{}]", kvp("op", "register"), TextFormat.shortDebugString(group));
  new GroupValidator().validateRegistrationThrowing(group);
  final Optional<Group> registration = processRegistration(group);

  registration.ifPresent(this::addToCache);
  return registration;
}
 
开发者ID:dehora,项目名称:outland,代码行数:9,代码来源:DefaultGroupService.java

示例10: add

import com.google.protobuf.TextFormat; //导入依赖的package包/类
@Override public Group add(Group group, MemberAccess member) {
  logger.info("{} /group[{}]/mbr[{}]", kvp("op", "add.member"),
      TextFormat.shortDebugString(group), TextFormat.shortDebugString(member));

  final Group update = processUpdate(group,
      builder -> {
        AccessCollection.Builder accessBuilder = newGrantCollectionBuilder();
        accessBuilder.addAllMembers(groupUpdateProcessor.mergeMembers(group, member));
        accessBuilder.addAllServices(group.getGranted().getServicesList());
        builder.setGranted(accessBuilder.buildPartial());
      });
  addToCache(update);
  return update;
}
 
开发者ID:dehora,项目名称:outland,代码行数:15,代码来源:DefaultGroupService.java

示例11: writeBulkLoadMarkerAndSync

import com.google.protobuf.TextFormat; //导入依赖的package包/类
/**
 * Write a log marker that a bulk load has succeeded and is about to be committed.
 *
 * @param wal        The log to write into.
 * @param htd        A description of the table that we are bulk loading into.
 * @param hri       A description of the region in the table that we are bulk loading into.
 * @param desc A protocol buffers based description of the client's bulk loading request
 * @return txid of this transaction or if nothing to do, the last txid
 * @throws IOException We will throw an IOException if we can not append to the HLog.
 */
public static long writeBulkLoadMarkerAndSync(final WAL wal, final HTableDescriptor htd,
    final HRegionInfo hri, final WALProtos.BulkLoadDescriptor desc,
    final MultiVersionConcurrencyControl mvcc)
throws IOException {
  long trx = writeMarker(wal, htd, hri, WALEdit.createBulkLoadEvent(hri, desc), mvcc, true);
  if (LOG.isTraceEnabled()) {
    LOG.trace("Appended Bulk Load marker " + TextFormat.shortDebugString(desc));
  }
  return trx;
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:21,代码来源:WALUtil.java

示例12: toBuildFarmServerConfig

import com.google.protobuf.TextFormat; //导入依赖的package包/类
private static BuildFarmServerConfig toBuildFarmServerConfig(InputStream inputStream, BuildFarmServerOptions options) throws IOException {
  BuildFarmServerConfig.Builder builder = BuildFarmServerConfig.newBuilder();
  String data = new String(Encoding.convertFromLatin1(ByteStreams.toByteArray(inputStream)));
  TextFormat.merge(data, builder);
  if (options.port > 0) {
      builder.setPort(options.port);
  }
  return builder.build();
}
 
开发者ID:bazelbuild,项目名称:bazel-buildfarm,代码行数:10,代码来源:BuildFarmServer.java

示例13: unescape

import com.google.protobuf.TextFormat; //导入依赖的package包/类
private static ByteString unescape(String toUnescape) {
    try {
        return TextFormat.unescapeBytes(toUnescape);
    } catch (TextFormat.InvalidEscapeSequenceException e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:ocraft,项目名称:ocraft-s2client,代码行数:8,代码来源:Images.java

示例14: read

import com.google.protobuf.TextFormat; //导入依赖的package包/类
static EditLogLedgerMetadata read(ZooKeeper zkc, String path)
    throws IOException, KeeperException.NoNodeException  {
  try {
    byte[] data = zkc.getData(path, false, null);

    EditLogLedgerProto.Builder builder = EditLogLedgerProto.newBuilder();
    if (LOG.isDebugEnabled()) {
      LOG.debug("Reading " + path + " data: " + new String(data, UTF_8));
    }
    TextFormat.merge(new String(data, UTF_8), builder);
    if (!builder.isInitialized()) {
      throw new IOException("Invalid/Incomplete data in znode");
    }
    EditLogLedgerProto ledger = builder.build();

    int dataLayoutVersion = ledger.getDataLayoutVersion();
    long ledgerId = ledger.getLedgerId();
    long firstTxId = ledger.getFirstTxId();
    if (ledger.hasLastTxId()) {
      long lastTxId = ledger.getLastTxId();
      return new EditLogLedgerMetadata(path, dataLayoutVersion,
                                       ledgerId, firstTxId, lastTxId);
    } else {
      return new EditLogLedgerMetadata(path, dataLayoutVersion,
                                       ledgerId, firstTxId);
    }
  } catch(KeeperException.NoNodeException nne) {
    throw nne;
  } catch(KeeperException ke) {
    throw new IOException("Error reading from zookeeper", ke);
  } catch (InterruptedException ie) {
    throw new IOException("Interrupted reading from zookeeper", ie);
  }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:35,代码来源:EditLogLedgerMetadata.java

示例15: toWorkerConfig

import com.google.protobuf.TextFormat; //导入依赖的package包/类
private static WorkerConfig toWorkerConfig(InputStream inputStream, WorkerOptions options) throws IOException {
  WorkerConfig.Builder builder = WorkerConfig.newBuilder();
  String data = new String(Encoding.convertFromLatin1(ByteStreams.toByteArray(inputStream)));
  TextFormat.merge(data, builder);
  if (!Strings.isNullOrEmpty(options.root)) {
    builder.setRoot(options.root);
  }

  if (!Strings.isNullOrEmpty(options.casCacheDirectory)) {
    builder.setCasCacheDirectory(options.casCacheDirectory);
  }
  return builder.build();
}
 
开发者ID:bazelbuild,项目名称:bazel-buildfarm,代码行数:14,代码来源:Worker.java


注:本文中的com.google.protobuf.TextFormat类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。