< Summary

Class:Microsoft.Azure.ServiceBus.SessionPumpHost
Assembly:Microsoft.Azure.ServiceBus
File(s):C:\Git\azure-sdk-for-net\sdk\servicebus\Microsoft.Azure.ServiceBus\src\SessionPumpHost.cs
Covered lines:0
Uncovered lines:40
Coverable lines:40
Total lines:86
Line coverage:0% (0 of 40)
Covered branches:0
Total branches:10
Branch coverage:0% (0 of 10)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
.ctor(...)-0%100%
get_ReceiveMode()-0%100%
get_SessionClient()-0%100%
get_ClientId()-0%100%
Close()-0%0%
OnSessionHandler(...)-0%0%

File(s)

C:\Git\azure-sdk-for-net\sdk\servicebus\Microsoft.Azure.ServiceBus\src\SessionPumpHost.cs

#LineLine coverage
 1// Copyright (c) Microsoft. All rights reserved.
 2// Licensed under the MIT license. See LICENSE file in the project root for full license information.
 3
 4namespace Microsoft.Azure.ServiceBus
 5{
 6    using System;
 7    using System.Threading;
 8    using System.Threading.Tasks;
 9
 10    internal sealed class SessionPumpHost
 11    {
 12        readonly object syncLock;
 13        SessionReceivePump sessionReceivePump;
 14        CancellationTokenSource sessionPumpCancellationTokenSource;
 15        readonly Uri endpoint;
 16
 017        public SessionPumpHost(string clientId, ReceiveMode receiveMode, ISessionClient sessionClient, Uri endpoint)
 18        {
 019            this.syncLock = new object();
 020            this.ClientId = clientId;
 021            this.ReceiveMode = receiveMode;
 022            this.SessionClient = sessionClient;
 023            this.endpoint = endpoint;
 024        }
 25
 026        ReceiveMode ReceiveMode { get; }
 27
 028        ISessionClient SessionClient { get; }
 29
 030        string ClientId { get; }
 31
 32        public void Close()
 33        {
 034            if (this.sessionReceivePump != null)
 35            {
 036                this.sessionPumpCancellationTokenSource?.Cancel();
 037                this.sessionPumpCancellationTokenSource?.Dispose();
 038                this.sessionReceivePump = null;
 39            }
 040        }
 41
 42        public void OnSessionHandler(
 43            Func<IMessageSession, Message, CancellationToken, Task> callback,
 44            SessionHandlerOptions sessionHandlerOptions)
 45        {
 046            MessagingEventSource.Log.RegisterOnSessionHandlerStart(this.ClientId, sessionHandlerOptions);
 47
 048            lock (this.syncLock)
 49            {
 050                if (this.sessionReceivePump != null)
 51                {
 052                    throw new InvalidOperationException(Resources.SessionHandlerAlreadyRegistered);
 53                }
 54
 055                this.sessionPumpCancellationTokenSource = new CancellationTokenSource();
 056                this.sessionReceivePump = new SessionReceivePump(
 057                    this.ClientId,
 058                    this.SessionClient,
 059                    this.ReceiveMode,
 060                    sessionHandlerOptions,
 061                    callback,
 062                    this.endpoint,
 063                    this.sessionPumpCancellationTokenSource.Token);
 064            }
 65
 66            try
 67            {
 068                this.sessionReceivePump.StartPump();
 069            }
 070            catch (Exception exception)
 71            {
 072                MessagingEventSource.Log.RegisterOnSessionHandlerException(this.ClientId, exception);
 073                if (this.sessionReceivePump != null)
 74                {
 075                    this.sessionPumpCancellationTokenSource.Cancel();
 076                    this.sessionPumpCancellationTokenSource.Dispose();
 077                    this.sessionReceivePump = null;
 78                }
 79
 080                throw;
 81            }
 82
 083            MessagingEventSource.Log.RegisterOnSessionHandlerStop(this.ClientId);
 084        }
 85    }
 86}