private static void offer(final Publication publication, final int count, final String prefix) { final ExpandableArrayBuffer buffer = new ExpandableArrayBuffer(); for (int i = 0; i < count; i++) { final int length = buffer.putStringWithoutLengthAscii(0, prefix + i); while (publication.offer(buffer, 0, length) <= 0) { SystemTest.checkInterruptedStatus(); Thread.yield(); } } }
putByte(index, ZERO); return 1; putBytes(index, MIN_INTEGER_VALUE); return MIN_INTEGER_VALUE.length; if (value < 0) putByte(index, MINUS_SIGN); start++; length++; length += i; ensureCapacity(index, length);
public int compareTo(final DirectBuffer that) { final int thisCapacity = this.capacity(); final int thatCapacity = that.capacity(); final byte[] thisByteArray = this.byteArray; final byte[] thatByteArray = that.byteArray(); final long thisOffset = this.addressOffset(); final long thatOffset = that.addressOffset(); for (int i = 0, length = Math.min(thisCapacity, thatCapacity); i < length; i++) { final int cmp = Byte.compare( UNSAFE.getByte(thisByteArray, thisOffset + i), UNSAFE.getByte(thatByteArray, thatOffset + i)); if (0 != cmp) { return cmp; } } if (thisCapacity != thatCapacity) { return thisCapacity - thatCapacity; } return 0; }
public String getStringAscii(final int index) { boundsCheck0(index, SIZE_OF_INT); final int length = UNSAFE.getInt(byteArray, ARRAY_BASE_OFFSET + index); return getStringAscii(index, length); }
public String getStringUtf8(final int index) { boundsCheck0(index, SIZE_OF_INT); final int length = UNSAFE.getInt(byteArray, ARRAY_BASE_OFFSET + index); return getStringUtf8(index, length); }
private static void sendFileCreate( final Publication publication, final long correlationId, final int length, final String filename) { final ExpandableArrayBuffer buffer = new ExpandableArrayBuffer(); buffer.putInt(VERSION_OFFSET, VERSION, LITTLE_ENDIAN); buffer.putInt(TYPE_OFFSET, FILE_CREATE_TYPE, LITTLE_ENDIAN); buffer.putLong(CORRELATION_ID_OFFSET, correlationId, LITTLE_ENDIAN); buffer.putLong(FILE_LENGTH_OFFSET, length, LITTLE_ENDIAN); final int msgLength = FILE_NAME_OFFSET + buffer.putStringUtf8(FILE_NAME_OFFSET, filename); long result; while ((result = publication.offer(buffer, 0, msgLength)) < 0) { checkResult(result); Thread.yield(); } }
@Test public void shouldBeLess() { final MutableDirectBuffer lhsBuffer = new ExpandableArrayBuffer(); final MutableDirectBuffer rhsBuffer = new ExpandableArrayBuffer(); lhsBuffer.putStringUtf8(0, "124"); rhsBuffer.putStringUtf8(0, "123"); assertThat(lhsBuffer.compareTo(rhsBuffer), greaterThan(0)); } }
private void reprocessPendingDeployments() { deploymentsState.foreachPending( ((pendingDeploymentDistribution, key) -> { final ExpandableArrayBuffer buffer = new ExpandableArrayBuffer(); final DirectBuffer deployment = pendingDeploymentDistribution.getDeployment(); buffer.putBytes(0, deployment, 0, deployment.capacity()); distributeDeployment(key, pendingDeploymentDistribution.getSourcePosition(), buffer); })); }
public void dumpMetrics(PrintStream ps) { final ExpandableArrayBuffer buff = new ExpandableArrayBuffer(); metricsManager.dump(buff, 0, System.currentTimeMillis()); try { ps.write(buff.byteArray()); } catch (IOException e) { e.printStackTrace(); } }
public void onTakeSnapshot(final Publication snapshotPublication) { final ExpandableArrayBuffer buffer = new ExpandableArrayBuffer(); int length = 0; buffer.putInt(length, nextCorrelationId); length += SIZE_OF_INT; buffer.putInt(length, counterValue); length += SIZE_OF_INT; length += buffer.putStringAscii(length, Integer.toString(counterValue)); snapshotPublication.offer(buffer, 0, length); }
public void onTakeSnapshot(final Publication snapshotPublication) { final ExpandableArrayBuffer buffer = new ExpandableArrayBuffer(); int length = 0; buffer.putInt(length, messageCount); length += SIZE_OF_INT; snapshotPublication.offer(buffer, 0, length); wasSnapshotTaken = true; }
public void putBytes(final int index, final byte[] src) { putBytes(index, src, 0, src.length); }
public void boundsCheck(final int index, final int length) { boundsCheck0(index, length); }
public int putStringUtf8(final int index, final String value, final int maxEncodedSize) { final byte[] bytes = value != null ? value.getBytes(UTF_8) : NULL_BYTES; if (bytes.length > maxEncodedSize) { throw new IllegalArgumentException("Encoded string larger than maximum size: " + maxEncodedSize); } putInt(index, bytes.length); putBytes(index + SIZE_OF_INT, bytes); return SIZE_OF_INT + bytes.length; }
private void setResult(int mappingIndex, int offset, int length, boolean fromSourceDocument) { int mappingResultOffset = mapToResultIndex(mappingIndex); mappingResults.putInt(mappingResultOffset, offset); mappingResultOffset += BitUtil.SIZE_OF_INT; mappingResults.putInt(mappingResultOffset, length); mappingResultOffset += BitUtil.SIZE_OF_INT; mappingResults.putByte(mappingResultOffset, fromSourceDocument ? (byte) 1 : (byte) 0); }
public int putStringUtf8(final int index, final String value) { return putStringUtf8(index, value, Integer.MAX_VALUE); }
private DirectBuffer getValue(long columnFamilyHandle, int keyLength) { final int valueLength = valueBuffer.capacity(); try { final int readBytes = get( nativeHandle_, keyBuffer.byteArray(), 0, keyLength, valueBuffer.byteArray(), 0, valueLength, columnFamilyHandle); if (readBytes >= valueLength) { valueBuffer.checkLimit(readBytes); return getValue(columnFamilyHandle, keyLength); } else if (readBytes <= RocksDB.NOT_FOUND) { return null; } else { valueViewBuffer.wrap(valueBuffer, 0, readBytes); return valueViewBuffer; } } catch (RocksDBException e) { throw new RuntimeException("Unexpected error trying to read RocksDB entry", e); } }
public int parseIntAscii(final int index, final int length) { boundsCheck0(index, length); final int endExclusive = index + length; final int first = getByte(index); int i = index; if (first == MINUS_SIGN) { i++; } int tally = 0; for (; i < endExclusive; i++) { tally = (tally * 10) + AsciiEncoding.getDigit(i, byteArray[i]); } if (first == MINUS_SIGN) { tally = -tally; } return tally; }
private void sendTimerMessageIntoCluster(final int value, final long timerCorrelationId, final long delayMs) { msgBuffer.putInt(MESSAGE_VALUE_OFFSET, value); msgBuffer.putLong(TIMER_MESSAGE_ID_OFFSET, timerCorrelationId); msgBuffer.putLong(TIMER_MESSAGE_DELAY_OFFSET, delayMs); sendBufferIntoCluster(aeronCluster, msgBuffer, TIMER_MESSAGE_LENGTH); }
private void sendCountedMessageIntoCluster(final int value) { msgBuffer.putInt(MESSAGE_VALUE_OFFSET, value); sendBufferIntoCluster(aeronCluster, msgBuffer, MESSAGE_LENGTH); }