Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lifecycle updates #14773

Merged
merged 6 commits into from
Sep 1, 2020
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ public CreateMessageBatchOptions() { }
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
public override string ToString() { throw null; }
}
public enum LinkCloseMode
{
Detach = 0,
}
public sealed partial class ProcessErrorEventArgs : System.EventArgs
{
public ProcessErrorEventArgs(System.Exception exception, Azure.Messaging.ServiceBus.ServiceBusErrorSource errorSource, string fullyQualifiedNamespace, string entityPath) { }
Expand Down Expand Up @@ -67,7 +71,7 @@ public ServiceBusClient(string fullyQualifiedNamespace, Azure.Core.TokenCredenti
public ServiceBusClient(string fullyQualifiedNamespace, Azure.Core.TokenCredential credential, Azure.Messaging.ServiceBus.ServiceBusClientOptions options) { }
public ServiceBusClient(string connectionString, Azure.Messaging.ServiceBus.ServiceBusClientOptions options) { }
public string FullyQualifiedNamespace { get { throw null; } }
public bool IsDisposed { get { throw null; } }
public bool IsClosed { get { throw null; } }
public Azure.Messaging.ServiceBus.ServiceBusTransportType TransportType { get { throw null; } }
public virtual Azure.Messaging.ServiceBus.ServiceBusProcessor CreateProcessor(string queueName) { throw null; }
public virtual Azure.Messaging.ServiceBus.ServiceBusProcessor CreateProcessor(string queueName, Azure.Messaging.ServiceBus.ServiceBusProcessorOptions options) { throw null; }
Expand Down Expand Up @@ -182,12 +186,13 @@ public static partial class ServiceBusModelFactory
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
public static Azure.Messaging.ServiceBus.Management.TopicProperties TopicProperties(string name, long maxSizeInMegabytes = (long)0, bool requiresDuplicateDetection = false, System.TimeSpan defaultMessageTimeToLive = default(System.TimeSpan), System.TimeSpan autoDeleteOnIdle = default(System.TimeSpan), System.TimeSpan duplicateDetectionHistoryTimeWindow = default(System.TimeSpan), bool enableBatchedOperations = false, Azure.Messaging.ServiceBus.Management.EntityStatus status = default(Azure.Messaging.ServiceBus.Management.EntityStatus)) { throw null; }
}
public partial class ServiceBusProcessor
public partial class ServiceBusProcessor : System.IAsyncDisposable
{
protected ServiceBusProcessor() { }
public bool AutoComplete { get { throw null; } }
public string EntityPath { get { throw null; } }
public string FullyQualifiedNamespace { get { throw null; } }
public bool IsClosed { get { throw null; } }
public bool IsProcessing { get { throw null; } }
public System.TimeSpan MaxAutoLockRenewalDuration { get { throw null; } }
public int MaxConcurrentCalls { get { throw null; } }
Expand All @@ -196,6 +201,8 @@ protected ServiceBusProcessor() { }
public Azure.Messaging.ServiceBus.ReceiveMode ReceiveMode { get { throw null; } }
public event System.Func<Azure.Messaging.ServiceBus.ProcessErrorEventArgs, System.Threading.Tasks.Task> ProcessErrorAsync { add { } remove { } }
public event System.Func<Azure.Messaging.ServiceBus.ProcessMessageEventArgs, System.Threading.Tasks.Task> ProcessMessageAsync { add { } remove { } }
public virtual System.Threading.Tasks.Task CloseAsync(Azure.Messaging.ServiceBus.LinkCloseMode closeMode = Azure.Messaging.ServiceBus.LinkCloseMode.Detach, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public System.Threading.Tasks.ValueTask DisposeAsync() { throw null; }
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
public override bool Equals(object obj) { throw null; }
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
Expand Down Expand Up @@ -256,10 +263,11 @@ public partial class ServiceBusReceiver : System.IAsyncDisposable
protected ServiceBusReceiver() { }
public string EntityPath { get { throw null; } }
public string FullyQualifiedNamespace { get { throw null; } }
public bool IsDisposed { get { throw null; } }
public bool IsClosed { get { throw null; } }
public int PrefetchCount { get { throw null; } }
public Azure.Messaging.ServiceBus.ReceiveMode ReceiveMode { get { throw null; } }
public virtual System.Threading.Tasks.Task AbandonMessageAsync(Azure.Messaging.ServiceBus.ServiceBusReceivedMessage message, System.Collections.Generic.IDictionary<string, object> propertiesToModify = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual System.Threading.Tasks.Task CloseAsync(Azure.Messaging.ServiceBus.LinkCloseMode closeMode = Azure.Messaging.ServiceBus.LinkCloseMode.Detach, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual System.Threading.Tasks.Task CompleteMessageAsync(Azure.Messaging.ServiceBus.ServiceBusReceivedMessage message, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual System.Threading.Tasks.Task DeadLetterMessageAsync(Azure.Messaging.ServiceBus.ServiceBusReceivedMessage message, System.Collections.Generic.IDictionary<string, object> propertiesToModify = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual System.Threading.Tasks.Task DeadLetterMessageAsync(Azure.Messaging.ServiceBus.ServiceBusReceivedMessage message, string deadLetterReason, string deadLetterErrorDescription = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
Expand Down Expand Up @@ -325,10 +333,11 @@ public partial class ServiceBusSender : System.IAsyncDisposable
protected ServiceBusSender() { }
public string EntityPath { get { throw null; } }
public string FullyQualifiedNamespace { get { throw null; } }
public bool IsDisposed { get { throw null; } }
public bool IsClosed { get { throw null; } }
public string ViaEntityPath { get { throw null; } }
public virtual System.Threading.Tasks.Task CancelScheduledMessageAsync(long sequenceNumber, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual System.Threading.Tasks.Task CancelScheduledMessagesAsync(System.Collections.Generic.IEnumerable<long> sequenceNumbers, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual System.Threading.Tasks.Task CloseAsync(Azure.Messaging.ServiceBus.LinkCloseMode closeMode = Azure.Messaging.ServiceBus.LinkCloseMode.Detach, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual System.Threading.Tasks.ValueTask<Azure.Messaging.ServiceBus.ServiceBusMessageBatch> CreateMessageBatchAsync(Azure.Messaging.ServiceBus.CreateMessageBatchOptions options, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual System.Threading.Tasks.ValueTask<Azure.Messaging.ServiceBus.ServiceBusMessageBatch> CreateMessageBatchAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual System.Threading.Tasks.ValueTask DisposeAsync() { throw null; }
Expand All @@ -355,12 +364,13 @@ public ServiceBusSenderOptions() { }
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
public override string ToString() { throw null; }
}
public partial class ServiceBusSessionProcessor
public partial class ServiceBusSessionProcessor : System.IAsyncDisposable
{
protected ServiceBusSessionProcessor() { }
public bool AutoComplete { get { throw null; } }
public string EntityPath { get { throw null; } }
public string FullyQualifiedNamespace { get { throw null; } }
public bool IsClosed { get { throw null; } }
public bool IsProcessing { get { throw null; } }
public System.TimeSpan MaxAutoLockRenewalDuration { get { throw null; } }
public int MaxConcurrentCallsPerSession { get { throw null; } }
Expand All @@ -372,6 +382,8 @@ protected ServiceBusSessionProcessor() { }
public event System.Func<Azure.Messaging.ServiceBus.ProcessSessionMessageEventArgs, System.Threading.Tasks.Task> ProcessMessageAsync { add { } remove { } }
public event System.Func<Azure.Messaging.ServiceBus.ProcessSessionEventArgs, System.Threading.Tasks.Task> SessionClosingAsync { add { } remove { } }
public event System.Func<Azure.Messaging.ServiceBus.ProcessSessionEventArgs, System.Threading.Tasks.Task> SessionInitializingAsync { add { } remove { } }
public virtual System.Threading.Tasks.Task CloseAsync(Azure.Messaging.ServiceBus.LinkCloseMode closeMode = Azure.Messaging.ServiceBus.LinkCloseMode.Detach, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public System.Threading.Tasks.ValueTask DisposeAsync() { throw null; }
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
public override bool Equals(object obj) { throw null; }
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ public class ServiceBusClient : IAsyncDisposable
public string FullyQualifiedNamespace => Connection.FullyQualifiedNamespace;

/// <summary>
/// Indicates whether or not this <see cref="ServiceBusClient"/> has been disposed.
/// Indicates whether or not this <see cref="ServiceBusClient"/> has been closed.
/// </summary>
///
/// <value>
/// <c>true</c> if the client is disposed; otherwise, <c>false</c>.
/// <c>true</c> if the client is closed; otherwise, <c>false</c>.
/// </value>
public bool IsDisposed { get; private set; } = false;
public bool IsClosed { get; private set; } = false;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You may want to consider moving this out to use a volatile backing field.


/// <summary>
/// The transport type used for this <see cref="ServiceBusClient"/>.
Expand All @@ -53,7 +53,6 @@ public class ServiceBusClient : IAsyncDisposable
/// <summary>
/// The instance of <see cref="ServiceBusEventSource" /> which can be mocked for testing.
/// </summary>
///
internal ServiceBusEventSource Logger { get; set; } = ServiceBusEventSource.Log;

/// <summary>
Expand All @@ -70,20 +69,20 @@ public class ServiceBusClient : IAsyncDisposable
[SuppressMessage("Usage", "AZC0002:Ensure all service methods take an optional CancellationToken parameter.", Justification = "This signature must match the IAsyncDisposable interface.")]
public virtual async ValueTask DisposeAsync()
{
Logger.ClientDisposeStart(typeof(ServiceBusClient), Identifier);
IsDisposed = true;
Logger.ClientCloseStart(typeof(ServiceBusClient), Identifier);
IsClosed = true;
try
{
await Connection.CloseAsync(CancellationToken.None).ConfigureAwait(false);
}
catch (Exception ex)
{
Logger.ClientDisposeException(typeof(ServiceBusClient), Identifier, ex);
Logger.ClientCloseException(typeof(ServiceBusClient), Identifier, ex);
throw;
}
finally
{
Logger.ClientDisposeComplete(typeof(ServiceBusClient), Identifier);
Logger.ClientCloseComplete(typeof(ServiceBusClient), Identifier);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,9 @@ internal ServiceBusEventSource() { }
internal const int ManagementSerializedExceptionEvent = 42;
internal const int RunOperationExceptionEvent = 43;

internal const int ClientDisposeStartEvent = 44;
internal const int ClientDisposeCompleteEvent = 45;
internal const int ClientDisposeExceptionEvent = 46;
internal const int ClientCloseStartEvent = 44;
internal const int ClientCloseCompleteEvent = 45;
internal const int ClientCloseExceptionEvent = 46;

internal const int RenewSessionLockStartEvent = 47;
internal const int RenewSessionLockCompleteEvent = 48;
Expand Down Expand Up @@ -1185,31 +1185,31 @@ public virtual void ClientCreateExceptionCore(
/// <summary>
/// Indicates that a client is closing, which may correspond to
/// a <see cref="ServiceBusClient" />, <see cref="ServiceBusSender" />,
/// or <see cref="ServiceBusReceiver"/>.
/// <see cref="ServiceBusReceiver"/>, or a <see cref="ServiceBusProcessor"/>.
/// </summary>
///
/// <param name="clientType">The type of client being closed.</param>
/// <param name="identifier">An identifier to associate with the client.</param>
///
[NonEvent]
public virtual void ClientDisposeStart(
public virtual void ClientCloseStart(
Type clientType,
string identifier)
{
if (IsEnabled())
{
ClientDisposeStartCore(clientType.Name, identifier ?? string.Empty);
ClientCloseStartCore(clientType.Name, identifier ?? string.Empty);
}
}

[Event(ClientDisposeStartEvent, Level = EventLevel.Verbose, Message = "Closing a {0} (Identifier '{1}').")]
public virtual void ClientDisposeStartCore(
[Event(ClientCloseStartEvent, Level = EventLevel.Verbose, Message = "Closing a {0} (Identifier '{1}').")]
public virtual void ClientCloseStartCore(
string clientType,
string identifier)
{
if (IsEnabled())
{
WriteEvent(ClientDisposeStartEvent, clientType, identifier);
WriteEvent(ClientCloseStartEvent, clientType, identifier);
}
}

Expand All @@ -1222,24 +1222,24 @@ public virtual void ClientDisposeStartCore(
/// <param name="identifier">An identifier to associate with the client.</param>
///
[NonEvent]
public virtual void ClientDisposeComplete(
public virtual void ClientCloseComplete(
Type clientType,
string identifier)
{
if (IsEnabled())
{
ClientDisposeCompleteCore(clientType.Name, identifier ?? string.Empty);
ClientCloseCompleteCore(clientType.Name, identifier ?? string.Empty);
}
}

[Event(ClientDisposeCompleteEvent, Level = EventLevel.Verbose, Message = "A {0} has been closed (Identifier '{1}').")]
public virtual void ClientDisposeCompleteCore(
[Event(ClientCloseCompleteEvent, Level = EventLevel.Verbose, Message = "A {0} has been closed (Identifier '{1}').")]
public virtual void ClientCloseCompleteCore(
string clientType,
string identifier)
{
if (IsEnabled())
{
WriteEvent(ClientDisposeCompleteEvent, clientType, identifier);
WriteEvent(ClientCloseCompleteEvent, clientType, identifier);
}
}

Expand All @@ -1253,26 +1253,26 @@ public virtual void ClientDisposeCompleteCore(
/// <param name="exception">The message for the exception that occurred.</param>
///
[NonEvent]
public virtual void ClientDisposeException(
public virtual void ClientCloseException(
Type clientType,
string identifier,
Exception exception)
{
if (IsEnabled())
{
ClientDisposeExceptionCore(clientType.Name, identifier ?? string.Empty, exception.ToString());
ClientCloseExceptionCore(clientType.Name, identifier ?? string.Empty, exception.ToString());
}
}

[Event(ClientDisposeExceptionEvent, Level = EventLevel.Error, Message = "An exception occurred while closing a {0} (Identifier '{1}'). Error Message: '{2}'")]
public virtual void ClientDisposeExceptionCore(
[Event(ClientCloseExceptionEvent, Level = EventLevel.Error, Message = "An exception occurred while closing a {0} (Identifier '{1}'). Error Message: '{2}'")]
public virtual void ClientCloseExceptionCore(
string clientType,
string identifier,
string exception)
{
if (IsEnabled())
{
WriteEvent(ClientDisposeExceptionEvent, clientType, identifier, exception);
WriteEvent(ClientCloseExceptionEvent, clientType, identifier, exception);
}
}
#endregion
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

namespace Azure.Messaging.ServiceBus
{
/// <summary>
/// The mode in which links will be closed.
/// </summary>
public enum LinkCloseMode
{
/// <summary>
/// The link will be detached when closing.
/// </summary>
Detach = 0
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ public ReceiverManager(
}

public virtual async Task CloseReceiverIfNeeded(
CancellationToken cancellationToken)
CancellationToken cancellationToken,
bool forceClose = false)
{
try
{
Expand Down Expand Up @@ -269,7 +270,7 @@ private async Task RenewMessageLock(
TimeSpan delay = CalculateRenewDelay(message.LockedUntil);

await Task.Delay(delay, cancellationToken).ConfigureAwait(false);
if (Receiver.IsDisposed)
if (Receiver.IsClosed)
{
break;
}
Expand Down
Loading