Java Code Examples for org.ehcache.clustered.common.internal.messages.ChainCodec

Following code examples demonstrate how to use org.ehcache.clustered.common.internal.messages.ChainCodecfrom ehcache. These examples are extracted from various highly rated open source projects. You can directly use these code snippets or view their entire linked source code. These snippets are extracted to provide contextual information about how to use this class in the real world. These samples also let you understand some good practices on how to use org.ehcache.clustered.common.internal.messages.ChainCodecand various code implementation of this class.

  private Map<Long, Chain> decodeChainMapEntries(StructDecoder<Void> decoder) {
    StructArrayDecoder<? extends StructDecoder<?>> entriesDecoder = decoder.structs(CHAIN_MAP_ENTRIES_SUB_STRUCT);

    if (entriesDecoder != null) {
      int len = entriesDecoder.length();
      Map<Long, Chain> chainMap = new HashMap<>((int) ((float) len / 0.75f + 1.0f));
      for (int i = 0; i < len; i++) {
        StructDecoder<?> entryDecoder = entriesDecoder.next();
        Long key = entryDecoder.int64(KEY_FIELD);
        StructDecoder<?> chainDecoder = entryDecoder.struct(CHAIN_FIELD);
        Chain chain = ChainCodec.decode(chainDecoder);
        chainMap.put(key, chain);
        entryDecoder.end();
      }
      return chainMap;
    } else {
      return Collections.emptyMap();
    }
  } 


  private PassiveReplicationMessage.ChainReplicationMessage decodeChainReplicationMessage(ByteBuffer messageBuffer) {
    StructDecoder<Void> decoder = CHAIN_REPLICATION_STRUCT.decoder(messageBuffer);

    Long currentTransactionId = decoder.int64(TRANSACTION_ID_FIELD);
    Long clientId = decoder.int64(CLIENT_ID_FIELD);

    Long oldestTransactionId = decoder.int64(OLDEST_TRANSACTION_ID_FIELD);
    Long key = decoder.int64(KEY_FIELD);

    Chain chain = ChainCodec.decode(decoder.struct(CHAIN_FIELD));

    return new PassiveReplicationMessage.ChainReplicationMessage(key, chain, currentTransactionId, oldestTransactionId, clientId);
  }