From dfcc183c8d7735a1524ed10e7419e7de18db21af Mon Sep 17 00:00:00 2001 From: Luke Bakken Date: Fri, 25 Feb 2022 10:24:04 -0800 Subject: [PATCH] Use constants --- .gitignore | 1 - .../client/api/IConnectionExtensions.cs | 8 ++-- .../client/api/InternalConstants.cs | 41 +++++++++++++++++++ .../client/impl/AutorecoveringConnection.cs | 2 +- .../RabbitMQ.Client/client/impl/Connection.cs | 2 +- .../RabbitMQ.Client/client/impl/ModelBase.cs | 2 +- 6 files changed, 48 insertions(+), 8 deletions(-) create mode 100644 projects/RabbitMQ.Client/client/api/InternalConstants.cs diff --git a/.gitignore b/.gitignore index b42864eedc..9b6ed3ef31 100644 --- a/.gitignore +++ b/.gitignore @@ -19,7 +19,6 @@ TestResult.xml /NuGet .vscode/ *.lock.json -api/ test.sh *.VisualState.xml diff --git a/projects/RabbitMQ.Client/client/api/IConnectionExtensions.cs b/projects/RabbitMQ.Client/client/api/IConnectionExtensions.cs index 4cece0cde3..444b46c70a 100644 --- a/projects/RabbitMQ.Client/client/api/IConnectionExtensions.cs +++ b/projects/RabbitMQ.Client/client/api/IConnectionExtensions.cs @@ -19,7 +19,7 @@ public static class IConnectionExtensions /// public static void Close(this IConnection connection) { - connection.Close(Constants.ReplySuccess, "Goodbye", TimeSpan.FromSeconds(30), false); + connection.Close(Constants.ReplySuccess, "Goodbye", InternalConstants.DefaultConnectionCloseTimeout, false); } /// @@ -37,7 +37,7 @@ public static void Close(this IConnection connection) /// public static void Close(this IConnection connection, ushort reasonCode, string reasonText) { - connection.Close(reasonCode, reasonText, TimeSpan.FromSeconds(30), false); + connection.Close(reasonCode, reasonText, InternalConstants.DefaultConnectionCloseTimeout, false); } /// @@ -93,7 +93,7 @@ public static void Close(this IConnection connection, ushort reasonCode, string /// public static void Abort(this IConnection connection) { - connection.Close(Constants.ReplySuccess, "Connection close forced", TimeSpan.FromSeconds(5), true); + connection.Close(Constants.ReplySuccess, "Connection close forced", InternalConstants.DefaultConnectionAbortTimeout, true); } /// @@ -111,7 +111,7 @@ public static void Abort(this IConnection connection) /// public static void Abort(this IConnection connection, ushort reasonCode, string reasonText) { - connection.Close(reasonCode, reasonText, TimeSpan.FromSeconds(5), true); + connection.Close(reasonCode, reasonText, InternalConstants.DefaultConnectionAbortTimeout, true); } /// diff --git a/projects/RabbitMQ.Client/client/api/InternalConstants.cs b/projects/RabbitMQ.Client/client/api/InternalConstants.cs new file mode 100644 index 0000000000..8ee85ae173 --- /dev/null +++ b/projects/RabbitMQ.Client/client/api/InternalConstants.cs @@ -0,0 +1,41 @@ +// This source code is dual-licensed under the Apache License, version +// 2.0, and the Mozilla Public License, version 2.0. +// +// The APL v2.0: +// +//--------------------------------------------------------------------------- +// Copyright (c) 2007-2020 VMware, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +//--------------------------------------------------------------------------- +// +// The MPL v2.0: +// +//--------------------------------------------------------------------------- +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. +// +// Copyright (c) 2007-2020 VMware, Inc. All rights reserved. +//--------------------------------------------------------------------------- + +using System; + +namespace RabbitMQ.Client +{ + internal static class InternalConstants + { + internal static readonly TimeSpan DefaultConnectionAbortTimeout = TimeSpan.FromSeconds(5); + internal static readonly TimeSpan DefaultConnectionCloseTimeout = TimeSpan.FromSeconds(30); + } +} diff --git a/projects/RabbitMQ.Client/client/impl/AutorecoveringConnection.cs b/projects/RabbitMQ.Client/client/impl/AutorecoveringConnection.cs index 272cbeb89f..fb3aa18b11 100644 --- a/projects/RabbitMQ.Client/client/impl/AutorecoveringConnection.cs +++ b/projects/RabbitMQ.Client/client/impl/AutorecoveringConnection.cs @@ -216,7 +216,7 @@ public void Dispose() try { - this.Abort(TimeSpan.FromSeconds(15)); + this.Abort(InternalConstants.DefaultConnectionAbortTimeout); } catch (Exception) { diff --git a/projects/RabbitMQ.Client/client/impl/Connection.cs b/projects/RabbitMQ.Client/client/impl/Connection.cs index 9511529172..53e40b3048 100644 --- a/projects/RabbitMQ.Client/client/impl/Connection.cs +++ b/projects/RabbitMQ.Client/client/impl/Connection.cs @@ -410,7 +410,7 @@ public void Dispose() try { - this.Abort(TimeSpan.FromSeconds(15)); + this.Abort(InternalConstants.DefaultConnectionAbortTimeout); _mainLoopTask.Wait(); } catch (OperationInterruptedException) diff --git a/projects/RabbitMQ.Client/client/impl/ModelBase.cs b/projects/RabbitMQ.Client/client/impl/ModelBase.cs index c8d9f9f893..fe3e46ee10 100644 --- a/projects/RabbitMQ.Client/client/impl/ModelBase.cs +++ b/projects/RabbitMQ.Client/client/impl/ModelBase.cs @@ -742,7 +742,7 @@ protected void HandleConnectionStart(in IncomingCommand cmd) if (m_connectionStartCell is null) { var reason = new ShutdownEventArgs(ShutdownInitiator.Library, Constants.CommandInvalid, "Unexpected Connection.Start"); - Session.Connection.Close(reason, false, TimeSpan.FromSeconds(30)); + Session.Connection.Close(reason, false, InternalConstants.DefaultConnectionCloseTimeout); } var method = new ConnectionStart(cmd.MethodBytes.Span);