use of org.agrona.DirectBuffer in project aeron by real-logic.
the class RecordingPos method countBySession.
/**
* Count the number of counters for a given session. It is possible for different recording to exist on the
* same session if there are images under subscriptions with different channel and stream id.
*
* @param countersReader to search within.
* @param sessionId to search for.
* @return the count of recordings matching a session id.
*/
public static int countBySession(final CountersReader countersReader, final int sessionId) {
int count = 0;
final DirectBuffer buffer = countersReader.metaDataBuffer();
for (int i = 0, size = countersReader.maxCounterId(); i < size; i++) {
if (countersReader.getCounterState(i) == RECORD_ALLOCATED) {
final int recordOffset = CountersReader.metaDataOffset(i);
if (buffer.getInt(recordOffset + TYPE_ID_OFFSET) == RECORDING_POSITION_TYPE_ID && buffer.getInt(recordOffset + KEY_OFFSET + SESSION_ID_OFFSET) == sessionId) {
++count;
}
}
}
return count;
}
use of org.agrona.DirectBuffer in project aeron by real-logic.
the class MultiSubscriberTest method verifyData.
private void verifyData(final UnsafeBuffer srcBuffer, final FragmentHandler mockFragmentHandler) {
final ArgumentCaptor<DirectBuffer> bufferArg = ArgumentCaptor.forClass(DirectBuffer.class);
final ArgumentCaptor<Integer> offsetArg = ArgumentCaptor.forClass(Integer.class);
verify(mockFragmentHandler, times(1)).onFragment(bufferArg.capture(), offsetArg.capture(), eq(srcBuffer.capacity()), any(Header.class));
final DirectBuffer capturedBuffer = bufferArg.getValue();
final int offset = offsetArg.getValue();
for (int i = 0; i < srcBuffer.capacity(); i++) {
final int index = offset + i;
assertThat("same at " + index, capturedBuffer.getByte(index), is(srcBuffer.getByte(i)));
}
}
use of org.agrona.DirectBuffer in project aeron by real-logic.
the class DriverTool method main.
public static void main(final String[] args) throws Exception {
boolean printPidOnly = false;
if (0 != args.length) {
checkForHelp(args);
if (args[0].equals("pid")) {
printPidOnly = true;
}
}
final File cncFile = CommonContext.newDefaultCncFile();
final MappedByteBuffer cncByteBuffer = IoUtil.mapExistingFile(cncFile, "cnc");
final DirectBuffer cncMetaData = createMetaDataBuffer(cncByteBuffer);
final int cncVersion = cncMetaData.getInt(cncVersionOffset(0));
if (CncFileDescriptor.CNC_VERSION != cncVersion) {
throw new IllegalStateException("Aeron CnC version does not match: version=" + cncVersion + " required=" + CNC_VERSION);
}
final ManyToOneRingBuffer toDriver = new ManyToOneRingBuffer(createToDriverBuffer(cncByteBuffer, cncMetaData));
if (printPidOnly) {
System.out.println(pid(cncMetaData));
} else {
System.out.println("Command `n Control file %s" + cncFile);
System.out.format("Version: %d, PID: %d%n", cncVersion, pid(cncMetaData));
printDateActivityAndStartTimestamps(startTimestamp(cncMetaData), toDriver.consumerHeartbeatTime());
}
}
use of org.agrona.DirectBuffer in project aeron by real-logic.
the class AuthenticationTest method launchService.
private void launchService(final MutableLong sessionId, final MutableReference<byte[]> encodedPrincipal, final AtomicLong msgCounter) {
final ClusteredService service = new StubClusteredService() {
private int counterValue = 0;
public void onSessionOpen(final ClientSession session, final long timestampMs) {
sessionId.value = session.id();
encodedPrincipal.set(session.encodedPrincipal());
}
public void onSessionMessage(final long clusterSessionId, final long correlationId, final long timestampMs, final DirectBuffer buffer, final int offset, final int length, final Header header) {
assertThat(buffer.getInt(offset), is(counterValue));
msgCounter.getAndIncrement();
counterValue++;
}
};
container = null;
container = ClusteredServiceContainer.launch(new ClusteredServiceContainer.Context().clusteredService(service).errorHandler(Throwable::printStackTrace).deleteDirOnStart(true));
}
use of org.agrona.DirectBuffer in project aeron by real-logic.
the class ClusterNodeTest method shouldScheduleEventInService.
@Test(timeout = 10_000)
public void shouldScheduleEventInService() {
container = launchTimedService();
aeronCluster = connectToCluster();
final Aeron aeron = aeronCluster.context().aeron();
final SessionDecorator sessionDecorator = new SessionDecorator(aeronCluster.clusterSessionId());
final Publication publication = aeronCluster.ingressPublication();
final ExpandableArrayBuffer msgBuffer = new ExpandableArrayBuffer();
final long msgCorrelationId = aeron.nextCorrelationId();
final String msg = "Hello World!";
msgBuffer.putStringWithoutLengthAscii(0, msg);
while (sessionDecorator.offer(publication, msgCorrelationId, msgBuffer, 0, msg.length()) < 0) {
TestUtil.checkInterruptedStatus();
Thread.yield();
}
final MutableInteger messageCount = new MutableInteger();
final EgressAdapter adapter = new EgressAdapter(new StubEgressListener() {
public void onMessage(final long correlationId, final long clusterSessionId, final long timestamp, final DirectBuffer buffer, final int offset, final int length, final Header header) {
assertThat(correlationId, is(msgCorrelationId));
assertThat(buffer.getStringWithoutLengthAscii(offset, length), is(msg + "-scheduled"));
messageCount.value += 1;
}
}, aeronCluster.egressSubscription(), FRAGMENT_LIMIT);
while (messageCount.get() == 0) {
if (adapter.poll() <= 0) {
TestUtil.checkInterruptedStatus();
Thread.yield();
}
}
}
Aggregations