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


Java ImmutableValue.asArrayValue方法代码示例

本文整理汇总了Java中org.msgpack.value.ImmutableValue.asArrayValue方法的典型用法代码示例。如果您正苦于以下问题:Java ImmutableValue.asArrayValue方法的具体用法?Java ImmutableValue.asArrayValue怎么用?Java ImmutableValue.asArrayValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.msgpack.value.ImmutableValue的用法示例。


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

示例1: decode

import org.msgpack.value.ImmutableValue; //导入方法依赖的package包/类
public CheckPingResult decode(ImmutableValue value) {
  logger.debug("decoding ping {}", value);
  if (!value.isArrayValue()) {
    error("A ping message must be an array", value);
  }
  ImmutableArrayValue arrayValue = value.asArrayValue();
  if (arrayValue.size() != 6) {
    error("A ping message must have 6 elements", value);
  }
  String ping = decodeString(arrayValue.get(0));
  if (!ping.equals(("PING"))) {
    error("Invalid ping message", value);
  }
  String clientHostname = decodeString(arrayValue.get(1));
  String sharedKeySalt = decodeString(arrayValue.get(2)); // TODO Support both String and byte[]
  String sharedKeyHexDigest = decodeString(arrayValue.get(3));
  String username = decodeString(arrayValue.get(4));
  String passwordDigest = decodeString(arrayValue.get(5));

  if (node == null && !security.isAnonymousSourceAllowed()) {
    // FIXME add remote address to message
    String message = "Anonymous client disallowed.";
    logger.warn(message);
    return CheckPingResult.failure(message);
  }

  String sharedKey = null;
  try {
    sharedKey = node != null ? node.getSharedKey() : security.getSharedKey();
    MessageDigest md = MessageDigest.getInstance("SHA-512");
    md.update(sharedKeySalt.getBytes());
    md.update(clientHostname.getBytes());
    md.update(nonce);
    md.update(sharedKey.getBytes());
    String serverSideDigest = generateHexString(md.digest());
    if (!sharedKeyHexDigest.equals(serverSideDigest)) {
      // FIXME Add remote address to log
      logger.warn("Shared key mismatch: {}", clientHostname);
      return CheckPingResult.failure("Shared key mismatch");
    }

    if (security.isUserAuthEnabled()) {
      boolean userAuthenticationSucceeded = security.findAuthenticateUsers(node, username).stream().anyMatch(user -> {
        md.reset();
        md.update(userAuth);
        md.update(username.getBytes());
        md.update(user.getPassword().getBytes());
        String serverSidePasswordDigest = generateHexString(md.digest());
        return passwordDigest.equals(serverSidePasswordDigest);
      });
      if (!userAuthenticationSucceeded) {
        // FIXME Add remote address to log
        logger.info("Authentication failed: hostname={}, username={}", clientHostname, username);
        return CheckPingResult.failure("username/password mismatch");
      }
    }
  } catch (NoSuchAlgorithmException e) {
    error(e.getMessage(), value, e);
  }

  return CheckPingResult.success(sharedKeySalt, sharedKey);
}
 
开发者ID:okumin,项目名称:influent,代码行数:63,代码来源:MsgPackPingDecoder.java

示例2: decode

import org.msgpack.value.ImmutableValue; //导入方法依赖的package包/类
/**
 * Decodes a request from clients.
 *
 * {@see https://github.com/fluent/fluentd/wiki/Forward-Protocol-Specification-v1}
 *
 * {{{
 *   Connection ::= <<Request>>*
 *   Request ::= Message | Forward | PackedForward | nil
 *   Message ::= [ Tag, Time, Record, Option? ]
 *   Forward ::= [ Tag, MultiEventStream, Option? ]
 *   MultiEventStream ::= [ Event* ]
 *   PackedForward ::= [ Tag, MessagePackEventStream, Option? ]
 *   MessagePackEventStream ::= <<Event>>*
 *   Event ::= [ Time, Record ]
 *   Tag ::= string
 *   Time ::= integer | EventTime
 *   Record ::= object
 *   Option ::= object
 * }}}
 *
 * @param value msgpack value
 * @return {@code ForwardRequest} if {@code value} is a forward request,
 *         {@code Optional.empty()} if {@code value} is nil that is a future heartbeat request
 */
Optional<ForwardRequest> decode(final ImmutableValue value) {
  if (value.isNilValue()) return Optional.empty(); // reserved

  if (!value.isArrayValue()) {
    throw error("A request must be an array.", value);
  }
  final ImmutableArrayValue message = value.asArrayValue();

  if (message.size() < 2) {
    throw error("The size of array is too small.", value);
  }

  final Tag tag = decodeTag(message.get(0));

  final Value second = message.get(1);
  final List<EventEntry> entries;
  ForwardOption option = ForwardOption.empty();
  // TODO: CompressedPackedForward
  if (second.isArrayValue()) {
    entries = decodeMultiEventStream(second.asArrayValue());
    if (message.size() > 2) {
      option = decodeOption(message.get(2));
    }
  } else if (second.isStringValue() || second.isBinaryValue()) {
    entries = decodeMessagePackEventStream(second.asRawValue());
    if (message.size() > 2) {
      option = decodeOption(message.get(2));
    }
  } else {
    if (message.size() < 3) {
      throw error("The size of array is too small.", value);
    }
    final Instant time = decodeTime(second);
    final ImmutableMapValue record = decodeRecord(message.get(2));
    entries = Collections.singletonList(EventEntry.of(time, record));
    if (message.size() > 3) {
      option = decodeOption(message.get(3));
    }
  }

  return Optional.of(ForwardRequest.of(EventStream.of(tag, entries), option));
}
 
开发者ID:okumin,项目名称:influent,代码行数:67,代码来源:MsgpackForwardRequestDecoder.java


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