Tabnine Logo
DataFrameDescriptor
Code IndexAdd Tabnine to your IDE (free)

How to use
DataFrameDescriptor
in
io.zeebe.dispatcher.impl.log

Best Java code snippets using io.zeebe.dispatcher.impl.log.DataFrameDescriptor (Showing top 20 results out of 315)

origin: zeebe-io/zeebe

 @Override
 public DirectBuffer next() {
  final int framedFragmentLength =
    bufferView.getInt(DataFrameDescriptor.lengthOffset(iterationOffset));
  final int fragmentLength = DataFrameDescriptor.messageLength(framedFragmentLength);
  final int messageOffset = DataFrameDescriptor.messageOffset(iterationOffset);
  buffer.wrap(bufferView, messageOffset, fragmentLength);
  iterationOffset += DataFrameDescriptor.alignedLength(framedFragmentLength);
  return buffer;
 }
}
origin: zeebe-io/zeebe

@Override
public int getStreamId() {
 return buffer.getInt(streamIdOffset(fragmentOffset), Protocol.ENDIANNESS);
}
origin: zeebe-io/zeebe

@Override
public int getType() {
 return buffer.getShort(typeOffset(fragmentOffset), Protocol.ENDIANNESS);
}
origin: zeebe-io/zeebe

public static int alignedFramedLength(int msgLength) {
 return alignedLength(framedLength(msgLength));
}
origin: zeebe-io/zeebe

@Override
public int getMessageLength() {
 return messageLength(buffer.getInt(lengthOffset(fragmentOffset), Protocol.ENDIANNESS));
}
origin: zeebe-io/zeebe

/**
 * Add a new fragment to the batch.
 *
 * @param length the length of the fragment
 * @param streamId the stream id of the fragment
 * @return the position of the fragment
 * @throws IllegalArgumentException if the given length is greater than the remaining capacity. In
 *     this case, you should try with smaller length, or abort the whole batch.
 */
@SuppressWarnings("restriction")
public long nextFragment(int length, int streamId) {
 currentOffset = nextOffset;
 final int framedLength = framedLength(length);
 nextOffset += alignedLength(framedLength);
 // ensure that there is enough capacity for padding message, or less than frame alignment which
 // omits the padding message
 final int remainingCapacity = buffer.capacity() - nextOffset;
 if (remainingCapacity < 0
   || (FRAME_ALIGNMENT <= remainingCapacity && remainingCapacity < HEADER_LENGTH)) {
  throw new IllegalArgumentException(
    String.format(ERROR_MESSAGE, currentOffset, length, buffer.capacity()));
 }
 // set negative length => uncommitted fragment
 buffer.putIntOrdered(lengthOffset(currentOffset), -framedLength);
 UNSAFE.storeFence();
 buffer.putShort(typeOffset(currentOffset), TYPE_MESSAGE);
 buffer.putInt(streamIdOffset(currentOffset), streamId);
 return position(partitionId, partitionOffset + nextOffset);
}
origin: zeebe-io/zeebe

final int framedLength = buffer.getIntVolatile(lengthOffset(fragmentOffset));
if (framedLength <= 0) {
 break;
final short type = buffer.getShort(typeOffset(fragmentOffset));
if (type == TYPE_PADDING) {
 fragmentOffset += alignedLength(framedLength);
 final int streamId = buffer.getInt(streamIdOffset(fragmentOffset));
 final int flagsOffset = flagsOffset(fragmentOffset);
 final byte flags = buffer.getByte(flagsOffset);
 try {
  final boolean isMarkedAsFailed = flagFailed(flags);
  final int messageLength = messageLength(framedLength);
  final int handlerResult =
    frgHandler.onFragment(
      buffer, messageOffset(fragmentOffset), messageLength, streamId, isMarkedAsFailed);
   buffer.putByte(flagsOffset, DataFrameDescriptor.enableFlagFailed(flags));
  fragmentOffset += alignedLength(framedLength);
origin: zeebe-io/zeebe

final int framedLength = buffer.getIntVolatile(lengthOffset(partitionOffset));
if (framedLength <= 0) {
 break;
final short type = buffer.getShort(typeOffset(partitionOffset));
if (type == TYPE_PADDING) {
 partitionOffset += alignedLength(framedLength);
  final int streamId = buffer.getInt(streamIdOffset(partitionOffset));
  if (readBytes == 0) {
   initialStreamId = streamId;
 final byte flags = buffer.getByte(flagsOffset(partitionOffset));
 if (!isReadingBatch) {
  isReadingBatch = flagBatchBegin(flags);
 } else {
  isReadingBatch = !flagBatchEnd(flags);
 final int alignedFrameLength = alignedLength(framedLength);
 if (alignedFrameLength <= maxBlockSize - readBytes) {
  partitionOffset += alignedFrameLength;
origin: zeebe-io/zeebe

/** Commit all fragments of the batch so that it can be read by subscriptions. */
public void commit() {
 final int firstFragmentFramedLength = -buffer.getInt(lengthOffset(FIRST_FRAGMENT_OFFSET));
 // do not set batch flags if only one fragment in the batch
 if (currentOffset > 0) {
  // set batch begin flag
  final byte firstFragmentFlags = buffer.getByte(flagsOffset(FIRST_FRAGMENT_OFFSET));
  buffer.putByte(flagsOffset(FIRST_FRAGMENT_OFFSET), enableFlagBatchBegin(firstFragmentFlags));
  // set positive length => commit fragment
  int fragmentOffset = DataFrameDescriptor.alignedLength(firstFragmentFramedLength);
  while (fragmentOffset < nextOffset) {
   final int fragmentFramedLength = -buffer.getInt(lengthOffset(fragmentOffset));
   buffer.putInt(lengthOffset(fragmentOffset), fragmentFramedLength);
   fragmentOffset += DataFrameDescriptor.alignedLength(fragmentFramedLength);
  }
  // set batch end flag
  final byte lastFragmentFlags = buffer.getByte(flagsOffset(currentOffset));
  buffer.putByte(flagsOffset(currentOffset), enableFlagBatchEnd(lastFragmentFlags));
 }
 fillRemainingBatchSize();
 // commit the first fragment at the end so that the batch can be read at
 // once
 buffer.putIntOrdered(lengthOffset(FIRST_FRAGMENT_OFFSET), firstFragmentFramedLength);
 onCompleteHandler.run();
 reset();
}
origin: zeebe-io/zeebe

private void fillRemainingBatchSize() {
 // since the claimed batch size can be longer than the written fragment
 // size, we need to fill the rest with a padding fragment
 final int remainingLength = buffer.capacity() - nextOffset;
 if (remainingLength >= HEADER_LENGTH) {
  buffer.putInt(lengthOffset(nextOffset), remainingLength);
  buffer.putShort(typeOffset(nextOffset), TYPE_PADDING);
 }
}
origin: zeebe-io/zeebe

/**
 * Commit all fragments of the batch and mark them as failed. They will be ignored by
 * subscriptions.
 */
public void abort() {
 // discard all fragments by set the type to padding
 int fragmentOffset = 0;
 while (fragmentOffset < nextOffset) {
  final int fragmentLength = -buffer.getInt(lengthOffset(fragmentOffset));
  buffer.putInt(typeOffset(fragmentOffset), TYPE_PADDING);
  buffer.putIntOrdered(lengthOffset(fragmentOffset), fragmentLength);
  fragmentOffset += DataFrameDescriptor.alignedLength(fragmentLength);
 }
 fillRemainingBatchSize();
 onCompleteHandler.run();
 reset();
}
origin: zeebe-io/zeebe

/**
 * Finish reading and consume the fragments (i.e. update the subscription position). Mark all
 * fragments as failed.
 */
public void markFailed() {
 int fragmentOffset = 0;
 while (fragmentOffset < blockLength) {
  int framedFragmentLength =
    bufferView.getInt(DataFrameDescriptor.lengthOffset(fragmentOffset));
  if (framedFragmentLength < 0) {
   framedFragmentLength = -framedFragmentLength;
  }
  final int frameLength = DataFrameDescriptor.alignedLength(framedFragmentLength);
  final int flagsOffset = DataFrameDescriptor.flagsOffset(fragmentOffset);
  final byte flags = bufferView.getByte(flagsOffset);
  bufferView.putByte(flagsOffset, DataFrameDescriptor.enableFlagFailed(flags));
  fragmentOffset += frameLength;
 }
 updatePosition();
}
origin: zeebe-io/zeebe

public static int getFragmentLength(final DirectBuffer buffer, final int offset) {
 return alignedLength(buffer.getInt(lengthOffset(offset), Protocol.ENDIANNESS));
}
origin: zeebe-io/zeebe

public void wrap(final DirectBuffer buffer, final int offset) {
 this.fragmentOffset = offset;
 this.messageOffset = messageOffset(fragmentOffset);
 this.buffer = buffer;
}
origin: zeebe-io/zeebe

public static int getFramedMessageLength(int messageLength) {
 return DataFrameDescriptor.alignedLength(MESSAGE_HEADER_LENGTH + messageLength);
}
origin: zeebe-io/zeebe

protected Answer<?> claimFragment(final long offset) {
 return invocation -> {
  final ClaimedFragment claimedFragment = (ClaimedFragment) invocation.getArguments()[0];
  final int length = (int) invocation.getArguments()[1];
  fragmentOffset = claimedFragment.getOffset();
  claimedFragment.wrap(sendBuffer, 0, alignedFramedLength(length), () -> {});
  final long claimedPosition = offset + alignedFramedLength(length);
  return claimedPosition;
 };
}
origin: zeebe-io/zeebe

/** Commit the fragment so that it can be read by subscriptions. */
public void commit() {
 // commit the message by writing the positive framed length
 buffer.putIntOrdered(lengthOffset(0), buffer.capacity());
 onCompleteHandler.run();
 reset();
}
origin: zeebe-io/zeebe

@SuppressWarnings("restriction")
public int appendFrame(
  final LogBufferPartition partition,
  final int activePartitionId,
  final DirectBuffer msg,
  final int start,
  final int length,
  final int streamId) {
 final int partitionSize = partition.getPartitionSize();
 final int framedLength = framedLength(length);
 final int alignedFrameLength = alignedLength(framedLength);
 // move the tail of the partition
 final int frameOffset = partition.getAndAddTail(alignedFrameLength);
 int newTail = frameOffset + alignedFrameLength;
 if (newTail <= (partitionSize - HEADER_LENGTH)) {
  final UnsafeBuffer buffer = partition.getDataBuffer();
  // write negative length field
  buffer.putIntOrdered(lengthOffset(frameOffset), -framedLength);
  UNSAFE.storeFence();
  buffer.putShort(typeOffset(frameOffset), TYPE_MESSAGE);
  buffer.putInt(streamIdOffset(frameOffset), streamId);
  buffer.putBytes(messageOffset(frameOffset), msg, start, length);
  // commit the message
  buffer.putIntOrdered(lengthOffset(frameOffset), framedLength);
 } else {
  newTail = onEndOfPartition(partition, frameOffset);
 }
 return newTail;
}
origin: io.zeebe/zb-dispatcher

final int framedLength = buffer.getIntVolatile(lengthOffset(fragmentOffset));
if (framedLength <= 0) {
 break;
final short type = buffer.getShort(typeOffset(fragmentOffset));
if (type == TYPE_PADDING) {
 fragmentOffset += alignedLength(framedLength);
 final int streamId = buffer.getInt(streamIdOffset(fragmentOffset));
 final int flagsOffset = flagsOffset(fragmentOffset);
 final byte flags = buffer.getByte(flagsOffset);
 try {
  final boolean isMarkedAsFailed = flagFailed(flags);
  final int messageLength = messageLength(framedLength);
  final int handlerResult =
    frgHandler.onFragment(
      buffer, messageOffset(fragmentOffset), messageLength, streamId, isMarkedAsFailed);
   buffer.putByte(flagsOffset, DataFrameDescriptor.enableFlagFailed(flags));
  fragmentOffset += alignedLength(framedLength);
origin: io.zeebe/zb-dispatcher

final int framedLength = buffer.getIntVolatile(lengthOffset(partitionOffset));
if (framedLength <= 0) {
 break;
final short type = buffer.getShort(typeOffset(partitionOffset));
if (type == TYPE_PADDING) {
 partitionOffset += alignedLength(framedLength);
  final int streamId = buffer.getInt(streamIdOffset(partitionOffset));
  if (readBytes == 0) {
   initialStreamId = streamId;
 final byte flags = buffer.getByte(flagsOffset(partitionOffset));
 if (!isReadingBatch) {
  isReadingBatch = flagBatchBegin(flags);
 } else {
  isReadingBatch = !flagBatchEnd(flags);
 final int alignedFrameLength = alignedLength(framedLength);
 if (alignedFrameLength <= maxBlockSize - readBytes) {
  partitionOffset += alignedFrameLength;
io.zeebe.dispatcher.impl.logDataFrameDescriptor

Javadoc

 
0                   1                   2                   3 
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 
|R|                        Frame Length                         | 
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-------------------------------+ 
|  Version      |B|E|F| Flags   |             Type              | 
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-------------------------------+ 
|                            StreamId                           | 
+---------------------------------------------------------------+ 
|                                                               | 
|                            Message                           ... 
...                                                              | 
+---------------------------------------------------------------+ 

Frame length: Including the length of the header to ensure length is always > 0 which is important for distinguishing committed from uncommitted but claimed fragments.

Flags:

  • B: Begin Batch
  • E: End Batch
  • F: Failed (e.g. set by a prior subscriber)

Most used methods

  • alignedLength
  • lengthOffset
  • messageLength
  • messageOffset
  • alignedFramedLength
  • streamIdOffset
  • typeOffset
  • enableFlagBatchBegin
  • enableFlagBatchEnd
  • enableFlagFailed
  • flagBatchBegin
  • flagBatchEnd
  • flagBatchBegin,
  • flagBatchEnd,
  • flagFailed,
  • flagsOffset,
  • framedLength,
  • versionOffset

Popular in Java

  • Reactive rest calls using spring rest template
  • onCreateOptionsMenu (Activity)
  • getApplicationContext (Context)
  • setScale (BigDecimal)
  • BufferedInputStream (java.io)
    A BufferedInputStream adds functionality to another input stream-namely, the ability to buffer the i
  • OutputStream (java.io)
    A writable sink for bytes.Most clients will use output streams that write data to the file system (
  • Collection (java.util)
    Collection is the root of the collection hierarchy. It defines operations on data collections and t
  • Map (java.util)
    A Map is a data structure consisting of a set of keys and values in which each key is mapped to a si
  • Logger (org.apache.log4j)
    This is the central class in the log4j package. Most logging operations, except configuration, are d
  • Scheduler (org.quartz)
    This is the main interface of a Quartz Scheduler. A Scheduler maintains a registry of org.quartz.Job
  • Best plugins for Eclipse
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now