コード例 #1
0
ファイル: ClientSession.cs プロジェクト: megakid/Aeron.NET
        /// <summary>
        /// Non-blocking publish of a partial buffer containing a message to a cluster.
        /// </summary>
        /// <param name="correlationId"> to be used to identify the message to the cluster. </param>
        /// <param name="buffer">        containing message. </param>
        /// <param name="offset">        offset in the buffer at which the encoded message begins. </param>
        /// <param name="length">        in bytes of the encoded message. </param>
        /// <returns> the same as <seealso cref="Publication#offer(DirectBuffer, int, int)"/> when in <seealso cref="Cluster.Role#LEADER"/>
        /// otherwise <see cref="MOCKED_OFFER"/>. </returns>
        public long Offer(
            long correlationId,
            IDirectBuffer buffer,
            int offset,
            int length)
        {
            if (_cluster.Role() != ClusterRole.Leader)
            {
                return(MOCKED_OFFER);
            }

            if (null == _responsePublication)
            {
                throw new ClusterException("session not connected id=" + _id);
            }

            _sessionHeaderEncoder
            .CorrelationId(correlationId)
            .Timestamp(_cluster.TimeMs());

            _messageBuffer.Reset(buffer, offset, length);

            return(_responsePublication.Offer(_vectors));
        }