io.aeron.ExclusivePublication Java Examples
The following examples show how to use
io.aeron.ExclusivePublication.
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: AeronUtil.java From benchmarks with Apache License 2.0 | 6 votes |
static int sendMessages( final ExclusivePublication publication, final UnsafeBuffer offerBuffer, final int numberOfMessages, final int messageLength, final long timestamp, final long checksum) { int count = 0; for (int i = 0; i < numberOfMessages; i++) { offerBuffer.putLong(0, timestamp, LITTLE_ENDIAN); offerBuffer.putLong(messageLength - SIZE_OF_LONG, checksum, LITTLE_ENDIAN); final long result = publication.offer(offerBuffer, 0, messageLength, null); if (result < 0) { checkPublicationResult(result); break; } count++; } return count; }
Example #2
Source File: ConsensusPublisher.java From aeron with Apache License 2.0 | 6 votes |
boolean stopCatchup(final ExclusivePublication publication, final long leadershipTermId, final int followerMemberId) { final int length = MessageHeaderEncoder.ENCODED_LENGTH + StopCatchupEncoder.BLOCK_LENGTH; int attempts = SEND_ATTEMPTS; do { final long result = publication.tryClaim(length, bufferClaim); if (result > 0) { stopCatchupEncoder .wrapAndApplyHeader(bufferClaim.buffer(), bufferClaim.offset(), messageHeaderEncoder) .leadershipTermId(leadershipTermId) .followerMemberId(followerMemberId); bufferClaim.commit(); return true; } checkResult(result); } while (--attempts > 0); return false; }
Example #3
Source File: EngineContext.java From artio with Apache License 2.0 | 6 votes |
private Replayer newReplayer( final ExclusivePublication replayPublication, final ReplayQuery replayQuery) { final EpochFractionFormat epochFractionFormat = configuration.sessionEpochFractionFormat(); return new Replayer( replayQuery, replayPublication, new BufferClaim(), configuration.archiverIdleStrategy(), errorHandler, configuration.outboundMaxClaimAttempts(), inboundLibraryStreams.subscription("replayer"), configuration.agentNamePrefix(), new SystemEpochClock(), configuration.gapfillOnReplayMessageTypes(), configuration.replayHandler(), senderSequenceNumbers, new FixSessionCodecsFactory(epochFractionFormat), configuration.senderMaxBytesInBuffer(), replayerCommandQueue, epochFractionFormat, fixCounters.currentReplayCount(), configuration.maxConcurrentSessionReplays()); }
Example #4
Source File: ReplayerSession.java From artio with Apache License 2.0 | 6 votes |
protected ReplayerSession( final long connectionId, final BufferClaim bufferClaim, final IdleStrategy idleStrategy, final int maxClaimAttempts, final ExclusivePublication publication, final ReplayQuery replayQuery, final int beginSeqNo, final int endSeqNo, final long sessionId, final int sequenceIndex) { this.connectionId = connectionId; this.bufferClaim = bufferClaim; this.idleStrategy = idleStrategy; this.maxClaimAttempts = maxClaimAttempts; this.publication = publication; this.replayQuery = replayQuery; this.beginSeqNo = beginSeqNo; this.endSeqNo = endSeqNo; this.sessionId = sessionId; this.sequenceIndex = sequenceIndex; }
Example #5
Source File: ConsensusPublisher.java From aeron with Apache License 2.0 | 6 votes |
boolean joinCluster(final ExclusivePublication publication, final long leadershipTermId, final int memberId) { final int length = MessageHeaderEncoder.ENCODED_LENGTH + JoinClusterEncoder.BLOCK_LENGTH; int attempts = SEND_ATTEMPTS; do { final long result = publication.tryClaim(length, bufferClaim); if (result > 0) { joinClusterEncoder .wrapAndApplyHeader(bufferClaim.buffer(), bufferClaim.offset(), messageHeaderEncoder) .leadershipTermId(leadershipTermId) .memberId(memberId); bufferClaim.commit(); return true; } checkResult(result); } while (--attempts > 0); return false; }
Example #6
Source File: ILinkReplayerSession.java From artio with Apache License 2.0 | 6 votes |
public ILinkReplayerSession( final long connectionId, final BufferClaim bufferClaim, final IdleStrategy idleStrategy, final int maxClaimAttempts, final ExclusivePublication publication, final ReplayQuery replayQuery, final int beginSeqNo, final int endSeqNo, final long sessionId) { super(connectionId, bufferClaim, idleStrategy, maxClaimAttempts, publication, replayQuery, beginSeqNo, endSeqNo, sessionId, 0); state = State.REPLAYING; }
Example #7
Source File: ConsensusPublisher.java From aeron with Apache License 2.0 | 6 votes |
boolean terminationPosition(final ExclusivePublication publication, final long logPosition) { final int length = MessageHeaderEncoder.ENCODED_LENGTH + TerminationPositionEncoder.BLOCK_LENGTH; int attempts = SEND_ATTEMPTS; do { final long result = publication.tryClaim(length, bufferClaim); if (result > 0) { terminationPositionEncoder .wrapAndApplyHeader(bufferClaim.buffer(), bufferClaim.offset(), messageHeaderEncoder) .logPosition(logPosition); bufferClaim.commit(); return true; } checkResult(result); } while (--attempts > 0); return false; }
Example #8
Source File: ConsensusPublisher.java From aeron with Apache License 2.0 | 6 votes |
boolean terminationAck(final ExclusivePublication publication, final long logPosition, final int memberId) { final int length = MessageHeaderEncoder.ENCODED_LENGTH + TerminationAckEncoder.BLOCK_LENGTH; int attempts = SEND_ATTEMPTS; do { final long result = publication.tryClaim(length, bufferClaim); if (result > 0) { terminationAckEncoder .wrapAndApplyHeader(bufferClaim.buffer(), bufferClaim.offset(), messageHeaderEncoder) .logPosition(logPosition) .memberId(memberId); bufferClaim.commit(); return true; } checkResult(result); } while (--attempts > 0); return false; }
Example #9
Source File: ReplaySessionTest.java From aeron with Apache License 2.0 | 6 votes |
private ReplaySession replaySession( final long position, final long length, final long correlationId, final ExclusivePublication replay, final ControlSession controlSession, final Counter recordingPositionCounter, final Checksum checksum) { return new ReplaySession( position, length, REPLAY_ID, CONNECT_TIMEOUT_MS, correlationId, controlSession, proxy, replayBuffer, mockCatalog, archiveDir, epochClock, replay, recordingSummary, recordingPositionCounter, checksum); }
Example #10
Source File: TestNode.java From aeron with Apache License 2.0 | 6 votes |
public void onTakeSnapshot(final ExclusivePublication snapshotPublication) { final ExpandableArrayBuffer buffer = new ExpandableArrayBuffer(SNAPSHOT_MSG_LENGTH); buffer.putInt(0, messageCount); for (int i = 0; i < SNAPSHOT_FRAGMENT_COUNT; i++) { idleStrategy.reset(); while (snapshotPublication.offer(buffer, 0, SNAPSHOT_MSG_LENGTH) <= 0) { idleStrategy.idle(); } } wasSnapshotTaken = true; }
Example #11
Source File: ReplaySessionTest.java From aeron with Apache License 2.0 | 6 votes |
private void mockPublication(final ExclusivePublication replay, final UnsafeBuffer termBuffer) { when(replay.offerBlock(any(MutableDirectBuffer.class), anyInt(), anyInt())).then( (invocation) -> { final MutableDirectBuffer buffer = invocation.getArgument(0); final int offset = invocation.getArgument(1); final int length = invocation.getArgument(2); termBuffer.putBytes(offerBlockOffset, buffer, offset, length); messageCounter++; offerBlockOffset += length; return (long)length; }); when(replay.appendPadding(anyInt())).then( (invocation) -> { final int claimedSize = invocation.getArgument(0); messageCounter++; return (long)claimedSize; }); }
Example #12
Source File: SnapshotTaker.java From aeron with Apache License 2.0 | 5 votes |
/** * Construct a {@link SnapshotTaker} which will encode the snapshot to a publication. * * @param publication into which the snapshot will be encoded. * @param idleStrategy to call when the publication is back pressured. * @param aeronAgentInvoker to call when idling so it stays active. */ public SnapshotTaker( final ExclusivePublication publication, final IdleStrategy idleStrategy, final AgentInvoker aeronAgentInvoker) { this.publication = publication; this.idleStrategy = idleStrategy; this.aeronAgentInvoker = aeronAgentInvoker; }
Example #13
Source File: ConsensusPublisher.java From aeron with Apache License 2.0 | 5 votes |
void canvassPosition( final ExclusivePublication publication, final long logLeadershipTermId, final long logPosition, final int followerMemberId) { final int length = MessageHeaderEncoder.ENCODED_LENGTH + CanvassPositionEncoder.BLOCK_LENGTH; int attempts = SEND_ATTEMPTS; do { final long result = publication.tryClaim(length, bufferClaim); if (result > 0) { canvassPositionEncoder .wrapAndApplyHeader(bufferClaim.buffer(), bufferClaim.offset(), messageHeaderEncoder) .logLeadershipTermId(logLeadershipTermId) .logPosition(logPosition) .followerMemberId(followerMemberId); bufferClaim.commit(); return; } checkResult(result); } while (--attempts > 0); }
Example #14
Source File: ConsensusPublisher.java From aeron with Apache License 2.0 | 5 votes |
boolean requestVote( final ExclusivePublication publication, final long logLeadershipTermId, final long logPosition, final long candidateTermId, final int candidateMemberId) { final int length = MessageHeaderEncoder.ENCODED_LENGTH + RequestVoteEncoder.BLOCK_LENGTH; int attempts = SEND_ATTEMPTS; do { final long result = publication.tryClaim(length, bufferClaim); if (result > 0) { requestVoteEncoder .wrapAndApplyHeader(bufferClaim.buffer(), bufferClaim.offset(), messageHeaderEncoder) .logLeadershipTermId(logLeadershipTermId) .logPosition(logPosition) .candidateTermId(candidateTermId) .candidateMemberId(candidateMemberId); bufferClaim.commit(); return true; } checkResult(result); } while (--attempts > 0); return false; }
Example #15
Source File: ConsensusPublisher.java From aeron with Apache License 2.0 | 5 votes |
boolean addPassiveMember( final ExclusivePublication publication, final long correlationId, final String memberEndpoints) { final int length = MessageHeaderEncoder.ENCODED_LENGTH + AddPassiveMemberEncoder.BLOCK_LENGTH + AddPassiveMemberEncoder.memberEndpointsHeaderLength() + memberEndpoints.length(); int attempts = SEND_ATTEMPTS; do { final long result = publication.tryClaim(length, bufferClaim); if (result > 0) { addPassiveMemberEncoder .wrapAndApplyHeader(bufferClaim.buffer(), bufferClaim.offset(), messageHeaderEncoder) .correlationId(correlationId) .memberEndpoints(memberEndpoints); bufferClaim.commit(); return true; } checkResult(result); } while (--attempts > 0); return false; }
Example #16
Source File: ConsensusPublisher.java From aeron with Apache License 2.0 | 5 votes |
void placeVote( final ExclusivePublication publication, final long candidateTermId, final long logLeadershipTermId, final long logPosition, final int candidateMemberId, final int followerMemberId, final boolean vote) { final int length = MessageHeaderEncoder.ENCODED_LENGTH + VoteEncoder.BLOCK_LENGTH; int attempts = SEND_ATTEMPTS; do { final long result = publication.tryClaim(length, bufferClaim); if (result > 0) { voteEncoder .wrapAndApplyHeader(bufferClaim.buffer(), bufferClaim.offset(), messageHeaderEncoder) .candidateTermId(candidateTermId) .logLeadershipTermId(logLeadershipTermId) .logPosition(logPosition) .candidateMemberId(candidateMemberId) .followerMemberId(followerMemberId) .vote(vote ? BooleanType.TRUE : BooleanType.FALSE); bufferClaim.commit(); return; } checkResult(result); } while (--attempts > 0); }
Example #17
Source File: ConsensusPublisher.java From aeron with Apache License 2.0 | 5 votes |
void newLeadershipTerm( final ExclusivePublication publication, final long logLeadershipTermId, final long logTruncatePosition, final long leadershipTermId, final long logPosition, final long timestamp, final int leaderMemberId, final int logSessionId, final boolean isStartup) { final int length = MessageHeaderEncoder.ENCODED_LENGTH + NewLeadershipTermEncoder.BLOCK_LENGTH; int attempts = SEND_ATTEMPTS; do { final long result = publication.tryClaim(length, bufferClaim); if (result > 0) { newLeadershipTermEncoder .wrapAndApplyHeader(bufferClaim.buffer(), bufferClaim.offset(), messageHeaderEncoder) .logLeadershipTermId(logLeadershipTermId) .logTruncatePosition(logTruncatePosition) .leadershipTermId(leadershipTermId) .logPosition(logPosition) .timestamp(timestamp) .leaderMemberId(leaderMemberId) .logSessionId(logSessionId) .isStartup(isStartup ? BooleanType.TRUE : BooleanType.FALSE); bufferClaim.commit(); return; } checkResult(result); } while (--attempts > 0); }
Example #18
Source File: ConsensusPublisher.java From aeron with Apache License 2.0 | 5 votes |
boolean appendPosition( final ExclusivePublication publication, final long leadershipTermId, final long logPosition, final int followerMemberId) { final int length = MessageHeaderEncoder.ENCODED_LENGTH + AppendPositionEncoder.BLOCK_LENGTH; int attempts = SEND_ATTEMPTS; do { final long result = publication.tryClaim(length, bufferClaim); if (result > 0) { appendPositionEncoder .wrapAndApplyHeader(bufferClaim.buffer(), bufferClaim.offset(), messageHeaderEncoder) .leadershipTermId(leadershipTermId) .logPosition(logPosition) .followerMemberId(followerMemberId); bufferClaim.commit(); return true; } checkResult(result); } while (--attempts > 0); return false; }
Example #19
Source File: ConsensusPublisher.java From aeron with Apache License 2.0 | 5 votes |
void commitPosition( final ExclusivePublication publication, final long leadershipTermId, final long logPosition, final int leaderMemberId) { final int length = MessageHeaderEncoder.ENCODED_LENGTH + CommitPositionEncoder.BLOCK_LENGTH; int attempts = SEND_ATTEMPTS; do { final long result = publication.tryClaim(length, bufferClaim); if (result > 0) { commitPositionEncoder .wrapAndApplyHeader(bufferClaim.buffer(), bufferClaim.offset(), messageHeaderEncoder) .leadershipTermId(leadershipTermId) .logPosition(logPosition) .leaderMemberId(leaderMemberId); bufferClaim.commit(); return; } checkResult(result); } while (--attempts > 0); }
Example #20
Source File: ConsensusPublisher.java From aeron with Apache License 2.0 | 5 votes |
boolean catchupPosition( final ExclusivePublication publication, final long leadershipTermId, final long logPosition, final int followerMemberId) { final int length = MessageHeaderEncoder.ENCODED_LENGTH + CatchupPositionEncoder.BLOCK_LENGTH; int attempts = SEND_ATTEMPTS; do { final long result = publication.tryClaim(length, bufferClaim); if (result > 0) { catchupPositionEncoder .wrapAndApplyHeader(bufferClaim.buffer(), bufferClaim.offset(), messageHeaderEncoder) .leadershipTermId(leadershipTermId) .logPosition(logPosition) .followerMemberId(followerMemberId); bufferClaim.commit(); return true; } checkResult(result); } while (--attempts > 0); return false; }
Example #21
Source File: SingleNodeCluster.java From aeron with Apache License 2.0 | 5 votes |
public void onTakeSnapshot(final ExclusivePublication snapshotPublication) { System.out.println("onTakeSnapshot messageCount=" + messageCount); buffer.putInt(0, messageCount); idleStrategy.reset(); while (snapshotPublication.offer(buffer, 0, 4) < 0) { idleStrategy.idle(); } }
Example #22
Source File: ConsensusPublisher.java From aeron with Apache License 2.0 | 5 votes |
boolean clusterMemberChange( final ExclusivePublication publication, final long correlationId, final int leaderMemberId, final String activeMembers, final String passiveMembers) { final int length = MessageHeaderEncoder.ENCODED_LENGTH + ClusterMembersChangeEncoder.BLOCK_LENGTH + ClusterMembersChangeEncoder.activeMembersHeaderLength() + activeMembers.length() + ClusterMembersChangeEncoder.passiveMembersHeaderLength() + passiveMembers.length(); int attempts = SEND_ATTEMPTS; do { final long result = publication.tryClaim(length, bufferClaim); if (result > 0) { clusterMembersChangeEncoder .wrapAndApplyHeader(bufferClaim.buffer(), bufferClaim.offset(), messageHeaderEncoder) .correlationId(correlationId) .leaderMemberId(leaderMemberId) .activeMembers(activeMembers) .passiveMembers(passiveMembers); bufferClaim.commit(); return true; } checkResult(result); } while (--attempts > 0); return false; }
Example #23
Source File: ConsensusPublisher.java From aeron with Apache License 2.0 | 5 votes |
boolean snapshotRecordingQuery( final ExclusivePublication publication, final long correlationId, final int requestMemberId) { final int length = MessageHeaderEncoder.ENCODED_LENGTH + SnapshotRecordingQueryEncoder.BLOCK_LENGTH; int attempts = SEND_ATTEMPTS; do { final long result = publication.tryClaim(length, bufferClaim); if (result > 0) { snapshotRecordingQueryEncoder .wrapAndApplyHeader(bufferClaim.buffer(), bufferClaim.offset(), messageHeaderEncoder) .correlationId(correlationId) .requestMemberId(requestMemberId); bufferClaim.commit(); return true; } checkResult(result); } while (--attempts > 0); return false; }
Example #24
Source File: ConsensusPublisher.java From aeron with Apache License 2.0 | 5 votes |
boolean backupQuery( final ExclusivePublication publication, final long correlationId, final int responseStreamId, final int version, final String responseChannel, final byte[] encodedCredentials) { final int length = MessageHeaderEncoder.ENCODED_LENGTH + BackupQueryEncoder.BLOCK_LENGTH + BackupQueryEncoder.responseChannelHeaderLength() + responseChannel.length() + BackupQueryEncoder.encodedCredentialsHeaderLength() + encodedCredentials.length; int attempts = SEND_ATTEMPTS; do { final long result = publication.tryClaim(length, bufferClaim); if (result > 0) { backupQueryEncoder .wrapAndApplyHeader(bufferClaim.buffer(), bufferClaim.offset(), messageHeaderEncoder) .correlationId(correlationId) .responseStreamId(responseStreamId) .version(version) .responseChannel(responseChannel) .putEncodedCredentials(encodedCredentials, 0, encodedCredentials.length); bufferClaim.commit(); return true; } checkResult(result); } while (--attempts > 0); return false; }
Example #25
Source File: BasicAuctionClusteredService.java From aeron with Apache License 2.0 | 5 votes |
public void onTakeSnapshot(final ExclusivePublication snapshotPublication) { snapshotBuffer.putLong(CUSTOMER_ID_OFFSET, auction.getCurrentWinningCustomerId()); // <1> snapshotBuffer.putLong(PRICE_OFFSET, auction.getBestPrice()); while (snapshotPublication.offer(snapshotBuffer, 0, SNAPSHOT_MESSAGE_LENGTH) < 0) // <2> { idleStrategy.idle(); } }
Example #26
Source File: GatewayPublication.java From artio with Apache License 2.0 | 5 votes |
public GatewayPublication( final ExclusivePublication dataPublication, final AtomicCounter fails, final IdleStrategy idleStrategy, final Clock clock, final int maxClaimAttempts) { super(maxClaimAttempts, idleStrategy, fails, dataPublication); this.clock = clock; this.maxPayloadLength = dataPublication.maxPayloadLength(); this.maxInitialBodyLength = maxPayloadLength - FRAMED_MESSAGE_SIZE; }
Example #27
Source File: FixEngine.java From artio with Apache License 2.0 | 5 votes |
private ExclusivePublication replayPublication() { final ExclusivePublication publication = aeron.addExclusivePublication( IPC_CHANNEL, configuration.outboundReplayStream()); StreamInformation.print("replayPublication", publication, configuration); return publication; }
Example #28
Source File: Streams.java From artio with Apache License 2.0 | 5 votes |
public GatewayPublication gatewayPublication( final IdleStrategy idleStrategy, final ExclusivePublication dataPublication) { return new GatewayPublication( dataPublication, failedPublications, idleStrategy, clock, maxClaimAttempts); }
Example #29
Source File: ClaimablePublication.java From artio with Apache License 2.0 | 5 votes |
ClaimablePublication( final int maxClaimAttempts, final IdleStrategy idleStrategy, final AtomicCounter fails, final ExclusivePublication dataPublication) { this.maxClaimAttempts = maxClaimAttempts; this.idleStrategy = idleStrategy; this.fails = fails; dataPublication(dataPublication); }
Example #30
Source File: ILink3SenderEndPoint.java From artio with Apache License 2.0 | 5 votes |
public ILink3SenderEndPoint( final long connectionId, final TcpChannel channel, final ErrorHandler errorHandler, final ExclusivePublication inboundPublication, final int libraryId) { this.connectionId = connectionId; this.channel = channel; this.errorHandler = errorHandler; this.inboundPublication = inboundPublication; this.libraryId = libraryId; }