use of org.agrona.MutableDirectBuffer in project deeplearning4j by deeplearning4j.
the class SbeStatsInitializationReport method encode.
@Override
public byte[] encode() {
byte[] bytes = new byte[encodingLengthBytes()];
MutableDirectBuffer buffer = new UnsafeBuffer(bytes);
encode(buffer);
return bytes;
}
use of org.agrona.MutableDirectBuffer in project deeplearning4j by deeplearning4j.
the class SbeStatsReport method encode.
@Override
public byte[] encode() {
byte[] bytes = new byte[encodingLengthBytes()];
MutableDirectBuffer buffer = new UnsafeBuffer(bytes);
encode(buffer);
return bytes;
}
use of org.agrona.MutableDirectBuffer in project deeplearning4j by deeplearning4j.
the class SbeStatsReport method decode.
@Override
public void decode(byte[] decode) {
MutableDirectBuffer buffer = new UnsafeBuffer(decode);
decode(buffer);
}
use of org.agrona.MutableDirectBuffer in project aeron by real-logic.
the class ClientConductorTest method setUp.
@Before
public void setUp() {
final Aeron.Context ctx = new Aeron.Context().clientLock(mockClientLock).epochClock(epochClock).nanoClock(nanoClock).toClientBuffer(mockToClientReceiver).driverProxy(driverProxy).logBuffersFactory(logBuffersFactory).errorHandler(mockClientErrorHandler).availableImageHandler(mockAvailableImageHandler).unavailableImageHandler(mockUnavailableImageHandler).keepAliveInterval(KEEP_ALIVE_INTERVAL).driverTimeoutMs(AWAIT_TIMEOUT).interServiceTimeout(TimeUnit.MILLISECONDS.toNanos(INTER_SERVICE_TIMEOUT_MS));
ctx.countersValuesBuffer(counterValuesBuffer);
when(mockClientLock.tryLock()).thenReturn(TRUE);
when(driverProxy.addPublication(CHANNEL, STREAM_ID_1)).thenReturn(CORRELATION_ID);
when(driverProxy.addPublication(CHANNEL, STREAM_ID_2)).thenReturn(CORRELATION_ID_2);
when(driverProxy.removePublication(CORRELATION_ID)).thenReturn(CLOSE_CORRELATION_ID);
when(driverProxy.addSubscription(anyString(), anyInt())).thenReturn(CORRELATION_ID);
when(driverProxy.removeSubscription(CORRELATION_ID)).thenReturn(CLOSE_CORRELATION_ID);
conductor = new ClientConductor(ctx);
publicationReady.wrap(publicationReadyBuffer, 0);
subscriptionReady.wrap(subscriptionReadyBuffer, 0);
operationSuccess.wrap(operationSuccessBuffer, 0);
errorResponse.wrap(errorMessageBuffer, 0);
publicationReady.correlationId(CORRELATION_ID);
publicationReady.registrationId(CORRELATION_ID);
publicationReady.sessionId(SESSION_ID_1);
publicationReady.streamId(STREAM_ID_1);
publicationReady.logFileName(SESSION_ID_1 + "-log");
operationSuccess.correlationId(CLOSE_CORRELATION_ID);
final UnsafeBuffer[] termBuffersSession1 = new UnsafeBuffer[PARTITION_COUNT];
final UnsafeBuffer[] termBuffersSession2 = new UnsafeBuffer[PARTITION_COUNT];
for (int i = 0; i < PARTITION_COUNT; i++) {
termBuffersSession1[i] = new UnsafeBuffer(allocateDirect(TERM_BUFFER_LENGTH));
termBuffersSession2[i] = new UnsafeBuffer(allocateDirect(TERM_BUFFER_LENGTH));
}
final UnsafeBuffer logMetaDataSession1 = new UnsafeBuffer(allocateDirect(TERM_BUFFER_LENGTH));
final UnsafeBuffer logMetaDataSession2 = new UnsafeBuffer(allocateDirect(TERM_BUFFER_LENGTH));
final MutableDirectBuffer header1 = DataHeaderFlyweight.createDefaultHeader(SESSION_ID_1, STREAM_ID_1, 0);
final MutableDirectBuffer header2 = DataHeaderFlyweight.createDefaultHeader(SESSION_ID_2, STREAM_ID_2, 0);
LogBufferDescriptor.storeDefaultFrameHeader(logMetaDataSession1, header1);
LogBufferDescriptor.storeDefaultFrameHeader(logMetaDataSession2, header2);
final LogBuffers logBuffersSession1 = mock(LogBuffers.class);
final LogBuffers logBuffersSession2 = mock(LogBuffers.class);
when(logBuffersFactory.map(SESSION_ID_1 + "-log")).thenReturn(logBuffersSession1);
when(logBuffersFactory.map(SESSION_ID_2 + "-log")).thenReturn(logBuffersSession2);
when(logBuffersFactory.map(SESSION_ID_1 + "-log")).thenReturn(logBuffersSession1);
when(logBuffersFactory.map(SESSION_ID_2 + "-log")).thenReturn(logBuffersSession2);
when(logBuffersSession1.duplicateTermBuffers()).thenReturn(termBuffersSession1);
when(logBuffersSession2.duplicateTermBuffers()).thenReturn(termBuffersSession2);
when(logBuffersSession1.metaDataBuffer()).thenReturn(logMetaDataSession1);
when(logBuffersSession2.metaDataBuffer()).thenReturn(logMetaDataSession2);
when(logBuffersSession1.termLength()).thenReturn(TERM_BUFFER_LENGTH);
when(logBuffersSession2.termLength()).thenReturn(TERM_BUFFER_LENGTH);
}
use of org.agrona.MutableDirectBuffer in project aeron by real-logic.
the class FileSender method sendChunk.
private static void sendChunk(final Publication publication, final BufferClaim bufferClaim, final long correlationId, final UnsafeBuffer fileBuffer, final int chunkOffset, final int chunkLength) {
long result;
while ((result = publication.tryClaim(CHUNK_PAYLOAD_OFFSET + chunkLength, bufferClaim)) < 0) {
checkResult(result);
Thread.yield();
}
final MutableDirectBuffer buffer = bufferClaim.buffer();
final int offset = bufferClaim.offset();
buffer.putInt(offset + VERSION_OFFSET, VERSION, LITTLE_ENDIAN);
buffer.putInt(offset + TYPE_OFFSET, FILE_CHUNK_TYPE, LITTLE_ENDIAN);
buffer.putLong(offset + CORRELATION_ID_OFFSET, correlationId, LITTLE_ENDIAN);
buffer.putLong(offset + CHUNK_OFFSET_OFFSET, chunkOffset, LITTLE_ENDIAN);
buffer.putLong(offset + CHUNK_LENGTH_OFFSET, chunkLength, LITTLE_ENDIAN);
buffer.putBytes(offset + CHUNK_PAYLOAD_OFFSET, fileBuffer, chunkOffset, chunkLength);
bufferClaim.commit();
}
Aggregations