Пример #1
0
        /// <summary>
        /// Query cluster member for recording log information.
        /// </summary>
        /// <returns> result of query. </returns>
        public byte[] QueryForRecordingLog()
        {
            _lock.Lock();
            try
            {
                long         deadlineNs    = _nanoClock.NanoTime() + _ctx.MessageTimeoutNs();
                long         correlationId = SendAdminQuery(AdminQueryType.RECORDING_LOG, deadlineNs);
                EgressPoller poller        = new EgressPoller(_subscription, FRAGMENT_LIMIT);

                while (true)
                {
                    PollNextResponse(deadlineNs, correlationId, poller);

                    if (poller.CorrelationId() == correlationId)
                    {
                        if (poller.TemplateId() == AdminResponseDecoder.TEMPLATE_ID)
                        {
                            return(poller.AdminResponseData());
                        }
                        else if (poller.EventCode() == EventCode.ERROR)
                        {
                            throw new InvalidOperationException(poller.Detail());
                        }
                    }
                }
            }
            finally
            {
                _lock.Unlock();
            }
        }
Пример #2
0
        private long OpenSession()
        {
            long         deadlineNs    = _nanoClock.NanoTime() + _ctx.MessageTimeoutNs();
            long         correlationId = SendConnectRequest(_ctx.CredentialsSupplier().EncodedCredentials(), deadlineNs);
            EgressPoller poller        = new EgressPoller(_subscription, CONNECT_FRAGMENT_LIMIT);

            while (true)
            {
                PollNextResponse(deadlineNs, correlationId, poller);

                if (poller.CorrelationId() == correlationId)
                {
                    if (poller.IsChallenged())
                    {
                        byte[] encodedCredentials = _ctx.CredentialsSupplier().OnChallenge(poller.EncodedChallenge());
                        correlationId =
                            SendChallengeResponse(poller.ClusterSessionId(), encodedCredentials, deadlineNs);
                        continue;
                    }

                    switch (poller.EventCode())
                    {
                    case EventCode.OK:
                        _leaderMemberId = poller.LeaderMemberId();
                        return(poller.ClusterSessionId());

                    case EventCode.ERROR:
                        throw new AuthenticationException(poller.Detail());

                    case EventCode.AUTHENTICATION_REJECTED:
                        throw new AuthenticationException(poller.Detail());
                    }
                }
            }
        }
Пример #3
0
        /// <summary>
        /// Query cluster member for endpoint information.
        /// <para>
        /// <code>
        /// id=num,memberStatus=member-facing:port,log=log:port,archive=archive:port
        /// </code>
        ///
        /// </para>
        /// </summary>
        /// <returns> result of query. </returns>
        public string QueryForEndpoints()
        {
            _lock.Lock();
            try
            {
                long         deadlineNs    = _nanoClock.NanoTime() + _ctx.MessageTimeoutNs();
                long         correlationId = SendAdminQuery(AdminQueryType.ENDPOINTS, deadlineNs);
                EgressPoller poller        = new EgressPoller(_subscription, FRAGMENT_LIMIT);

                while (true)
                {
                    PollNextResponse(deadlineNs, correlationId, poller);

                    if (poller.CorrelationId() == correlationId)
                    {
                        if (poller.TemplateId() == AdminResponseDecoder.TEMPLATE_ID)
                        {
                            return(Encoding.ASCII.GetString(poller.AdminResponseData())); // TODO check default charset for Java
                        }
                        else if (poller.EventCode() == EventCode.ERROR)
                        {
                            throw new InvalidOperationException(poller.Detail());
                        }
                    }
                }
            }
            finally
            {
                _lock.Unlock();
            }
        }
Пример #4
0
        private void PollNextResponse(long deadlineNs, long correlationId, EgressPoller poller)
        {
            _idleStrategy.Reset();

            while (poller.Poll() <= 0 && !poller.IsPollComplete())
            {
                if (_nanoClock.NanoTime() > deadlineNs)
                {
                    throw new TimeoutException("awaiting response for correlationId=" + correlationId);
                }

                _idleStrategy.Idle();
            }
        }