internal ClusteredServiceAgent(ClusteredServiceContainer.Context ctx)
        {
            this.ctx = ctx;

            archiveCtx   = ctx.ArchiveContext();
            aeron        = ctx.Aeron();
            service      = ctx.ClusteredService();
            idleStrategy = ctx.IdleStrategy();
            serviceId    = ctx.ServiceId();
            epochClock   = ctx.EpochClock();
            markFile     = ctx.MarkFile();


            var channel = ctx.ServiceControlChannel();

            _consensusModuleProxy = new ConsensusModuleProxy(aeron.AddPublication(channel, ctx.ConsensusModuleStreamId()));
            _serviceAdapter       = new ServiceAdapter(aeron.AddSubscription(channel, ctx.ServiceStreamId()), this);

            UnsafeBuffer headerBuffer = new UnsafeBuffer(new byte[SESSION_HEADER_LENGTH]);

            _egressMessageHeaderEncoder.WrapAndApplyHeader(headerBuffer, 0, new MessageHeaderEncoder());

            _vectors[0] = new DirectBufferVector(headerBuffer, 0, SESSION_HEADER_LENGTH);
            _vectors[1] = _messageVector;
        }
        internal ClusteredServiceAgent(ClusteredServiceContainer.Context ctx)
        {
            this.ctx = ctx;

            headerVector = new DirectBufferVector(headerBuffer, 0, headerBuffer.Capacity);

            abortHandler      = Abort;
            archiveCtx        = ctx.ArchiveContext();
            aeron             = ctx.Aeron();
            aeronAgentInvoker = ctx.Aeron().ConductorAgentInvoker;
            service           = ctx.ClusteredService();
            idleStrategy      = ctx.IdleStrategy();
            serviceId         = ctx.ServiceId();
            epochClock        = ctx.EpochClock();
            markFile          = ctx.MarkFile();


            var channel = ctx.ServiceControlChannel();

            _consensusModuleProxy =
                new ConsensusModuleProxy(aeron.AddPublication(channel, ctx.ConsensusModuleStreamId()));
            _serviceAdapter = new ServiceAdapter(aeron.AddSubscription(channel, ctx.ServiceStreamId()), this);
            _sessionMessageHeaderEncoder.WrapAndApplyHeader(headerBuffer, 0, new MessageHeaderEncoder());
            aeron.AddCloseHandler(abortHandler);
        }
Example #3
0
        /// <summary>
        /// Construct a new session header wrapper.
        /// </summary>
        /// <param name="clusterSessionId"> that has been allocated by the cluster. </param>
        public SessionDecorator(long clusterSessionId)
        {
            UnsafeBuffer headerBuffer = new UnsafeBuffer(new byte[SESSION_HEADER_LENGTH]);

            sessionHeaderEncoder.WrapAndApplyHeader(headerBuffer, 0, new MessageHeaderEncoder()).ClusterSessionId(clusterSessionId);

            vectors[0] = new DirectBufferVector(headerBuffer, 0, SESSION_HEADER_LENGTH);
            vectors[1] = messageBuffer;
        }
Example #4
0
        /// <summary>
        /// Construct a new session header wrapper.
        /// </summary>
        /// <param name="clusterSessionId"> that has been allocated by the cluster. </param>
        /// <param name="leadershipTermId"> of the current leader.</param>
        public IngressSessionDecorator(long clusterSessionId, long leadershipTermId)
        {
            UnsafeBuffer headerBuffer = new UnsafeBuffer(new byte[INGRESS_MESSAGE_HEADER_LENGTH]);

            ingressMessageHeaderEncoder
            .WrapAndApplyHeader(headerBuffer, 0, new MessageHeaderEncoder())
            .LeadershipTermId(leadershipTermId)
            .ClusterSessionId(clusterSessionId)
            .Timestamp(Aeron.Aeron.NULL_VALUE);

            vectors[0] = new DirectBufferVector(headerBuffer, 0, INGRESS_MESSAGE_HEADER_LENGTH);
            vectors[1] = messageVector;
        }
Example #5
0
        /// <summary>
        /// Construct a new session header wrapper.
        /// </summary>
        /// <param name="clusterSessionId"> that has been allocated by the cluster. </param>
        /// <param name="lastCorrelationId"> the last correlation id that was sent to the cluster with this session.</param>
        public SessionDecorator(long clusterSessionId, long lastCorrelationId = Aeron.Aeron.NULL_VALUE)
        {
            UnsafeBuffer headerBuffer = new UnsafeBuffer(new byte[SESSION_HEADER_LENGTH]);

            sessionHeaderEncoder
            .WrapAndApplyHeader(headerBuffer, 0, new MessageHeaderEncoder())
            .ClusterSessionId(clusterSessionId)
            .Timestamp(Aeron.Aeron.NULL_VALUE);

            vectors[0] = new DirectBufferVector(headerBuffer, 0, SESSION_HEADER_LENGTH);
            vectors[1] = messageBuffer;

            this.lastCorrelationId = lastCorrelationId;
        }
Example #6
0
        internal ClientSession(long sessionId, int responseStreamId, string responseChannel, byte[] encodedPrincipal, ICluster cluster)
        {
            _id = sessionId;
            _responseStreamId = responseStreamId;
            _responseChannel  = responseChannel;
            _encodedPrincipal = encodedPrincipal;
            _cluster          = cluster;

            UnsafeBuffer headerBuffer = new UnsafeBuffer(new byte[SESSION_HEADER_LENGTH]);

            _sessionHeaderEncoder.WrapAndApplyHeader(headerBuffer, 0, new MessageHeaderEncoder()).ClusterSessionId(sessionId);

            _vectors[0] = new DirectBufferVector(headerBuffer, 0, SESSION_HEADER_LENGTH);
            _vectors[1] = _messageBuffer;
        }
        /// <summary>
        /// Construct a new session header wrapper.
        /// </summary>
        /// <param name="lastCorrelationId"> the last correlation id that was sent to the cluster with this session.</param>
        /// <param name="clusterSessionId"> that has been allocated by the cluster. </param>
        /// <param name="leadershipTermId"> of the current leader.</param>
        public IngressSessionDecorator(long lastCorrelationId, long clusterSessionId, long leadershipTermId)
        {
            UnsafeBuffer headerBuffer = new UnsafeBuffer(new byte[INGRESS_MESSAGE_HEADER_LENGTH]);

            ingressMessageHeaderEncoder
            .WrapAndApplyHeader(headerBuffer, 0, new MessageHeaderEncoder())
            .CorrelationId(lastCorrelationId)
            .ClusterSessionId(clusterSessionId)
            .LeadershipTermId(leadershipTermId);

            vectors[0] = new DirectBufferVector(headerBuffer, 0, INGRESS_MESSAGE_HEADER_LENGTH);
            vectors[1] = messageVector;

            this.lastCorrelationId = lastCorrelationId;
        }
Example #8
0
        private AeronCluster(Context ctx)
        {
            _ctx = ctx;


            Subscription subscription = null;

            try
            {
                ctx.Conclude();

                _aeron        = ctx.Aeron();
                _idleStrategy = ctx.IdleStrategy();
                _nanoClock    = _aeron.Ctx().NanoClock();
                _isUnicast    = ctx.ClusterMemberEndpoints() != null;
                UpdateMemberEndpoints(ctx.ClusterMemberEndpoints());

                subscription  = _aeron.AddSubscription(ctx.EgressChannel(), ctx.EgressStreamId());
                _subscription = subscription;

                _publication      = ConnectToCluster();
                _clusterSessionId = OpenSession();

                UnsafeBuffer headerBuffer = new UnsafeBuffer(new byte[SessionDecorator.SESSION_HEADER_LENGTH]);
                _sessionHeaderEncoder
                .WrapAndApplyHeader(headerBuffer, 0, _messageHeaderEncoder)
                .ClusterSessionId(_clusterSessionId)
                .Timestamp(Aeron.Aeron.NULL_VALUE);

                _vectors[0] = new DirectBufferVector(headerBuffer, 0, SessionDecorator.SESSION_HEADER_LENGTH);
                _vectors[1] = _messageBuffer;

                _poller            = new Poller(ctx.SessionMessageListener(), _clusterSessionId, this);
                _fragmentAssembler = new FragmentAssembler(_poller);
            }
            catch (Exception)
            {
                if (!ctx.OwnsAeronClient())
                {
                    CloseHelper.QuietDispose(_publication);
                    CloseHelper.QuietDispose(subscription);
                }

                CloseHelper.QuietDispose(ctx);
                throw;
            }
        }