Search in sources :

Example 1 with MutableDirectBuffer

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;
}
Also used : MutableDirectBuffer(org.agrona.MutableDirectBuffer) UnsafeBuffer(org.agrona.concurrent.UnsafeBuffer)

Example 2 with MutableDirectBuffer

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;
}
Also used : MutableDirectBuffer(org.agrona.MutableDirectBuffer) UnsafeBuffer(org.agrona.concurrent.UnsafeBuffer)

Example 3 with MutableDirectBuffer

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);
}
Also used : MutableDirectBuffer(org.agrona.MutableDirectBuffer) UnsafeBuffer(org.agrona.concurrent.UnsafeBuffer)

Example 4 with MutableDirectBuffer

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);
}
Also used : MutableDirectBuffer(org.agrona.MutableDirectBuffer) Before(org.junit.Before)

Example 5 with MutableDirectBuffer

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();
}
Also used : MutableDirectBuffer(org.agrona.MutableDirectBuffer)

Aggregations

MutableDirectBuffer (org.agrona.MutableDirectBuffer)34 UnsafeBuffer (org.agrona.concurrent.UnsafeBuffer)13 DirectBuffer (org.agrona.DirectBuffer)7 BeforeEach (org.junit.jupiter.api.BeforeEach)6 Test (org.junit.jupiter.api.Test)6 MediaDriver (io.aeron.driver.MediaDriver)5 ExtendWith (org.junit.jupiter.api.extension.ExtendWith)5 RegisterExtension (org.junit.jupiter.api.extension.RegisterExtension)5 RegistrationException (io.aeron.exceptions.RegistrationException)4 FragmentHandler (io.aeron.logbuffer.FragmentHandler)4 InterruptAfter (io.aeron.test.InterruptAfter)4 InterruptingTestCallback (io.aeron.test.InterruptingTestCallback)4 SystemTestWatcher (io.aeron.test.SystemTestWatcher)4 Tests (io.aeron.test.Tests)4 TestMediaDriver (io.aeron.test.driver.TestMediaDriver)4 Objects.requireNonNull (java.util.Objects.requireNonNull)3 MutableLong (org.agrona.collections.MutableLong)3 Assertions.assertNotEquals (org.junit.jupiter.api.Assertions.assertNotEquals)3 Assertions.assertThrows (org.junit.jupiter.api.Assertions.assertThrows)3 Assumptions.assumeTrue (org.junit.jupiter.api.Assumptions.assumeTrue)3