Ejemplo n.º 1
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());
                    }
                }
            }
        }
Ejemplo n.º 2
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();
            }
        }
Ejemplo n.º 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();
            }
        }