本文整理了Java中co.cask.cdap.api.common.Bytes.putShort()
方法的一些代码示例,展示了Bytes.putShort()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Bytes.putShort()
方法的具体详情如下:
包路径:co.cask.cdap.api.common.Bytes
类名称:Bytes
方法名:putShort
[英]Put a short value out to the specified byte array position.
[中]将短值输出到指定的字节数组位置。
代码示例来源: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: 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: cdapio/cdap
byte[] bytes, int offset) {
int pos = offset;
pos = Bytes.putShort(bytes, pos, (short) (rLength & 0x0000ffff));
pos = Bytes.putBytes(bytes, pos, row, rOffset, rLength);
pos = Bytes.putByte(bytes, pos, (byte) (fLength & 0x0000ff));
代码示例来源:origin: co.cask.cdap/cdap-data-fabric
pos = Bytes.putInt(bytes, pos, keylength);
pos = Bytes.putInt(bytes, pos, vlength);
pos = Bytes.putShort(bytes, pos, (short) (rlength & 0x0000ffff));
pos = Bytes.putBytes(bytes, pos, row, roffset, rlength);
pos = Bytes.putByte(bytes, pos, (byte) (flength & 0x0000ff));
代码示例来源: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: 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: 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());
}
}
代码示例来源:origin: caskdata/cdap
@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());
}
}
代码示例来源:origin: caskdata/cdap
Bytes.putLong(stopRow, topic.length, transactionWritePointer);
Bytes.putLong(startRow, topic.length + Bytes.SIZEOF_LONG, messageId.getPayloadWriteTimestamp());
Bytes.putShort(startRow, topic.length + (2 * Bytes.SIZEOF_LONG), messageId.getPayloadSequenceId());
stopRow = Bytes.stopKeyForPrefix(stopRow);
代码示例来源:origin: co.cask.cdap/cdap-tms
Bytes.putLong(stopRow, topic.length, transactionWritePointer);
Bytes.putLong(startRow, topic.length + Bytes.SIZEOF_LONG, messageId.getPayloadWriteTimestamp());
Bytes.putShort(startRow, topic.length + (2 * Bytes.SIZEOF_LONG), messageId.getPayloadSequenceId());
stopRow = Bytes.stopKeyForPrefix(stopRow);
内容来源于网络,如有侵权,请联系作者删除!