public override void ChannelActive(IChannelHandlerContext context)
        {
            this.capturedContext = context;

            this.publishProcessors = new Dictionary <IMessagingServiceClient, MessageAsyncProcessor <PublishPacket> >(1);

            bool abortOnOutOfOrderAck = this.settings.AbortOnOutOfOrderPubAck;

            this.publishPubAckProcessor = new RequestAckPairProcessor <AckPendingMessageState, PublishPacket>(this.AcknowledgePublishAsync, abortOnOutOfOrderAck, this);
            this.publishPubAckProcessor.Closed.OnFault(ShutdownOnPubAckFaultAction, this);
            this.publishPubRecProcessor = new RequestAckPairProcessor <AckPendingMessageState, PublishPacket>(this.AcknowledgePublishReceiveAsync, abortOnOutOfOrderAck, this);
            this.publishPubRecProcessor.Closed.OnFault(ShutdownOnPubRecFaultAction, this);
            this.pubRelPubCompProcessor = new RequestAckPairProcessor <CompletionPendingMessageState, PubRelPacket>(this.AcknowledgePublishCompleteAsync, abortOnOutOfOrderAck, this);
            this.pubRelPubCompProcessor.Closed.OnFault(ShutdownOnPubCompFaultAction, this);

            this.stateFlags = StateFlags.WaitingForConnect;
            TimeSpan?timeout = this.settings.ConnectArrivalTimeout;

            if (timeout.HasValue)
            {
                context.Executor.ScheduleAsync(CheckConnectTimeoutCallback, context, timeout.Value);
            }
            base.ChannelActive(context);

            context.Read();
        }
Ejemplo n.º 2
0
        public override void ChannelActive(IChannelHandlerContext context)
        {
            this.capturedContext = context;

            this.publishProcessors = new Dictionary <IMessagingServiceClient, MessageAsyncProcessor <PublishPacket> >(1);

            TimeSpan?ackTimeout = this.settings.DeviceReceiveAckCanTimeout ? this.settings.DeviceReceiveAckTimeout : (TimeSpan?)null;

            this.publishPubAckProcessor = new RequestAckPairProcessor <AckPendingMessageState, PublishPacket>(this.AcknowledgePublishAsync, this.RetransmitNextPublish, ackTimeout);
            this.publishPubAckProcessor.Completion.OnFault(ShutdownOnPubAckFaultAction);
            this.publishPubRecProcessor = new RequestAckPairProcessor <AckPendingMessageState, PublishPacket>(this.AcknowledgePublishReceiveAsync, this.RetransmitNextPublish, ackTimeout);
            this.publishPubRecProcessor.Completion.OnFault(ShutdownOnPubRecFaultAction);
            this.pubRelPubCompProcessor = new RequestAckPairProcessor <CompletionPendingMessageState, PubRelPacket>(this.AcknowledgePublishCompleteAsync, this.RetransmitNextPublishRelease, ackTimeout);
            this.pubRelPubCompProcessor.Completion.OnFault(ShutdownOnPubCompFaultAction);

            this.stateFlags = StateFlags.WaitingForConnect;
            TimeSpan?timeout = this.settings.ConnectArrivalTimeout;

            if (timeout.HasValue)
            {
                context.Executor.ScheduleAsync(CheckConnectTimeoutCallback, context, timeout.Value);
            }
            base.ChannelActive(context);

            context.Read();
        }
Ejemplo n.º 3
0
        public MqttIotHubAdapter(
            Settings settings,
            ISessionStatePersistenceProvider sessionStateManager,
            IDeviceIdentityProvider authProvider,
            IQos2StatePersistenceProvider qos2StateProvider,
            IMessagingFactory messagingFactory,
            IMessageRouter messageRouter)
        {
            Contract.Requires(settings != null);
            Contract.Requires(sessionStateManager != null);
            Contract.Requires(authProvider != null);
            Contract.Requires(messageRouter != null);

            if (qos2StateProvider != null)
            {
                this.maxSupportedQosToClient = QualityOfService.ExactlyOnce;
                this.qos2StateProvider       = qos2StateProvider;
            }
            else
            {
                this.maxSupportedQosToClient = QualityOfService.AtLeastOnce;
            }

            this.settings            = settings;
            this.sessionStateManager = sessionStateManager;
            this.authProvider        = authProvider;
            this.messagingFactory    = messagingFactory;
            this.messageRouter       = messageRouter;

            this.publishProcessor = new MessageAsyncProcessor <PublishPacket>(this.PublishToServerAsync);
            this.publishProcessor.Completion.OnFault(ShutdownOnPublishToServerFaultAction);

            TimeSpan?ackTimeout = this.settings.DeviceReceiveAckCanTimeout ? this.settings.DeviceReceiveAckTimeout : (TimeSpan?)null;

            this.publishPubAckProcessor = new RequestAckPairProcessor <AckPendingMessageState, PublishPacket>(this.AcknowledgePublishAsync, this.RetransmitNextPublish, ackTimeout);
            this.publishPubAckProcessor.Completion.OnFault(ShutdownOnPubAckFaultAction);
            this.publishPubRecProcessor = new RequestAckPairProcessor <AckPendingMessageState, PublishPacket>(this.AcknowledgePublishReceiveAsync, this.RetransmitNextPublish, ackTimeout);
            this.publishPubRecProcessor.Completion.OnFault(ShutdownOnPubRecFaultAction);
            this.pubRelPubCompProcessor = new RequestAckPairProcessor <CompletionPendingMessageState, PubRelPacket>(this.AcknowledgePublishCompleteAsync, this.RetransmitNextPublishRelease, ackTimeout);
            this.pubRelPubCompProcessor.Completion.OnFault(ShutdownOnPubCompFaultAction);
        }