diff --git a/src/Microsoft.Azure.ServiceBus/ClientEntity.cs b/src/Microsoft.Azure.ServiceBus/ClientEntity.cs
index fca9708c..3de07d8b 100644
--- a/src/Microsoft.Azure.ServiceBus/ClientEntity.cs
+++ b/src/Microsoft.Azure.ServiceBus/ClientEntity.cs
@@ -54,6 +54,11 @@ internal set
///
public abstract ServiceBusConnection ServiceBusConnection { get; }
+ ///
+ /// Returns true if connection is owned and false if connection is shared.
+ ///
+ public bool OwnsConnection { get; internal set; }
+
///
/// Gets the name of the entity.
///
diff --git a/src/Microsoft.Azure.ServiceBus/Core/MessageReceiver.cs b/src/Microsoft.Azure.ServiceBus/Core/MessageReceiver.cs
index 198c99a6..7d4b6a78 100644
--- a/src/Microsoft.Azure.ServiceBus/Core/MessageReceiver.cs
+++ b/src/Microsoft.Azure.ServiceBus/Core/MessageReceiver.cs
@@ -48,7 +48,6 @@ public class MessageReceiver : ClientEntity, IMessageReceiver
readonly ConcurrentExpiringSet requestResponseLockedMessages;
readonly bool isSessionReceiver;
readonly object messageReceivePumpSyncLock;
- readonly bool ownsConnection;
readonly ActiveClientLinkManager clientLinkManager;
readonly ServiceBusDiagnosticSource diagnosticSource;
@@ -99,7 +98,7 @@ public MessageReceiver(
throw Fx.Exception.ArgumentNullOrWhiteSpace(connectionString);
}
- this.ownsConnection = true;
+ this.OwnsConnection = true;
}
///
@@ -124,7 +123,7 @@ public MessageReceiver(
int prefetchCount = Constants.DefaultClientPrefetchCount)
: this(entityPath, null, receiveMode, new ServiceBusConnection(endpoint, transportType, retryPolicy) {TokenProvider = tokenProvider}, null, retryPolicy, prefetchCount)
{
- this.ownsConnection = true;
+ this.OwnsConnection = true;
}
///
@@ -145,7 +144,7 @@ public MessageReceiver(
int prefetchCount = Constants.DefaultClientPrefetchCount)
: this(entityPath, null, receiveMode, serviceBusConnection, null, retryPolicy, prefetchCount)
{
- this.ownsConnection = false;
+ this.OwnsConnection = false;
}
internal MessageReceiver(
@@ -1009,7 +1008,7 @@ protected override async Task OnClosingAsync()
await this.ReceiveLinkManager.CloseAsync().ConfigureAwait(false);
await this.RequestResponseLinkManager.CloseAsync().ConfigureAwait(false);
- if (this.ownsConnection)
+ if (this.OwnsConnection)
{
await this.ServiceBusConnection.CloseAsync().ConfigureAwait(false);
}
diff --git a/src/Microsoft.Azure.ServiceBus/Core/MessageSender.cs b/src/Microsoft.Azure.ServiceBus/Core/MessageSender.cs
index 2c1de23c..b1e2438c 100644
--- a/src/Microsoft.Azure.ServiceBus/Core/MessageSender.cs
+++ b/src/Microsoft.Azure.ServiceBus/Core/MessageSender.cs
@@ -37,7 +37,6 @@ namespace Microsoft.Azure.ServiceBus.Core
public class MessageSender : ClientEntity, IMessageSender
{
int deliveryCount;
- readonly bool ownsConnection;
readonly ActiveClientLinkManager clientLinkManager;
readonly ServiceBusDiagnosticSource diagnosticSource;
readonly bool isViaSender;
@@ -74,7 +73,7 @@ public MessageSender(
throw Fx.Exception.ArgumentNullOrWhiteSpace(connectionString);
}
- this.ownsConnection = true;
+ this.OwnsConnection = true;
}
///
@@ -94,7 +93,7 @@ public MessageSender(
RetryPolicy retryPolicy = null)
: this(entityPath, null, null, new ServiceBusConnection(endpoint, transportType, retryPolicy) {TokenProvider = tokenProvider}, null, retryPolicy)
{
- this.ownsConnection = true;
+ this.OwnsConnection = true;
}
///
@@ -109,7 +108,7 @@ public MessageSender(
RetryPolicy retryPolicy = null)
: this(entityPath, null, null, serviceBusConnection, null, retryPolicy)
{
- this.ownsConnection = false;
+ this.OwnsConnection = false;
}
///
@@ -132,7 +131,7 @@ public MessageSender(
RetryPolicy retryPolicy = null)
:this(viaEntityPath, entityPath, null, serviceBusConnection, null, retryPolicy)
{
- this.ownsConnection = false;
+ this.OwnsConnection = false;
}
internal MessageSender(
@@ -444,7 +443,7 @@ protected override async Task OnClosingAsync()
await this.SendLinkManager.CloseAsync().ConfigureAwait(false);
await this.RequestResponseLinkManager.CloseAsync().ConfigureAwait(false);
- if (this.ownsConnection)
+ if (this.OwnsConnection)
{
await this.ServiceBusConnection.CloseAsync().ConfigureAwait(false);
}
diff --git a/src/Microsoft.Azure.ServiceBus/QueueClient.cs b/src/Microsoft.Azure.ServiceBus/QueueClient.cs
index 679fcc94..9e4f7620 100644
--- a/src/Microsoft.Azure.ServiceBus/QueueClient.cs
+++ b/src/Microsoft.Azure.ServiceBus/QueueClient.cs
@@ -54,7 +54,6 @@ namespace Microsoft.Azure.ServiceBus
/// It uses AMQP protocol for communicating with servicebus.
public class QueueClient : ClientEntity, IQueueClient
{
- readonly bool ownsConnection;
readonly object syncLock;
int prefetchCount;
@@ -91,7 +90,7 @@ public QueueClient(string connectionString, string entityPath, ReceiveMode recei
throw Fx.Exception.ArgumentNullOrWhiteSpace(connectionString);
}
- this.ownsConnection = true;
+ this.OwnsConnection = true;
}
///
@@ -113,7 +112,7 @@ public QueueClient(
RetryPolicy retryPolicy = null)
: this(new ServiceBusConnection(endpoint, transportType, retryPolicy) {TokenProvider = tokenProvider}, entityPath, receiveMode, retryPolicy)
{
- this.ownsConnection = true;
+ this.OwnsConnection = true;
}
///
@@ -137,7 +136,7 @@ public QueueClient(ServiceBusConnection serviceBusConnection, string entityPath,
this.syncLock = new object();
this.QueueName = entityPath;
this.ReceiveMode = receiveMode;
- this.ownsConnection = false;
+ this.OwnsConnection = false;
if (this.ServiceBusConnection.TokenProvider != null)
{
this.CbsTokenProvider = new TokenProviderAdapter(this.ServiceBusConnection.TokenProvider, this.ServiceBusConnection.OperationTimeout);
@@ -535,7 +534,7 @@ protected override async Task OnClosingAsync()
await this.sessionClient.CloseAsync().ConfigureAwait(false);
}
- if (this.ownsConnection)
+ if (this.OwnsConnection)
{
await this.ServiceBusConnection.CloseAsync().ConfigureAwait(false);
}
diff --git a/src/Microsoft.Azure.ServiceBus/SessionClient.cs b/src/Microsoft.Azure.ServiceBus/SessionClient.cs
index ff88d269..48bdf339 100644
--- a/src/Microsoft.Azure.ServiceBus/SessionClient.cs
+++ b/src/Microsoft.Azure.ServiceBus/SessionClient.cs
@@ -45,7 +45,6 @@ namespace Microsoft.Azure.ServiceBus
public sealed class SessionClient : ClientEntity, ISessionClient
{
const int DefaultPrefetchCount = 0;
- readonly bool ownsConnection;
readonly ServiceBusDiagnosticSource diagnosticSource;
///
@@ -97,7 +96,7 @@ public SessionClient(
throw Fx.Exception.ArgumentNullOrWhiteSpace(connectionString);
}
- this.ownsConnection = true;
+ this.OwnsConnection = true;
}
///
@@ -130,7 +129,7 @@ public SessionClient(
retryPolicy,
null)
{
- this.ownsConnection = true;
+ this.OwnsConnection = true;
}
///
@@ -158,7 +157,7 @@ public SessionClient(
retryPolicy,
null)
{
- this.ownsConnection = false;
+ this.OwnsConnection = false;
}
internal SessionClient(
@@ -397,7 +396,7 @@ public override void UnregisterPlugin(string serviceBusPluginName)
protected override async Task OnClosingAsync()
{
- if (this.ownsConnection)
+ if (this.OwnsConnection)
{
await this.ServiceBusConnection.CloseAsync().ConfigureAwait(false);
}
diff --git a/src/Microsoft.Azure.ServiceBus/SubscriptionClient.cs b/src/Microsoft.Azure.ServiceBus/SubscriptionClient.cs
index 1e840b62..13e11fcd 100644
--- a/src/Microsoft.Azure.ServiceBus/SubscriptionClient.cs
+++ b/src/Microsoft.Azure.ServiceBus/SubscriptionClient.cs
@@ -52,7 +52,6 @@ public class SubscriptionClient : ClientEntity, ISubscriptionClient
{
int prefetchCount;
readonly object syncLock;
- readonly bool ownsConnection;
readonly ServiceBusDiagnosticSource diagnosticSource;
IInnerSubscriptionClient innerSubscriptionClient;
@@ -86,7 +85,7 @@ public SubscriptionClient(string connectionString, string topicPath, string subs
throw Fx.Exception.ArgumentNullOrWhiteSpace(connectionString);
}
- this.ownsConnection = true;
+ this.OwnsConnection = true;
}
///
@@ -110,7 +109,7 @@ public SubscriptionClient(
RetryPolicy retryPolicy = null)
: this(new ServiceBusConnection(endpoint, transportType, retryPolicy) {TokenProvider = tokenProvider}, topicPath, subscriptionName, receiveMode, retryPolicy)
{
- this.ownsConnection = true;
+ this.OwnsConnection = true;
}
///
@@ -142,7 +141,7 @@ public SubscriptionClient(ServiceBusConnection serviceBusConnection, string topi
this.Path = EntityNameHelper.FormatSubscriptionPath(this.TopicPath, this.SubscriptionName);
this.ReceiveMode = receiveMode;
this.diagnosticSource = new ServiceBusDiagnosticSource(this.Path, serviceBusConnection.Endpoint);
- this.ownsConnection = false;
+ this.OwnsConnection = false;
if (this.ServiceBusConnection.TokenProvider != null)
{
this.CbsTokenProvider = new TokenProviderAdapter(this.ServiceBusConnection.TokenProvider, this.ServiceBusConnection.OperationTimeout);
@@ -637,7 +636,7 @@ protected override async Task OnClosingAsync()
await this.sessionClient.CloseAsync().ConfigureAwait(false);
}
- if (this.ownsConnection)
+ if (this.OwnsConnection)
{
await this.ServiceBusConnection.CloseAsync().ConfigureAwait(false);
}
diff --git a/src/Microsoft.Azure.ServiceBus/TopicClient.cs b/src/Microsoft.Azure.ServiceBus/TopicClient.cs
index 9fee3bee..e31707f7 100644
--- a/src/Microsoft.Azure.ServiceBus/TopicClient.cs
+++ b/src/Microsoft.Azure.ServiceBus/TopicClient.cs
@@ -31,7 +31,6 @@ namespace Microsoft.Azure.ServiceBus
/// It uses AMQP protocol for communicating with servicebus.
public class TopicClient : ClientEntity, ITopicClient
{
- readonly bool ownsConnection;
readonly object syncLock;
MessageSender innerSender;
@@ -61,7 +60,7 @@ public TopicClient(string connectionString, string entityPath, RetryPolicy retry
throw Fx.Exception.ArgumentNullOrWhiteSpace(connectionString);
}
- this.ownsConnection = true;
+ this.OwnsConnection = true;
}
///
@@ -81,7 +80,7 @@ public TopicClient(
RetryPolicy retryPolicy = null)
: this(new ServiceBusConnection(endpoint, transportType, retryPolicy) {TokenProvider = tokenProvider}, entityPath, retryPolicy)
{
- this.ownsConnection = true;
+ this.OwnsConnection = true;
}
///
@@ -102,7 +101,7 @@ public TopicClient(ServiceBusConnection serviceBusConnection, string entityPath,
this.ServiceBusConnection = serviceBusConnection ?? throw new ArgumentNullException(nameof(serviceBusConnection));
this.syncLock = new object();
this.TopicName = entityPath;
- this.ownsConnection = false;
+ this.OwnsConnection = false;
if (this.ServiceBusConnection.TokenProvider != null)
{
this.CbsTokenProvider = new TokenProviderAdapter(this.ServiceBusConnection.TokenProvider, this.ServiceBusConnection.OperationTimeout);
@@ -236,7 +235,7 @@ protected override async Task OnClosingAsync()
await this.innerSender.CloseAsync().ConfigureAwait(false);
}
- if (this.ownsConnection)
+ if (this.OwnsConnection)
{
await this.ServiceBusConnection.CloseAsync().ConfigureAwait(false);
}
diff --git a/test/Microsoft.Azure.ServiceBus.UnitTests/API/ApiApprovals.ApproveAzureServiceBus.approved.txt b/test/Microsoft.Azure.ServiceBus.UnitTests/API/ApiApprovals.ApproveAzureServiceBus.approved.txt
index bb44dc86..f911f396 100644
--- a/test/Microsoft.Azure.ServiceBus.UnitTests/API/ApiApprovals.ApproveAzureServiceBus.approved.txt
+++ b/test/Microsoft.Azure.ServiceBus.UnitTests/API/ApiApprovals.ApproveAzureServiceBus.approved.txt
@@ -10,6 +10,7 @@ namespace Microsoft.Azure.ServiceBus
public string ClientId { get; }
public bool IsClosedOrClosing { get; }
public abstract System.TimeSpan OperationTimeout { get; set; }
+ public bool OwnsConnection { get; }
public abstract string Path { get; }
public abstract System.Collections.Generic.IList RegisteredPlugins { get; }
public Microsoft.Azure.ServiceBus.RetryPolicy RetryPolicy { get; }