/// <summary> /// Wrap the buffer at a given offset for updates. /// </summary> /// <param name="buffer"> to wrap </param> /// <param name="offset"> at which the message begins. </param> /// <returns> for fluent API </returns> public PublicationBuffersReadyFlyweight Wrap(IMutableDirectBuffer buffer, int offset) { this._buffer = buffer; this._offset = offset; return this; }
/// <summary> /// Wrap the buffer at a given offset for updates. /// </summary> /// <param name="buffer"> to wrap </param> /// <param name="offset"> at which the message begins. </param> /// <returns> for fluent API </returns> public ErrorResponseFlyweight Wrap(IMutableDirectBuffer buffer, int offset) { this._buffer = buffer; this._offset = offset; return this; }
/// <summary> /// Wrap the buffer at a given offset for updates. /// </summary> /// <param name="buffer"> to wrap </param> /// <param name="offset"> at which the message begins. </param> /// <returns> for fluent API </returns> public ImageMessageFlyweight Wrap(IMutableDirectBuffer buffer, int offset) { this.buffer = buffer; this.offset = offset; return this; }
public DetachSegmentsRequestEncoder Wrap(IMutableDirectBuffer buffer, int offset) { this._buffer = buffer; this._offset = offset; Limit(offset + BLOCK_LENGTH); return(this); }
public RecoveryPlanQueryEncoder Wrap(IMutableDirectBuffer buffer, int offset) { this._buffer = buffer; this._offset = offset; Limit(offset + BLOCK_LENGTH); return(this); }
public ChallengeEncoder Wrap(IMutableDirectBuffer buffer, int offset) { this._buffer = buffer; this._offset = offset; Limit(offset + BLOCK_LENGTH); return this; }
public NewLeaderEventEncoder Wrap(IMutableDirectBuffer buffer, int offset) { this._buffer = buffer; this._offset = offset; Limit(offset + BLOCK_LENGTH); return(this); }
public TerminationAckEncoder Wrap(IMutableDirectBuffer buffer, int offset) { this._buffer = buffer; this._offset = offset; Limit(offset + BLOCK_LENGTH); return(this); }
public RecordingStartedEncoder Wrap(IMutableDirectBuffer buffer, int offset) { this._buffer = buffer; this._offset = offset; Limit(offset + BLOCK_LENGTH); return(this); }
public SessionConnectRequestEncoder Wrap(IMutableDirectBuffer buffer, int offset) { this._buffer = buffer; this._offset = offset; Limit(offset + BLOCK_LENGTH); return(this); }
public ScheduleTimerEncoder Wrap(IMutableDirectBuffer buffer, int offset) { this._buffer = buffer; this._offset = offset; Limit(offset + BLOCK_LENGTH); return(this); }
public FindLastMatchingRecordingRequestEncoder Wrap(IMutableDirectBuffer buffer, int offset) { this._buffer = buffer; this._offset = offset; Limit(offset + BLOCK_LENGTH); return(this); }
public ControlResponseEncoder Wrap(IMutableDirectBuffer buffer, int offset) { this._buffer = buffer; this._offset = offset; Limit(offset + BLOCK_LENGTH); return(this); }
public BoundedReplayRequestEncoder Wrap(IMutableDirectBuffer buffer, int offset) { this._buffer = buffer; this._offset = offset; Limit(offset + BLOCK_LENGTH); return(this); }
public StopRecordingSubscriptionRequestEncoder Wrap(IMutableDirectBuffer buffer, int offset) { this._buffer = buffer; this._offset = offset; Limit(offset + BLOCK_LENGTH); return(this); }
private void WhenReceiveBroadcastOnMessage(int msgTypeId, IMutableDirectBuffer buffer, Func <IMutableDirectBuffer, int> filler) { A.CallTo(() => MockToClientReceiver.Receive(A <MessageHandler> ._)).Invokes(() => { var length = filler(buffer); Conductor.DriverListenerAdapter().OnMessage(msgTypeId, buffer, 0, length); }); }
public SnapshotRecordingQueryEncoder Wrap(IMutableDirectBuffer buffer, int offset) { this._buffer = buffer; this._offset = offset; Limit(offset + BLOCK_LENGTH); return(this); }
public EgressMessageHeaderEncoder Wrap(IMutableDirectBuffer buffer, int offset) { this._buffer = buffer; this._offset = offset; Limit(offset + BLOCK_LENGTH); return(this); }
public AddPassiveMemberEncoder Wrap(IMutableDirectBuffer buffer, int offset) { this._buffer = buffer; this._offset = offset; Limit(offset + BLOCK_LENGTH); return(this); }
public CommitPositionEncoder Wrap(IMutableDirectBuffer buffer, int offset) { this._buffer = buffer; this._offset = offset; Limit(offset + BLOCK_LENGTH); return(this); }
public ClusterMembersChangeEncoder Wrap(IMutableDirectBuffer buffer, int offset) { this._buffer = buffer; this._offset = offset; Limit(offset + BLOCK_LENGTH); return(this); }
public ListRecordingsForUriRequestEncoder Wrap(IMutableDirectBuffer buffer, int offset) { this._buffer = buffer; this._offset = offset; Limit(offset + BLOCK_LENGTH); return(this); }
/// <summary> /// Allocate a counter to represent the heartbeat of a clustered service. /// </summary> /// <param name="aeron"> to allocate the counter. </param> /// <param name="tempBuffer"> to use for building the key and label without allocation. </param> /// <param name="serviceId"> of the service heartbeat. </param> /// <returns> the <seealso cref="Counter"/> for the commit position. </returns> public static Counter Allocate(Aeron.Aeron aeron, IMutableDirectBuffer tempBuffer, int serviceId) { int labelOffset = 0; labelOffset += tempBuffer.PutStringWithoutLengthAscii(KEY_LENGTH + labelOffset, NAME); labelOffset += tempBuffer.PutIntAscii(KEY_LENGTH + labelOffset, serviceId); return(aeron.AddCounter(SERVICE_HEARTBEAT_TYPE_ID, tempBuffer, 0, KEY_LENGTH, tempBuffer, KEY_LENGTH, labelOffset)); }
/// <summary> /// Allocate a counter for tracking the last heartbeat of an entity. /// </summary> /// <param name="tempBuffer"> to be used for labels and key. </param> /// <param name="name"> of the counter for the label. </param> /// <param name="typeId"> of the counter for classification. </param> /// <param name="countersManager"> from which to allocated the underlying storage. </param> /// <param name="registrationId"> to be associated with the counter. </param> /// <returns> a new <seealso cref="AtomicCounter"/> for tracking the last heartbeat. </returns> public static AtomicCounter Allocate( IMutableDirectBuffer tempBuffer, string name, int typeId, CountersManager countersManager, long registrationId) { return(new AtomicCounter(countersManager.ValuesBuffer, AllocateCounterId(tempBuffer, name, typeId, countersManager, registrationId), countersManager)); }
/// <summary> /// Append pre-formatted block of message fragments into the term buffer. /// <para> /// <em>WARNING: This is internal API used by {@code ExclusivePublication#offerBlock} method.</em> /// </para> /// </summary> /// <param name="termId"> for the current term. </param> /// <param name="termOffset"> in the term at which to append. </param> /// <param name="buffer"> which contains block of messages. </param> /// <param name="offset"> within the buffer at which the block begins. </param> /// <param name="length"> of the block in bytes (always aligned). </param> /// <returns> the resulting offset of the term after success otherwise <seealso cref="FAILED"/>. </returns> public int AppendBlock(int termId, int termOffset, IMutableDirectBuffer buffer, int offset, int length) { int resultingOffset = termOffset + length; int lengthOfFirstFrame = buffer.GetInt(offset, ByteOrder.LittleEndian); buffer.PutInt(offset, 0, ByteOrder.LittleEndian); _termBuffer.PutBytes(termOffset, buffer, offset, length); FrameDescriptor.FrameLengthOrdered(_termBuffer, termOffset, lengthOfFirstFrame); PutRawTailOrdered(termId, resultingOffset); return(resultingOffset); }
/// <summary> /// Allocate a counter to represent the heartbeat of a clustered service. /// </summary> /// <param name="aeron"> to allocate the counter. </param> /// <param name="tempBuffer"> to use for building the key and label without allocation. </param> /// <param name="serviceId"> of the service heartbeat. </param> /// <returns> the <seealso cref="Counter"/> for the commit position. </returns> public static Counter Allocate(Aeron.Aeron aeron, IMutableDirectBuffer tempBuffer, int serviceId) { tempBuffer.PutInt(SERVICE_ID_OFFSET, serviceId); int labelOffset = BitUtil.Align(KEY_LENGTH, BitUtil.SIZE_OF_INT); int labelLength = 0; labelLength += tempBuffer.PutStringWithoutLengthAscii(labelOffset + labelLength, NAME); labelLength += tempBuffer.PutIntAscii(labelOffset + labelLength, serviceId); return(aeron.AddCounter(SERVICE_HEARTBEAT_TYPE_ID, tempBuffer, 0, KEY_LENGTH, tempBuffer, labelOffset, labelLength)); }
public BackupResponseEncoder WrapAndApplyHeader( IMutableDirectBuffer buffer, int offset, MessageHeaderEncoder headerEncoder) { headerEncoder .Wrap(buffer, offset) .BlockLength(BLOCK_LENGTH) .TemplateId(TEMPLATE_ID) .SchemaId(SCHEMA_ID) .Version(SCHEMA_VERSION); return(Wrap(buffer, offset + MessageHeaderEncoder.ENCODED_LENGTH)); }
/// <summary> /// Wrap a <seealso cref="BroadcastReceiver"/> to simplify the API for receiving messages. /// </summary> /// <param name="receiver"> to be wrapped. </param> public CopyBroadcastReceiver(BroadcastReceiver receiver) { _receiver = receiver; _scratchBuffer = new UnsafeBuffer(new byte[ScratchBufferSize]); while (receiver.ReceiveNext()) { // If we're reconnecting to a broadcast buffer then we need to // scan ourselves up to date, otherwise we risk "falling behind" // the buffer due to the time taken to catchup. } }
public int GetEncodedPrincipal(IMutableDirectBuffer dst, int dstOffset, int length) { int headerLength = 4; int limit = _parentMessage.Limit(); int dataLength = (int)unchecked ((uint)_buffer.GetInt(limit, ByteOrder.LittleEndian)); int bytesCopied = Math.Min(length, dataLength); _parentMessage.Limit(limit + headerLength + dataLength); _buffer.GetBytes(limit + headerLength, dst, dstOffset, bytesCopied); return(bytesCopied); }
public ServiceTerminationPositionEncoder WrapAndApplyHeader( IMutableDirectBuffer buffer, int offset, MessageHeaderEncoder headerEncoder) { headerEncoder .Wrap(buffer, offset) .BlockLength(BLOCK_LENGTH) .TemplateId(TEMPLATE_ID) .SchemaId(SCHEMA_ID) .Version(SCHEMA_VERSION); return Wrap(buffer, offset + MessageHeaderEncoder.ENCODED_LENGTH); }
/// <summary> /// Allocate a counter to represent the commit position on stream for the current leadership term. /// </summary> /// <param name="aeron"> to allocate the counter. </param> /// <param name="tempBuffer"> to use for building the key and label without allocation. </param> /// <param name="recordingId"> for the current term. </param> /// <param name="logPosition"> of the log at the beginning of the leadership term. </param> /// <param name="leadershipTermId"> of the log at the beginning of the leadership term. </param> /// <param name="sessionId"> of the active log for the current leadership term. </param> /// <returns> the <seealso cref="Counter"/> for the consensus position. </returns> public static Counter Allocate(Aeron.Aeron aeron, IMutableDirectBuffer tempBuffer, long recordingId, long logPosition, long leadershipTermId, int sessionId) { tempBuffer.PutLong(RECORDING_ID_OFFSET, recordingId); tempBuffer.PutLong(LOG_POSITION_OFFSET, logPosition); tempBuffer.PutLong(LEADERSHIP_TERM_ID_OFFSET, leadershipTermId); tempBuffer.PutInt(SESSION_ID_OFFSET, sessionId); int labelOffset = 0; labelOffset += tempBuffer.PutStringWithoutLengthAscii(KEY_LENGTH + labelOffset, NAME); labelOffset += tempBuffer.PutLongAscii(KEY_LENGTH + labelOffset, leadershipTermId); labelOffset += tempBuffer.PutStringWithoutLengthAscii(KEY_LENGTH + labelOffset, " logSessionId="); labelOffset += tempBuffer.PutIntAscii(KEY_LENGTH + labelOffset, sessionId); return(aeron.AddCounter(COMMIT_POSITION_TYPE_ID, tempBuffer, 0, KEY_LENGTH, tempBuffer, KEY_LENGTH, labelOffset)); }
public void Wrap( BackupResponseEncoder parentMessage, IMutableDirectBuffer buffer, int count) { if (count < 0 || count > 65534) { throw new ArgumentException("count outside allowed range: count=" + count); } this._parentMessage = parentMessage; this._buffer = buffer; _dimensions.Wrap(buffer, parentMessage.Limit()); _dimensions.BlockLength((ushort)44); _dimensions.NumInGroup((ushort)count); _index = -1; this._count = count; parentMessage.Limit(parentMessage.Limit() + HEADER_SIZE); }
/// <summary> /// Allocate an indicator for tracking the status of a channel endpoint. /// </summary> /// <param name="tempBuffer"> to be used for labels and metadata. </param> /// <param name="name"> of the counter for the label. </param> /// <param name="typeId"> of the counter for classification. </param> /// <param name="countersManager"> from which to allocated the underlying storage. </param> /// <param name="channel"> for the stream of messages. </param> /// <returns> a new <seealso cref="AtomicCounter"/> for tracking the status. </returns> public static AtomicCounter Allocate(IMutableDirectBuffer tempBuffer, string name, int typeId, CountersManager countersManager, string channel) { int keyLength = tempBuffer.PutStringWithoutLengthAscii(CHANNEL_OFFSET + BitUtil.SIZE_OF_INT, channel, 0, MAX_CHANNEL_LENGTH); tempBuffer.PutInt(CHANNEL_OFFSET, keyLength); int labelLength = 0; labelLength += tempBuffer.PutStringWithoutLengthAscii(keyLength + labelLength, name); labelLength += tempBuffer.PutStringWithoutLengthAscii(keyLength + labelLength, ": "); labelLength += tempBuffer.PutStringWithoutLengthAscii(keyLength + labelLength, channel, 0, CountersReader.MAX_LABEL_LENGTH - labelLength); return(countersManager.NewCounter(typeId, tempBuffer, 0, keyLength, tempBuffer, keyLength, labelLength)); }
private static void RoundTripMessages(IMutableDirectBuffer buffer, FragmentHandler fragmentHandler, Publication publication, Subscription subscription, int count) { for (var i = 0; i < count; i++) { do { buffer.PutLong(0, Stopwatch.GetTimestamp()); } while (publication.Offer(buffer, 0, MessageLength) < 0L); PollingIdleStrategy.Reset(); while (subscription.Poll(fragmentHandler, FragmentCountLimit) <= 0) { PollingIdleStrategy.Idle(); } } }
public void GetBytes(int index, IMutableDirectBuffer dstBuffer, int dstIndex, int length) { dstBuffer.PutBytes(dstIndex, this, index, length); }
public void OnMessage(int msgTypeId, IMutableDirectBuffer buffer, int index, int length) { switch (msgTypeId) { case ControlProtocolEvents.ON_PUBLICATION_READY: { _publicationReady.Wrap(buffer, index); long correlationId = _publicationReady.CorrelationId(); if (correlationId == _activeCorrelationId) { _listener.OnNewPublication(_expectedChannel, _publicationReady.StreamId(), _publicationReady.SessionId(), _publicationReady.PublicationLimitCounterId(), _publicationReady.LogFileName(), correlationId); _lastReceivedCorrelationId = correlationId; } break; } case ControlProtocolEvents.ON_AVAILABLE_IMAGE: { _imageReady.Wrap(buffer, index); _subscriberPositionMap.Clear(); for (int i = 0, max = _imageReady.SubscriberPositionCount(); i < max; i++) { long registrationId = _imageReady.PositionIndicatorRegistrationId(i); int positionId = _imageReady.SubscriberPositionId(i); _subscriberPositionMap.Add(registrationId, positionId); } _listener.OnAvailableImage( _imageReady.StreamId(), _imageReady.SessionId(), _subscriberPositionMap, _imageReady.LogFileName(), _imageReady.SourceIdentity(), _imageReady.CorrelationId()); break; } case ControlProtocolEvents.ON_OPERATION_SUCCESS: { _correlatedMessage.Wrap(buffer, index); long correlationId = _correlatedMessage.CorrelationId(); if (correlationId == _activeCorrelationId) { _lastReceivedCorrelationId = correlationId; } break; } case ControlProtocolEvents.ON_UNAVAILABLE_IMAGE: { _imageMessage.Wrap(buffer, index); _listener.OnUnavailableImage(_imageMessage.StreamId(), _imageMessage.CorrelationId()); break; } case ControlProtocolEvents.ON_ERROR: { _errorResponse.Wrap(buffer, index); long correlationId = _errorResponse.OffendingCommandCorrelationId(); if (correlationId == _activeCorrelationId) { _listener.OnError(_errorResponse.ErrorCode(), _errorResponse.ErrorMessage(), correlationId); _lastReceivedCorrelationId = correlationId; } break; } } }