co.cask.cdap.api.common.Bytes.putLong()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(13.4k)|赞(0)|评价(0)|浏览(73)

本文整理了Java中co.cask.cdap.api.common.Bytes.putLong()方法的一些代码示例,展示了Bytes.putLong()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Bytes.putLong()方法的具体详情如下:
包路径:co.cask.cdap.api.common.Bytes
类名称:Bytes
方法名:putLong

Bytes.putLong介绍

[英]Put a long value out to the specified byte array position.
[中]将长值输出到指定的字节数组位置。

代码示例

代码示例来源:origin: co.cask.cdap/cdap-api-common

/**
 * Put a double value out to the specified byte array position.
 * @param bytes byte array
 * @param offset offset to write to
 * @param d value
 * @return New offset into array <code>bytes</code>
 */
public static int putDouble(byte [] bytes, int offset, double d) {
 return putLong(bytes, offset, Double.doubleToLongBits(d));
}

代码示例来源:origin: cdapio/cdap

/**
 * Put a double value out to the specified byte array position.
 * @param bytes byte array
 * @param offset offset to write to
 * @param d value
 * @return New offset into array <code>bytes</code>
 */
public static int putDouble(byte [] bytes, int offset, double d) {
 return putLong(bytes, offset, Double.doubleToLongBits(d));
}

代码示例来源:origin: co.cask.cdap/cdap-data-fabric

/**
 * Get the next row based on the given write pointer and counter. It modifies the given row byte[] in place
 * and returns it.
 */
private byte[] getNextRow(byte[] row, long writePointer, int count) {
 Bytes.putLong(row, queueRowPrefix.length, writePointer);
 Bytes.putInt(row, queueRowPrefix.length + Longs.BYTES, count + 1);
 return row;
}

代码示例来源:origin: co.cask.cdap/cdap-data-fabric

private byte[] getColumn(long groupId, int instanceId) {
 byte[] column = new byte[Longs.BYTES + Ints.BYTES];
 Bytes.putLong(column, 0, groupId);
 Bytes.putInt(column, Longs.BYTES, instanceId);
 return column;
}

代码示例来源:origin: co.cask.cdap/cdap-data-fabric

/**
 * Returns the column qualifier for the consumer state column. The qualifier is formed by
 * {@code <groupId><instanceId>}.
 * @param groupId Group ID of the consumer
 * @param instanceId Instance ID of the consumer
 * @return A new byte[] which is the column qualifier.
 */
private byte[] getConsumerStateColumn(long groupId, int instanceId) {
 byte[] column = new byte[Longs.BYTES + Ints.BYTES];
 Bytes.putLong(column, 0, groupId);
 Bytes.putInt(column, Longs.BYTES, instanceId);
 return column;
}

代码示例来源:origin: co.cask.cdap/cdap-tms

/**
 * Computes the message raw ID and store it in the given byte array.
 *
 * @param publishTimestamp publish timestamp of the message
 * @param sequenceId publish sequence id of the message
 * @param writeTimestamp write timestamp in the payload table of the message
 * @param payloadSequenceId sequence id in the payload table of the message
 * @param buffer the buffer to encode raw id to
 * @param offset the starting offset in the buffer for storing the raw message id
 * @return the offset in the buffer that points to the index right after then end of the raw message id
 */
public static int putRawId(long publishTimestamp, short sequenceId,
              long writeTimestamp, short payloadSequenceId, byte[] buffer, int offset) {
 if (buffer.length - offset < RAW_ID_SIZE) {
  throw new IllegalArgumentException("Not enough size in the buffer to encode Message ID");
 }
 offset = Bytes.putLong(buffer, offset, publishTimestamp);
 offset = Bytes.putShort(buffer, offset, sequenceId);
 offset = Bytes.putLong(buffer, offset, writeTimestamp);
 return Bytes.putShort(buffer, offset, payloadSequenceId);
}

代码示例来源:origin: caskdata/cdap

/**
 * Computes the message raw ID and store it in the given byte array.
 *
 * @param publishTimestamp publish timestamp of the message
 * @param sequenceId publish sequence id of the message
 * @param writeTimestamp write timestamp in the payload table of the message
 * @param payloadSequenceId sequence id in the payload table of the message
 * @param buffer the buffer to encode raw id to
 * @param offset the starting offset in the buffer for storing the raw message id
 * @return the offset in the buffer that points to the index right after then end of the raw message id
 */
public static int putRawId(long publishTimestamp, short sequenceId,
              long writeTimestamp, short payloadSequenceId, byte[] buffer, int offset) {
 if (buffer.length - offset < RAW_ID_SIZE) {
  throw new IllegalArgumentException("Not enough size in the buffer to encode Message ID");
 }
 offset = Bytes.putLong(buffer, offset, publishTimestamp);
 offset = Bytes.putShort(buffer, offset, sequenceId);
 offset = Bytes.putLong(buffer, offset, writeTimestamp);
 return Bytes.putShort(buffer, offset, payloadSequenceId);
}

代码示例来源:origin: co.cask.cdap/cdap-data-fabric

@Override
public void getRowKeys(Iterable<ConsumerGroupConfig> consumerGroupConfigs, QueueEntry queueEntry, byte[] rowKeyPrefix,
            long writePointer, int counter, Collection<byte[]> rowKeys) {
 byte[] rowKey = new byte[rowKeyPrefix.length + Bytes.SIZEOF_LONG + Bytes.SIZEOF_INT];
 Bytes.putBytes(rowKey, 0, rowKeyPrefix, 0, rowKeyPrefix.length);
 Bytes.putLong(rowKey, rowKeyPrefix.length, writePointer);
 Bytes.putInt(rowKey, rowKey.length - Bytes.SIZEOF_INT, counter);
 rowKeys.add(rowKeyDistributor.getDistributedKey(rowKey));
}

代码示例来源:origin: co.cask.cdap/cdap-data-fabric

private byte[] getShardedKey(ConsumerGroupConfig groupConfig, int instanceId,
                byte[] originalRowKey) {
  // Need to subtract the SALT_BYTES as the row key distributor will prefix the key with salted bytes
  byte[] result = new byte[PREFIX_BYTES - SaltedHBaseQueueStrategy.SALT_BYTES + originalRowKey.length];
  Bytes.putBytes(result, PREFIX_BYTES - SaltedHBaseQueueStrategy.SALT_BYTES,
          originalRowKey, 0, originalRowKey.length);
  Bytes.putLong(result, 0, groupConfig.getGroupId());

  // Default for FIFO case.
  int shardId = groupConfig.getDequeueStrategy() == DequeueStrategy.FIFO ? -1 : instanceId;
  Bytes.putInt(result, Bytes.SIZEOF_LONG, shardId);

  return result;
 }
}

代码示例来源:origin: caskdata/cdap

@Override
public CloseableIterator<Entry> fetch(TopicMetadata metadata, long startTime, int limit,
                   @Nullable Transaction transaction) throws IOException {
 byte[] topic = MessagingUtils.toDataKeyPrefix(metadata.getTopicId(), metadata.getGeneration());
 byte[] startRow = new byte[topic.length + Bytes.SIZEOF_LONG];
 Bytes.putBytes(startRow, 0, topic, 0, topic.length);
 Bytes.putLong(startRow, topic.length, startTime);
 byte[] stopRow = Bytes.stopKeyForPrefix(topic);
 final CloseableIterator<RawMessageTableEntry> scanner = read(startRow, stopRow);
 return new FetchIterator(scanner, limit, null, transaction);
}

代码示例来源:origin: co.cask.cdap/cdap-tms

@Override
public CloseableIterator<Entry> fetch(TopicMetadata metadata, long startTime, int limit,
                   @Nullable Transaction transaction) throws IOException {
 byte[] topic = MessagingUtils.toDataKeyPrefix(metadata.getTopicId(), metadata.getGeneration());
 byte[] startRow = new byte[topic.length + Bytes.SIZEOF_LONG];
 Bytes.putBytes(startRow, 0, topic, 0, topic.length);
 Bytes.putLong(startRow, topic.length, startTime);
 byte[] stopRow = Bytes.stopKeyForPrefix(topic);
 final CloseableIterator<RawMessageTableEntry> scanner = read(startRow, stopRow);
 return new FetchIterator(scanner, limit, null, transaction);
}

代码示例来源:origin: co.cask.cdap/cdap-data-fabric

private byte[] encodeStateColumn(ConsumerEntryState state) {
 // State column content is encoded as (writePointer) + (instanceId) + (state)
 byte[] stateContent = new byte[Longs.BYTES + Ints.BYTES + 1];
 Bytes.putLong(stateContent, 0, transaction.getWritePointer());
 Bytes.putInt(stateContent, Longs.BYTES, getConfig().getInstanceId());
 Bytes.putByte(stateContent, Longs.BYTES + Ints.BYTES, state.getState());
 return stateContent;
}

代码示例来源:origin: co.cask.cdap/cdap-data-fabric

/**
 * Encodes the value for the state column with the current transaction and consumer information.
 *
 * @param state The state to encode
 * @return The stateContent byte array
 */
// TODO: This method is copied from AbstractQueue2Consumer. Future effort is needed to unify them.
private byte[] encodeStateColumn(ConsumerEntryState state) {
 byte[] stateContent = new byte[Longs.BYTES + Ints.BYTES + 1];
 // State column content is encoded as (writePointer) + (instanceId) + (state)
 Bytes.putLong(stateContent, 0, transaction.getWritePointer());
 Bytes.putInt(stateContent, Longs.BYTES, consumerConfig.getInstanceId());
 Bytes.putByte(stateContent, Longs.BYTES + Ints.BYTES, state.getState());
 return stateContent;
}

代码示例来源:origin: caskdata/cdap

@Override
 protected RawPayloadTableEntry computeNext() {
  if (!entries.hasNext()) {
   return endOfData();
  }
  Entry entry = entries.next();
  if (topicId == null || (!topicId.equals(entry.getTopicId())) || (generation != entry.getGeneration())) {
   topicId = entry.getTopicId();
   generation = entry.getGeneration();
   topic = MessagingUtils.toDataKeyPrefix(topicId, entry.getGeneration());
   rowKey = new byte[topic.length + (2 * Bytes.SIZEOF_LONG) + Bytes.SIZEOF_SHORT];
  }
  Bytes.putBytes(rowKey, 0, topic, 0, topic.length);
  Bytes.putLong(rowKey, topic.length, entry.getTransactionWritePointer());
  Bytes.putLong(rowKey, topic.length + Bytes.SIZEOF_LONG, entry.getPayloadWriteTimestamp());
  Bytes.putShort(rowKey, topic.length + (2 * Bytes.SIZEOF_LONG), entry.getPayloadSequenceId());
  return tableEntry.set(rowKey, entry.getPayload());
 }
}

代码示例来源:origin: co.cask.cdap/cdap-tms

@Override
 protected RawPayloadTableEntry computeNext() {
  if (!entries.hasNext()) {
   return endOfData();
  }
  Entry entry = entries.next();
  if (topicId == null || (!topicId.equals(entry.getTopicId())) || (generation != entry.getGeneration())) {
   topicId = entry.getTopicId();
   generation = entry.getGeneration();
   topic = MessagingUtils.toDataKeyPrefix(topicId, entry.getGeneration());
   rowKey = new byte[topic.length + (2 * Bytes.SIZEOF_LONG) + Bytes.SIZEOF_SHORT];
  }
  Bytes.putBytes(rowKey, 0, topic, 0, topic.length);
  Bytes.putLong(rowKey, topic.length, entry.getTransactionWritePointer());
  Bytes.putLong(rowKey, topic.length + Bytes.SIZEOF_LONG, entry.getPayloadWriteTimestamp());
  Bytes.putShort(rowKey, topic.length + (2 * Bytes.SIZEOF_LONG), entry.getPayloadSequenceId());
  return tableEntry.set(rowKey, entry.getPayload());
 }
}

代码示例来源:origin: caskdata/cdap

@Override
public CloseableIterator<Entry> fetch(TopicMetadata metadata, MessageId messageId, boolean inclusive,
                   final int limit, @Nullable final Transaction transaction) throws IOException {
 byte[] topic = MessagingUtils.toDataKeyPrefix(metadata.getTopicId(), metadata.getGeneration());
 byte[] startRow = new byte[topic.length + Bytes.SIZEOF_LONG + Bytes.SIZEOF_SHORT];
 Bytes.putBytes(startRow, 0, topic, 0, topic.length);
 Bytes.putLong(startRow, topic.length, messageId.getPublishTimestamp());
 Bytes.putShort(startRow, topic.length + Bytes.SIZEOF_LONG, messageId.getSequenceId());
 byte[] stopRow = Bytes.stopKeyForPrefix(topic);
 final CloseableIterator<RawMessageTableEntry> scanner = read(startRow, stopRow);
 return new FetchIterator(scanner, limit, inclusive ? null : startRow, transaction);
}

代码示例来源:origin: co.cask.cdap/cdap-tms

@Override
public CloseableIterator<Entry> fetch(TopicMetadata metadata, MessageId messageId, boolean inclusive,
                   final int limit, @Nullable final Transaction transaction) throws IOException {
 byte[] topic = MessagingUtils.toDataKeyPrefix(metadata.getTopicId(), metadata.getGeneration());
 byte[] startRow = new byte[topic.length + Bytes.SIZEOF_LONG + Bytes.SIZEOF_SHORT];
 Bytes.putBytes(startRow, 0, topic, 0, topic.length);
 Bytes.putLong(startRow, topic.length, messageId.getPublishTimestamp());
 Bytes.putShort(startRow, topic.length + Bytes.SIZEOF_LONG, messageId.getSequenceId());
 byte[] stopRow = Bytes.stopKeyForPrefix(topic);
 final CloseableIterator<RawMessageTableEntry> scanner = read(startRow, stopRow);
 return new FetchIterator(scanner, limit, inclusive ? null : startRow, transaction);
}

代码示例来源:origin: co.cask.cdap/cdap-tms

@Override
public void rollback(TopicMetadata metadata, RollbackDetail rollbackDetail) throws IOException {
 //long startTimestamp, short startSequenceId,
 //long endTimestamp, short endSequenceId
 byte[] topic = MessagingUtils.toDataKeyPrefix(metadata.getTopicId(), metadata.getGeneration());
 byte[] startRow = new byte[topic.length + Bytes.SIZEOF_LONG + Bytes.SIZEOF_SHORT];
 Bytes.putBytes(startRow, 0, topic, 0, topic.length);
 Bytes.putLong(startRow, topic.length, rollbackDetail.getStartTimestamp());
 Bytes.putShort(startRow, topic.length + Bytes.SIZEOF_LONG, (short) rollbackDetail.getStartSequenceId());
 byte[] stopRow = new byte[topic.length + Bytes.SIZEOF_LONG + Bytes.SIZEOF_SHORT];
 Bytes.putBytes(stopRow, 0, topic, 0, topic.length);
 Bytes.putLong(stopRow, topic.length, rollbackDetail.getEndTimestamp());
 Bytes.putShort(stopRow, topic.length + Bytes.SIZEOF_LONG, (short) rollbackDetail.getEndSequenceId());
 rollback(startRow, Bytes.stopKeyForPrefix(stopRow),
      Bytes.toBytes(-1 * rollbackDetail.getTransactionWritePointer()));
}

代码示例来源:origin: caskdata/cdap

@Override
public void rollback(TopicMetadata metadata, RollbackDetail rollbackDetail) throws IOException {
 //long startTimestamp, short startSequenceId,
 //long endTimestamp, short endSequenceId
 byte[] topic = MessagingUtils.toDataKeyPrefix(metadata.getTopicId(), metadata.getGeneration());
 byte[] startRow = new byte[topic.length + Bytes.SIZEOF_LONG + Bytes.SIZEOF_SHORT];
 Bytes.putBytes(startRow, 0, topic, 0, topic.length);
 Bytes.putLong(startRow, topic.length, rollbackDetail.getStartTimestamp());
 Bytes.putShort(startRow, topic.length + Bytes.SIZEOF_LONG, (short) rollbackDetail.getStartSequenceId());
 byte[] stopRow = new byte[topic.length + Bytes.SIZEOF_LONG + Bytes.SIZEOF_SHORT];
 Bytes.putBytes(stopRow, 0, topic, 0, topic.length);
 Bytes.putLong(stopRow, topic.length, rollbackDetail.getEndTimestamp());
 Bytes.putShort(stopRow, topic.length + Bytes.SIZEOF_LONG, (short) rollbackDetail.getEndSequenceId());
 rollback(startRow, Bytes.stopKeyForPrefix(stopRow),
      Bytes.toBytes(-1 * rollbackDetail.getTransactionWritePointer()));
}

代码示例来源:origin: co.cask.cdap/cdap-tms

@Override
 protected RawMessageTableEntry computeNext() {
  if (!entries.hasNext()) {
   return endOfData();
  }
  Entry entry = entries.next();
  // Create new byte arrays only when the topicId is different. Else, reuse the byte arrays.
  if (topicId == null || (!topicId.equals(entry.getTopicId())) || (generation != entry.getGeneration())) {
   topicId = entry.getTopicId();
   generation = entry.getGeneration();
   topic = MessagingUtils.toDataKeyPrefix(topicId, entry.getGeneration());
   rowKey = new byte[topic.length + Bytes.SIZEOF_LONG + Bytes.SIZEOF_SHORT];
  }
  Bytes.putBytes(rowKey, 0, topic, 0, topic.length);
  Bytes.putLong(rowKey, topic.length, entry.getPublishTimestamp());
  Bytes.putShort(rowKey, topic.length + Bytes.SIZEOF_LONG, entry.getSequenceId());
  byte[] txPtr = null;
  if (entry.isTransactional()) {
   txPtr = Bytes.toBytes(entry.getTransactionWritePointer());
  }
  return tableEntry.set(rowKey, txPtr, entry.getPayload());
 }
}

相关文章