Java Code Examples for io.aeron.Aeron#NULL_VALUE
The following examples show how to use
io.aeron.Aeron#NULL_VALUE .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StatusUtil.java From aeron with Apache License 2.0 | 6 votes |
/** * Return the controllable idle strategy {@link StatusIndicator}. * * @param countersReader that holds the status indicator. * @return status indicator to use or null if not found. */ public static StatusIndicator controllableIdleStrategy(final CountersReader countersReader) { StatusIndicator statusIndicator = null; final MutableInteger id = new MutableInteger(-1); countersReader.forEach( (counterId, label) -> { if (counterId == SystemCounterDescriptor.CONTROLLABLE_IDLE_STRATEGY.id() && label.equals(SystemCounterDescriptor.CONTROLLABLE_IDLE_STRATEGY.label())) { id.value = counterId; } }); if (Aeron.NULL_VALUE != id.value) { statusIndicator = new UnsafeBufferStatusIndicator(countersReader.valuesBuffer(), id.value); } return statusIndicator; }
Example 2
Source File: ClusterCounters.java From aeron with Apache License 2.0 | 6 votes |
/** * Find the counter id for a type of counter in a cluster. * * @param counters to search within. * @param typeId of the counter. * @param clusterId to which the allocated counter belongs. * @return the matching counter id or {@link Aeron#NULL_VALUE} if not found. */ public static int find(final CountersReader counters, final int typeId, final int clusterId) { final AtomicBuffer buffer = counters.metaDataBuffer(); for (int i = 0, size = counters.maxCounterId(); i < size; i++) { final int recordOffset = CountersReader.metaDataOffset(i); if (counters.getCounterState(i) == RECORD_ALLOCATED && counters.getCounterTypeId(i) == typeId && buffer.getInt(recordOffset + KEY_OFFSET) == clusterId) { return i; } } return Aeron.NULL_VALUE; }
Example 3
Source File: EmbeddedRecordingThroughput.java From aeron with Apache License 2.0 | 6 votes |
public static void main(final String[] args) { loadPropertiesFiles(args); try (EmbeddedRecordingThroughput test = new EmbeddedRecordingThroughput()) { test.startRecording(); long previousRecordingId = Aeron.NULL_VALUE; final ContinueBarrier barrier = new ContinueBarrier("Execute again?"); do { if (Aeron.NULL_VALUE != previousRecordingId) { test.truncateRecording(previousRecordingId); } previousRecordingId = test.streamMessagesForRecording(); } while (barrier.await()); } }
Example 4
Source File: ConsensusModule.java From aeron with Apache License 2.0 | 5 votes |
/** * Get the current state of the {@link ConsensusModule}. * * @param counters to search within. * @param clusterId to which the allocated counter belongs. * @return the state of the ConsensusModule or null if not found. */ public static State find(final CountersReader counters, final int clusterId) { final int counterId = ClusterCounters.find(counters, CONSENSUS_MODULE_STATE_TYPE_ID, clusterId); if (Aeron.NULL_VALUE != counterId) { return State.get((int)counters.getCounterValue(counterId)); } return null; }
Example 5
Source File: ControlSession.java From aeron with Apache License 2.0 | 5 votes |
private int waitForRequest(final long nowMs) { int workCount = 0; if (hasNoActivity(nowMs)) { state(State.INACTIVE); workCount += 1; } else if (nowMs > resendDeadlineMs) { resendDeadlineMs = nowMs + RESEND_INTERVAL_MS; if (controlResponseProxy.sendResponse( controlSessionId, correlationId, controlSessionId, OK, null, this)) { activityDeadlineMs = Aeron.NULL_VALUE; workCount += 1; } } return workCount; }
Example 6
Source File: EgressPoller.java From aeron with Apache License 2.0 | 5 votes |
public int poll() { clusterSessionId = Aeron.NULL_VALUE; correlationId = Aeron.NULL_VALUE; leadershipTermId = Aeron.NULL_VALUE; leaderMemberId = Aeron.NULL_VALUE; templateId = Aeron.NULL_VALUE; version = 0; eventCode = null; detail = ""; encodedChallenge = null; isPollComplete = false; return subscription.controlledPoll(fragmentAssembler, fragmentLimit); }
Example 7
Source File: RecordingEventsPoller.java From aeron with Apache License 2.0 | 5 votes |
/** * Poll for recording events. * * @return the number of fragments read during the operation. Zero if no events are available. */ public int poll() { templateId = Aeron.NULL_VALUE; pollComplete = false; return subscription.poll(this, 1); }
Example 8
Source File: ControlResponsePoller.java From aeron with Apache License 2.0 | 5 votes |
/** * Poll for control response events. * * @return the number of fragments read during the operation. Zero if no events are available. */ public int poll() { controlSessionId = Aeron.NULL_VALUE; correlationId = Aeron.NULL_VALUE; relevantId = Aeron.NULL_VALUE; version = 0; errorMessage = null; encodedChallenge = null; isPollComplete = false; return subscription.controlledPoll(fragmentAssembler, fragmentLimit); }
Example 9
Source File: RecordingCoordinator.java From artio with Apache License 2.0 | 4 votes |
private boolean recordingAlreadyStarted(final int sessionId) { return RecordingPos.findCounterIdBySession(counters, sessionId) != Aeron.NULL_VALUE; }
Example 10
Source File: ArchiveTest.java From aeron with Apache License 2.0 | 4 votes |
@Test public void shouldRecoverRecordingWithNonZeroStartPosition() { final MediaDriver.Context driverCtx = new MediaDriver.Context() .dirDeleteOnStart(true) .threadingMode(ThreadingMode.SHARED); final Context archiveCtx = new Context().threadingMode(SHARED); long resultingPosition; final int initialPosition = DataHeaderFlyweight.HEADER_LENGTH * 9; final long recordingId; try (ArchivingMediaDriver ignore = ArchivingMediaDriver.launch(driverCtx.clone(), archiveCtx.clone()); AeronArchive archive = AeronArchive.connect()) { final int termLength = 128 * 1024; final int initialTermId = 29; final String channel = new ChannelUriStringBuilder() .media(CommonContext.IPC_MEDIA) .initialPosition(initialPosition, initialTermId, termLength) .build(); final Publication publication = archive.addRecordedExclusivePublication(channel, 1); final DirectBuffer buffer = new UnsafeBuffer("Hello World".getBytes(StandardCharsets.US_ASCII)); while ((resultingPosition = publication.offer(buffer)) <= 0) { Tests.yield(); } final Aeron aeron = archive.context().aeron(); int counterId; final int sessionId = publication.sessionId(); final CountersReader countersReader = aeron.countersReader(); while (Aeron.NULL_VALUE == (counterId = RecordingPos.findCounterIdBySession(countersReader, sessionId))) { Tests.yield(); } recordingId = RecordingPos.getRecordingId(countersReader, counterId); while (countersReader.getCounterValue(counterId) < resultingPosition) { Tests.yield(); } } try (Catalog catalog = openCatalog(archiveCtx)) { final Catalog.CatalogEntryProcessor catalogEntryProcessor = (headerEncoder, headerDecoder, descriptorEncoder, descriptorDecoder) -> descriptorEncoder.stopPosition(Aeron.NULL_VALUE); assertTrue(catalog.forEntry(recordingId, catalogEntryProcessor)); } final Context archiveCtxClone = archiveCtx.clone(); final MediaDriver.Context driverCtxClone = driverCtx.clone(); try (ArchivingMediaDriver ignore = ArchivingMediaDriver.launch(driverCtxClone, archiveCtxClone); AeronArchive archive = AeronArchive.connect()) { assertEquals(initialPosition, archive.getStartPosition(recordingId)); assertEquals(resultingPosition, archive.getStopPosition(recordingId)); } finally { archiveCtxClone.deleteDirectory(); driverCtxClone.deleteDirectory(); } }
Example 11
Source File: Catalog.java From aeron with Apache License 2.0 | 4 votes |
private static int recoverStopOffset( final File archiveDir, final String segmentFile, final int offset, final int segmentFileLength, final Predicate<File> truncateFileOnPageStraddle, final Checksum checksum, final UnsafeBuffer buffer) { final File file = new File(archiveDir, segmentFile); try (FileChannel segment = FileChannel.open(file.toPath(), READ, WRITE)) { final int offsetLimit = (int)min(segmentFileLength, segment.size()); final ByteBuffer byteBuffer = buffer.byteBuffer(); int nextFragmentOffset = offset; int lastFragmentLength = 0; int bufferOffset = 0; out: while (nextFragmentOffset < offsetLimit) { final int bytesRead = readNextChunk(segment, byteBuffer, nextFragmentOffset, offsetLimit); bufferOffset = 0; while (bufferOffset < bytesRead) { final int frameLength = frameLength(buffer, bufferOffset); if (frameLength <= 0) { break out; } lastFragmentLength = align(frameLength, FRAME_ALIGNMENT); nextFragmentOffset += lastFragmentLength; bufferOffset += lastFragmentLength; } } final int lastFragmentOffset = nextFragmentOffset - lastFragmentLength; if (fragmentStraddlesPageBoundary(lastFragmentOffset, lastFragmentLength) && !isValidFragment(buffer, bufferOffset - lastFragmentLength, lastFragmentLength, checksum) && truncateFileOnPageStraddle.test(file)) { segment.truncate(lastFragmentOffset); byteBuffer.put(0, (byte)0).limit(1).position(0); segment.write(byteBuffer, segmentFileLength - 1); return lastFragmentOffset; } else { return nextFragmentOffset; } } catch (final IOException ex) { LangUtil.rethrowUnchecked(ex); return Aeron.NULL_VALUE; } }
Example 12
Source File: RecordingEventsPoller.java From aeron with Apache License 2.0 | 4 votes |
public void onFragment(final DirectBuffer buffer, final int offset, final int length, final Header header) { messageHeaderDecoder.wrap(buffer, offset); final int schemaId = messageHeaderDecoder.schemaId(); if (schemaId != MessageHeaderDecoder.SCHEMA_ID) { throw new ArchiveException("expected schemaId=" + MessageHeaderDecoder.SCHEMA_ID + ", actual=" + schemaId); } templateId = messageHeaderDecoder.templateId(); switch (templateId) { case RecordingStartedDecoder.TEMPLATE_ID: recordingStartedDecoder.wrap( buffer, offset + MessageHeaderDecoder.ENCODED_LENGTH, messageHeaderDecoder.blockLength(), messageHeaderDecoder.version()); recordingId = recordingStartedDecoder.recordingId(); recordingStartPosition = recordingStartedDecoder.startPosition(); recordingPosition = recordingStartPosition; recordingStopPosition = Aeron.NULL_VALUE; pollComplete = true; break; case RecordingProgressDecoder.TEMPLATE_ID: recordingProgressDecoder.wrap( buffer, offset + MessageHeaderDecoder.ENCODED_LENGTH, messageHeaderDecoder.blockLength(), messageHeaderDecoder.version()); recordingId = recordingProgressDecoder.recordingId(); recordingStartPosition = recordingProgressDecoder.startPosition(); recordingPosition = recordingProgressDecoder.position(); recordingStopPosition = Aeron.NULL_VALUE; pollComplete = true; break; case RecordingStoppedDecoder.TEMPLATE_ID: recordingStoppedDecoder.wrap( buffer, offset + MessageHeaderDecoder.ENCODED_LENGTH, messageHeaderDecoder.blockLength(), messageHeaderDecoder.version()); recordingId = recordingStoppedDecoder.recordingId(); recordingStartPosition = recordingStoppedDecoder.startPosition(); recordingStopPosition = recordingStoppedDecoder.stopPosition(); recordingPosition = recordingStopPosition; pollComplete = true; break; } }
Example 13
Source File: ControlResponsePoller.java From aeron with Apache License 2.0 | 4 votes |
public ControlledFragmentAssembler.Action onFragment( final DirectBuffer buffer, final int offset, final int length, final Header header) { if (isPollComplete) { return Action.ABORT; } messageHeaderDecoder.wrap(buffer, offset); final int schemaId = messageHeaderDecoder.schemaId(); if (schemaId != MessageHeaderDecoder.SCHEMA_ID) { throw new ArchiveException("expected schemaId=" + MessageHeaderDecoder.SCHEMA_ID + ", actual=" + schemaId); } if (messageHeaderDecoder.templateId() == ControlResponseDecoder.TEMPLATE_ID) { controlResponseDecoder.wrap( buffer, offset + MessageHeaderEncoder.ENCODED_LENGTH, messageHeaderDecoder.blockLength(), messageHeaderDecoder.version()); controlSessionId = controlResponseDecoder.controlSessionId(); correlationId = controlResponseDecoder.correlationId(); relevantId = controlResponseDecoder.relevantId(); code = controlResponseDecoder.code(); version = controlResponseDecoder.version(); errorMessage = controlResponseDecoder.errorMessage(); isPollComplete = true; return Action.BREAK; } if (messageHeaderDecoder.templateId() == ChallengeDecoder.TEMPLATE_ID) { challengeDecoder.wrap( buffer, offset + MessageHeaderEncoder.ENCODED_LENGTH, messageHeaderDecoder.blockLength(), messageHeaderDecoder.version()); controlSessionId = challengeDecoder.controlSessionId(); correlationId = challengeDecoder.correlationId(); relevantId = Aeron.NULL_VALUE; code = ControlResponseCode.NULL_VAL; version = challengeDecoder.version(); errorMessage = ""; final int encodedChallengeLength = challengeDecoder.encodedChallengeLength(); encodedChallenge = new byte[encodedChallengeLength]; challengeDecoder.getEncodedChallenge(encodedChallenge, 0, encodedChallengeLength); isPollComplete = true; return Action.BREAK; } return Action.CONTINUE; }
Example 14
Source File: ArchiveException.java From aeron with Apache License 2.0 | 4 votes |
public ArchiveException(final String message, final Category category) { super(message, category); this.errorCode = GENERIC; this.correlationId = Aeron.NULL_VALUE; }
Example 15
Source File: ArchiveException.java From aeron with Apache License 2.0 | 4 votes |
public ArchiveException(final String message, final Throwable cause, final int errorCode) { super(message, cause); this.errorCode = errorCode; correlationId = Aeron.NULL_VALUE; }
Example 16
Source File: ArchiveException.java From aeron with Apache License 2.0 | 4 votes |
public ArchiveException() { super(); errorCode = GENERIC; correlationId = Aeron.NULL_VALUE; }
Example 17
Source File: AbstractListRecordingsSession.java From aeron with Apache License 2.0 | 4 votes |
public long sessionId() { return Aeron.NULL_VALUE; }
Example 18
Source File: ListRecordingSubscriptionsSession.java From aeron with Apache License 2.0 | 4 votes |
public long sessionId() { return Aeron.NULL_VALUE; }
Example 19
Source File: ControlSession.java From aeron with Apache License 2.0 | 4 votes |
private boolean hasNoActivity(final long nowMs) { return Aeron.NULL_VALUE != activityDeadlineMs && nowMs > activityDeadlineMs; }
Example 20
Source File: ReadableCounter.java From aeron with Apache License 2.0 | 2 votes |
/** * Construct a view of an existing counter. * * @param countersReader for getting access to the buffers. * @param counterId for the counter to be viewed. * @throws IllegalStateException if the id has for the counter has not been allocated. */ public ReadableCounter(final CountersReader countersReader, final int counterId) { this(countersReader, Aeron.NULL_VALUE, counterId); }