Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Use .NET Events instead of lambdas

  • Loading branch information...
commit bb937f0e38ff2abae73f3d9252fda9c76d8a45c9 1 parent 91be05f
@jen20 jen20 authored
Showing with 392 additions and 527 deletions.
  1. +1 −0  .gitignore
  2. +32 −0 src/EventStore/EventStore.ClientAPI/ClientAuthenticationFailedEventArgs.cs
  3. +33 −0 src/EventStore/EventStore.ClientAPI/ClientClosedEventArgs.cs
  4. +33 −0 src/EventStore/EventStore.ClientAPI/ClientConnectionEventArgs.cs
  5. +31 −0 src/EventStore/EventStore.ClientAPI/ClientErrorEventArgs.cs
  6. +25 −0 src/EventStore/EventStore.ClientAPI/ClientReconnectingEventArgs.cs
  7. +23 −35 src/EventStore/EventStore.ClientAPI/ConnectionSettings.cs
  8. +8 −126 src/EventStore/EventStore.ClientAPI/ConnectionSettingsBuilder.cs
  9. +56 −16 src/EventStore/EventStore.ClientAPI/Core/EventStoreConnectionLogicHandler.cs
  10. +5 −1 src/EventStore/EventStore.ClientAPI/EventStore.ClientAPI.csproj
  11. +0 −321 src/EventStore/EventStore.ClientAPI/EventStoreClusterConnection.cs
  12. +12 −1 src/EventStore/EventStore.ClientAPI/EventStoreConnection.cs
  13. +71 −1 src/EventStore/EventStore.ClientAPI/EventStoreNodeConnection.cs
  14. +37 −0 src/EventStore/EventStore.ClientAPI/IEventStoreConnection.cs
  15. +0 −1  src/EventStore/EventStore.Core.Tests/ClientAPI/Helpers/TestConnection.cs
  16. +14 −13 src/EventStore/EventStore.Core.Tests/ClientAPI/connect.cs
  17. +6 −8 src/EventStore/EventStore.TestClient/Commands/RunTestScenarios/ScenarioBase.cs
  18. +1 −3 src/EventStore/EventStore.TestClient/Commands/WriteFloodClientApiProcessor.cs
  19. +4 −1 src/Style.DotSettings
View
1  .gitignore
@@ -10,6 +10,7 @@ ipch/
*.s
*.sdf
*.opensdf
+*.DotSettings
*.DotSettings.user
*.DotSettings.personal/Logs
/Data
View
32 src/EventStore/EventStore.ClientAPI/ClientAuthenticationFailedEventArgs.cs
@@ -0,0 +1,32 @@
+using System;
+
+namespace EventStore.ClientAPI
+{
+ /// <summary>
+ /// Event Arguments for the event raised when an <see cref="IEventStoreConnection"/> fails
+ /// to authenticate against an Event Store server.
+ /// </summary>
+ public class ClientAuthenticationFailedEventArgs : EventArgs
+ {
+ /// <summary>
+ /// A reason for authentication failure, if known.
+ /// </summary>
+ public string Reason { get; private set; }
+
+ /// <summary>
+ /// The <see cref="IEventStoreConnection"/> responsible for raising the event.
+ /// </summary>
+ public IEventStoreConnection Connection { get; private set; }
+
+ /// <summary>
+ /// Constructs a new instance of <see cref="ClientAuthenticationFailedEventArgs"/>.
+ /// </summary>
+ /// <param name="connection">The <see cref="IEventStoreConnection"/> responsible for raising the event.</param>
+ /// <param name="reason">A reason for authentication failure, if known.</param>
+ public ClientAuthenticationFailedEventArgs(IEventStoreConnection connection, string reason)
+ {
+ Connection = connection;
+ Reason = reason;
+ }
+ }
+}
View
33 src/EventStore/EventStore.ClientAPI/ClientClosedEventArgs.cs
@@ -0,0 +1,33 @@
+using System;
+
+namespace EventStore.ClientAPI
+{
+ /// <summary>
+ /// Event Arguments for the event raised when an <see cref="IEventStoreConnection"/> is
+ /// disconnected from an Event Store server.
+ /// </summary>
+ public class ClientClosedEventArgs : EventArgs
+ {
+ /// <summary>
+ /// A description of the reason the connection was closed if closing was initiated by the server or client API directly
+ /// rather than by calling <see cref="IEventStoreConnection.Close"/>.
+ /// </summary>
+ public string Reason { get; private set; }
+
+ /// <summary>
+ /// The <see cref="IEventStoreConnection"/> responsible for raising the event.
+ /// </summary>
+ public IEventStoreConnection Connection { get; private set; }
+
+ /// <summary>
+ /// Constructs a new instance of <see cref="ClientClosedEventArgs"/>.
+ /// </summary>
+ /// <param name="connection">The <see cref="IEventStoreConnection"/> responsible for raising the event.</param>
+ /// <param name="reason">A description of the reason the connection was closed.</param>
+ public ClientClosedEventArgs(IEventStoreConnection connection, string reason)
+ {
+ Connection = connection;
+ Reason = reason;
+ }
+ }
+}
View
33 src/EventStore/EventStore.ClientAPI/ClientConnectionEventArgs.cs
@@ -0,0 +1,33 @@
+using System;
+using System.Net;
+
+namespace EventStore.ClientAPI
+{
+ /// <summary>
+ /// Event Arguments for the event raised when an <see cref="IEventStoreConnection"/> is
+ /// connected to or disconnected from an Event Store server.
+ /// </summary>
+ public class ClientConnectionEventArgs : EventArgs
+ {
+ /// <summary>
+ /// The endpoint of the Event Store server to or from which the connection was connected or disconnected.
+ /// </summary>
+ public IPEndPoint RemoteEndPoint { get; private set; }
+
+ /// <summary>
+ /// The <see cref="IEventStoreConnection"/> responsible for raising the event.
+ /// </summary>
+ public IEventStoreConnection Connection { get; private set; }
+
+ /// <summary>
+ /// Constructs a new instance of <see cref="ClientConnectionEventArgs"/>.
+ /// </summary>
+ /// <param name="connection">The <see cref="IEventStoreConnection"/> responsible for raising the event.</param>
+ /// <param name="remoteEndPoint">The endpoint of the Event Store server to or from which the connection was connected or disconnected.</param>
+ public ClientConnectionEventArgs(IEventStoreConnection connection, IPEndPoint remoteEndPoint)
+ {
+ Connection = connection;
+ RemoteEndPoint = remoteEndPoint;
+ }
+ }
+}
View
31 src/EventStore/EventStore.ClientAPI/ClientErrorEventArgs.cs
@@ -0,0 +1,31 @@
+using System;
+
+namespace EventStore.ClientAPI
+{
+ /// <summary>
+ /// Event Arguments for the event raised when an error occurs on an <see cref="IEventStoreConnection"/>.
+ /// </summary>
+ public class ClientErrorEventArgs : EventArgs
+ {
+ /// <summary>
+ /// The thrown exception, if one was raised.
+ /// </summary>
+ public Exception Exception { get; private set; }
+
+ /// <summary>
+ /// The <see cref="IEventStoreConnection"/> responsible for raising the event.
+ /// </summary>
+ public IEventStoreConnection Connection { get; private set; }
+
+ /// <summary>
+ /// Constructs a new instance of <see cref="ClientErrorEventArgs"/>.
+ /// </summary>
+ /// <param name="connection">The <see cref="IEventStoreConnection"/> responsible for raising the event.</param>
+ /// <param name="exception">The thrown exception, if one was raised.</param>
+ public ClientErrorEventArgs(IEventStoreConnection connection, Exception exception)
+ {
+ Connection = connection;
+ Exception = exception;
+ }
+ }
+}
View
25 src/EventStore/EventStore.ClientAPI/ClientReconnectingEventArgs.cs
@@ -0,0 +1,25 @@
+using System;
+
+namespace EventStore.ClientAPI
+{
+ /// <summary>
+ /// Event Arguments for the event raised when an <see cref="IEventStoreConnection"/> is
+ /// about to reconnect to an Event Store server.
+ /// </summary>
+ public class ClientReconnectingEventArgs : EventArgs
+ {
+ /// <summary>
+ /// The <see cref="IEventStoreConnection"/> responsible for raising the event.
+ /// </summary>
+ public IEventStoreConnection Connection { get; private set; }
+
+ /// <summary>
+ /// Constructs a new instance of <see cref="ClientReconnectingEventArgs"/>.
+ /// </summary>
+ /// <param name="connection">The <see cref="IEventStoreConnection"/> responsible for raising the event.</param>
+ public ClientReconnectingEventArgs(IEventStoreConnection connection)
+ {
+ Connection = connection;
+ }
+ }
+}
View
58 src/EventStore/EventStore.ClientAPI/ConnectionSettings.cs
@@ -24,15 +24,19 @@
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-//
using System;
-using System.Net;
using EventStore.ClientAPI.Common.Utils;
using EventStore.ClientAPI.SystemData;
namespace EventStore.ClientAPI
{
+ /// <summary>
+ /// A <see cref="ConnectionSettings"/> object is an immutable representation of the settings for an
+ /// <see cref="IEventStoreConnection"/>. A <see cref="ConnectionSettings"/> object can be built using
+ /// a <see cref="ConnectionSettingsBuilder"/>, either via the <see cref="Create"/> method, or via
+ /// the constructor of <see cref="ConnectionSettingsBuilder"/>.
+ /// </summary>
public sealed class ConnectionSettings
{
private static readonly Lazy<ConnectionSettings> DefaultSettings = new Lazy<ConnectionSettings>(() => Create(), true);
@@ -91,40 +95,37 @@ public static ConnectionSettingsBuilder Create()
/// The amount of time that timeouts are checked in the system.
/// </summary>
public readonly TimeSpan OperationTimeoutCheckPeriod;
-
- public readonly UserCredentials DefaultUserCredentials;
- public readonly bool UseSslConnection;
- public readonly string TargetHost;
- public readonly bool ValidateServer;
-
/// <summary>
- /// Raised whenever the internal error occurs
+ /// The <see cref="UserCredentials"/> to use for operations where other <see cref="UserCredentials"/> are not explicitly supplied.
/// </summary>
- public Action<IEventStoreConnection, Exception> ErrorOccurred;
+ public readonly UserCredentials DefaultUserCredentials;
/// <summary>
- /// Raised whenever the connection is closed
+ /// Whether or not the connection is encrypted using SSL.
/// </summary>
- public Action<IEventStoreConnection, string> Closed;
+ public readonly bool UseSslConnection;
/// <summary>
- /// Raised whenever the internal connection is connected to the event store
+ /// The host name of the server expected on the SSL certificate.
/// </summary>
- public Action<IEventStoreConnection, IPEndPoint> Connected;
+ public readonly string TargetHost;
/// <summary>
- /// Raised whenever the internal connection is disconnected from the event store
+ /// Whether or not to validate the server SSL certificate.
/// </summary>
- public Action<IEventStoreConnection, IPEndPoint> Disconnected;
+ public readonly bool ValidateServer;
+
/// <summary>
- /// Raised whenever the internal connection is reconnecting to the event store
+ /// Whether or not to raise an error if no response is received from the server for an operation.
/// </summary>
- public Action<IEventStoreConnection> Reconnecting;
+ public readonly bool FailOnNoServerResponse;
/// <summary>
- /// Raised whenever the connection default user credentials authentication fails
+ /// The interval at which to send heartbeat messages.
/// </summary>
- public Action<IEventStoreConnection, string> AuthenticationFailed;
-
- public readonly bool FailOnNoServerResponse;
public readonly TimeSpan HeartbeatInterval;
+ /// <summary>
+ /// The interval after which an unacknowledged heartbeat will cause the connection to be considered faulted and disconnect.
+ /// </summary>
public readonly TimeSpan HeartbeatTimeout;
+
+
public readonly TimeSpan ClientConnectionTimeout;
internal ConnectionSettings(ILogger log,
@@ -141,12 +142,6 @@ public static ConnectionSettingsBuilder Create()
bool useSslConnection,
string targetHost,
bool validateServer,
- Action<IEventStoreConnection, Exception> errorOccurred,
- Action<IEventStoreConnection, string> closed,
- Action<IEventStoreConnection, IPEndPoint> connected,
- Action<IEventStoreConnection, IPEndPoint> disconnected,
- Action<IEventStoreConnection> reconnecting,
- Action<IEventStoreConnection, string> authenticationFailed,
bool failOnNoServerResponse,
TimeSpan heartbeatInterval,
TimeSpan heartbeatTimeout,
@@ -178,13 +173,6 @@ public static ConnectionSettingsBuilder Create()
TargetHost = targetHost;
ValidateServer = validateServer;
- ErrorOccurred = errorOccurred;
- Closed = closed;
- Connected = connected;
- Disconnected = disconnected;
- Reconnecting = reconnecting;
- AuthenticationFailed = authenticationFailed;
-
FailOnNoServerResponse = failOnNoServerResponse;
HeartbeatInterval = heartbeatInterval;
HeartbeatTimeout = heartbeatTimeout;
View
134 src/EventStore/EventStore.ClientAPI/ConnectionSettingsBuilder.cs
@@ -24,9 +24,8 @@
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-//
+
using System;
-using System.Net;
using EventStore.ClientAPI.Common.Log;
using EventStore.ClientAPI.Common.Utils;
using EventStore.ClientAPI.SystemData;
@@ -57,13 +56,6 @@ public class ConnectionSettingsBuilder
private string _targetHost;
private bool _validateServer;
- private Action<IEventStoreConnection, Exception> _errorOccurred;
- private Action<IEventStoreConnection, string> _closed;
- private Action<IEventStoreConnection, IPEndPoint> _connected;
- private Action<IEventStoreConnection, IPEndPoint> _disconnected;
- private Action<IEventStoreConnection> _reconnecting;
- private Action<IEventStoreConnection, string> _authenticationFailed;
-
private bool _failOnNoServerResponse;
private TimeSpan _heartbeatInterval = TimeSpan.FromMilliseconds(750);
private TimeSpan _heartbeatTimeout = TimeSpan.FromMilliseconds(1500);
@@ -74,15 +66,6 @@ internal ConnectionSettingsBuilder()
}
/// <summary>
- /// Configures the connection not to output log messages. This is the default.
- /// </summary>
- public ConnectionSettingsBuilder DoNotLog()
- {
- _log = new NoopLogger();
- return this;
- }
-
- /// <summary>
/// Configures the connection to output log messages to the given <see cref="ILogger" />.
/// </summary>
/// <param name="logger">The <see cref="ILogger"/> to use.</param>
@@ -124,16 +107,6 @@ public ConnectionSettingsBuilder EnableVerboseLogging()
}
/// <summary>
- /// Turns off excessive <see cref="EventStoreConnection"/> internal logic logging.
- /// </summary>
- /// <returns></returns>
- public ConnectionSettingsBuilder DisableVerboseLogging()
- {
- _verboseLogging = false;
- return this;
- }
-
- /// <summary>
/// Sets the limit for number of outstanding operations
/// </summary>
/// <param name="limit">The new limit of outstanding operations</param>
@@ -272,7 +245,7 @@ public ConnectionSettingsBuilder SetTimeoutCheckPeriodTo(TimeSpan timeoutCheckPe
}
/// <summary>
- /// Sets the default <see cref="UserCredentials"> to be used for this connection.
+ /// Sets the default <see cref="UserCredentials"/> to be used for this connection.
/// If user credentials are not given for an operation, these credentials will be used.
/// </summary>
/// <param name="userCredentials"></param>
@@ -299,87 +272,6 @@ public ConnectionSettingsBuilder UseSslConnection(string targetHost, bool valida
}
/// <summary>
- /// Use an unencrypted TCP connection. This should generally not be used with authentication
- /// as it will send usernames and passwords over the network as plaintext.
- /// </summary>
- /// <returns></returns>
- public ConnectionSettingsBuilder UseNormalConnection()
- {
- _useSslConnection = false;
- _targetHost = null;
- _validateServer = true;
- return this;
- }
-
- /// <summary>
- /// Sets handler of internal connection errors.
- /// </summary>
- /// <param name="handler"></param>
- /// <returns></returns>
- public ConnectionSettingsBuilder OnErrorOccurred(Action<IEventStoreConnection, Exception> handler)
- {
- _errorOccurred = handler;
- return this;
- }
-
- /// <summary>
- /// Sets handler of <see cref="EventStoreConnection"/> closing. For all disconnections
- /// use the OnDisconnected handler.
- /// </summary>
- /// <param name="handler"></param>
- /// <returns></returns>
- public ConnectionSettingsBuilder OnClosed(Action<IEventStoreConnection, string> handler)
- {
- _closed = handler;
- return this;
- }
-
- /// <summary>
- /// Sets handler called when connection is established.
- /// </summary>
- /// <param name="handler"></param>
- /// <returns></returns>
- public ConnectionSettingsBuilder OnConnected(Action<IEventStoreConnection, IPEndPoint> handler)
- {
- _connected = handler;
- return this;
- }
-
- /// <summary>
- /// Sets handler called when connection is dropped.
- /// This happens on all disconnections. Closed in when the connection is explicitly closed.
- /// </summary>
- /// <param name="handler"></param>
- /// <returns></returns>
- public ConnectionSettingsBuilder OnDisconnected(Action<IEventStoreConnection, IPEndPoint> handler)
- {
- _disconnected = handler;
- return this;
- }
-
- /// <summary>
- /// Sets handler called when reconnection attempt is made.
- /// </summary>
- /// <param name="handler"></param>
- /// <returns></returns>
- public ConnectionSettingsBuilder OnReconnecting(Action<IEventStoreConnection> handler)
- {
- _reconnecting = handler;
- return this;
- }
-
- /// <summary>
- /// Sets handler called when authentication failure occurs.
- /// </summary>
- /// <param name="handler"></param>
- /// <returns></returns>
- public ConnectionSettingsBuilder OnAuthenticationFailed(Action<IEventStoreConnection, string> handler)
- {
- _authenticationFailed = handler;
- return this;
- }
-
- /// <summary>
/// Marks that no response from server should cause an error on the request
/// </summary>
/// <returns></returns>
@@ -390,16 +282,6 @@ public ConnectionSettingsBuilder FailOnNoServerResponse()
}
/// <summary>
- /// Marks that no response from server for request should result in a retry
- /// </summary>
- /// <returns></returns>
- public ConnectionSettingsBuilder DoNotFailOnNoServerResponse()
- {
- _failOnNoServerResponse = false;
- return this;
- }
-
- /// <summary>
/// Sets how often heartbeats should be expected on the connection (lower values detect broken sockets faster)
/// </summary>
/// <param name="interval"></param>
@@ -432,6 +314,12 @@ public ConnectionSettingsBuilder WithConnectionTimeoutOf(TimeSpan timeout)
return this;
}
+ /// <summary>
+ /// Convert the mutable <see cref="ConnectionSettingsBuilder"/> object to an immutable
+ /// <see cref="ConnectionSettings"/> object.
+ /// </summary>
+ /// <param name="builder">The <see cref="ConnectionSettingsBuilder"/> to convert.</param>
+ /// <returns>An immutable <see cref="ConnectionSettings"/> object with the values specified by the builder.</returns>
public static implicit operator ConnectionSettings(ConnectionSettingsBuilder builder)
{
return new ConnectionSettings(builder._log,
@@ -448,12 +336,6 @@ public ConnectionSettingsBuilder WithConnectionTimeoutOf(TimeSpan timeout)
builder._useSslConnection,
builder._targetHost,
builder._validateServer,
- builder._errorOccurred,
- builder._closed,
- builder._connected,
- builder._disconnected,
- builder._reconnecting,
- builder._authenticationFailed,
builder._failOnNoServerResponse,
builder._heartbeatInterval,
builder._heartbeatTimeout,
View
72 src/EventStore/EventStore.ClientAPI/Core/EventStoreConnectionLogicHandler.cs
@@ -46,6 +46,7 @@ internal class EventStoreConnectionLogicHandler
private readonly IEventStoreConnection _esConnection;
private readonly ConnectionSettings _settings;
+
private readonly SimpleQueuedHandler _queue = new SimpleQueuedHandler();
private readonly Timer _timer;
private IEndPointDiscoverer _endPointDiscoverer;
@@ -60,6 +61,7 @@ internal class EventStoreConnectionLogicHandler
private ConnectionState _state = ConnectionState.Init;
private ConnectingPhase _connectingPhase = ConnectingPhase.Invalid;
+ private int _wasConnected;
private int _packageNumber;
private TcpPackageConnection _connection;
@@ -79,7 +81,7 @@ public EventStoreConnectionLogicHandler(IEventStoreConnection esConnection, Conn
_queue.RegisterHandler<CloseConnectionMessage>(msg => CloseConnection(msg.Reason, msg.Exception));
_queue.RegisterHandler<StartOperationMessage>(msg => StartOperation(msg.Operation, msg.MaxRetries, msg.Timeout));
- _queue.RegisterHandler<StartSubscriptionMessage>(msg => StartSubscription(msg));
+ _queue.RegisterHandler<StartSubscriptionMessage>(StartSubscription);
_queue.RegisterHandler<EstablishTcpConnectionMessage>(msg => EstablishTcpConnection(msg.EndPoints));
_queue.RegisterHandler<TcpConnectionEstablishedMessage>(msg => TcpConnectionEstablished(msg.Connection));
@@ -211,13 +213,12 @@ private void CloseConnection(string reason, Exception exception = null)
_subscriptions.CleanUp();
CloseTcpConnection(reason);
- LogInfo("closed. Reason: {0}.", reason);
+ LogInfo("Closed. Reason: {0}.", reason);
- if (exception != null && _settings.ErrorOccurred != null)
- _settings.ErrorOccurred(_esConnection, exception);
+ if (exception != null)
+ RaiseErrorOccurred(exception);
- if (_settings.Closed != null)
- _settings.Closed(_esConnection, reason);
+ RaiseClosed(reason);
}
private void CloseTcpConnection(string reason)
@@ -253,8 +254,10 @@ private void TcpConnectionClosed(TcpPackageConnection connection)
_subscriptions.PurgeSubscribedAndDroppedSubscriptions(_connection.ConnectionId);
_reconnInfo = new ReconnectionInfo(_reconnInfo.ReconnectionAttempt, _stopwatch.Elapsed);
- if (_settings.Disconnected != null)
- _settings.Disconnected(_esConnection, connection.RemoteEndPoint);
+ if (Interlocked.CompareExchange(ref _wasConnected, 0, 1) == 1)
+ {
+ RaiseDisconnected(connection.RemoteEndPoint);
+ }
}
private void TcpConnectionEstablished(TcpPackageConnection connection)
@@ -295,8 +298,9 @@ private void GoToConnectedState()
_state = ConnectionState.Connected;
_connectingPhase = ConnectingPhase.Connected;
- if (_settings.Connected != null)
- _settings.Connected(_esConnection, _connection.RemoteEndPoint);
+ Interlocked.CompareExchange(ref _wasConnected, 1, 0);
+
+ RaiseConnectedEvent(_connection.RemoteEndPoint);
if (_stopwatch.Elapsed - _lastTimeoutsTimeStamp >= _settings.OperationTimeoutCheckPeriod)
{
@@ -322,15 +326,13 @@ private void TimerTick()
CloseConnection("Reconnection limit reached.");
else
{
- if (_settings.Reconnecting != null)
- _settings.Reconnecting(_esConnection);
+ RaiseReconnecting();
DiscoverEndPoint(null);
}
}
if (_connectingPhase == ConnectingPhase.Authentication && _stopwatch.Elapsed - _authInfo.TimeStamp >= _settings.OperationTimeout)
{
- if (_settings.AuthenticationFailed != null)
- _settings.AuthenticationFailed(_esConnection, "Authentication timed out.");
+ RaiseAuthenticationFailed("Authentication timed out.");
GoToConnectedState();
}
if (_connectingPhase > ConnectingPhase.ConnectionEstablishing)
@@ -463,8 +465,9 @@ private void HandleTcpPackage(TcpPackageConnection connection, TcpPackage packag
&& _connectingPhase == ConnectingPhase.Authentication
&& _authInfo.CorrelationId == package.CorrelationId)
{
- if (package.Command == TcpCommand.NotAuthenticated && _settings.AuthenticationFailed != null)
- _settings.AuthenticationFailed(_esConnection, "Not authenticated");
+ if (package.Command == TcpCommand.NotAuthenticated)
+ RaiseAuthenticationFailed("Not authenticated");
+
GoToConnectedState();
return;
}
@@ -566,6 +569,43 @@ private void LogInfo(string message, params object[] parameters)
if (_settings.VerboseLogging) _settings.Log.Info("EventStoreConnection '{0}': {1}.", _esConnection.ConnectionName, parameters.Length == 0 ? message : string.Format(message, parameters));
}
+ private void RaiseConnectedEvent(IPEndPoint remoteEndPoint)
+ {
+ Connected(_esConnection, new ClientConnectionEventArgs(_esConnection, remoteEndPoint));
+ }
+
+ private void RaiseDisconnected(IPEndPoint remoteEndPoint)
+ {
+ Disconnected(_esConnection, new ClientConnectionEventArgs(_esConnection, remoteEndPoint));
+ }
+
+ private void RaiseClosed(string reason)
+ {
+ Closed(_esConnection, new ClientClosedEventArgs(_esConnection, reason));
+ }
+
+ private void RaiseErrorOccurred(Exception exception)
+ {
+ ErrorOccurred(_esConnection, new ClientErrorEventArgs(_esConnection, exception));
+ }
+
+ private void RaiseReconnecting()
+ {
+ Reconnecting(_esConnection, new ClientReconnectingEventArgs(_esConnection));
+ }
+
+ private void RaiseAuthenticationFailed(string reason)
+ {
+ AuthenticationFailed(_esConnection, new ClientAuthenticationFailedEventArgs(_esConnection, reason));
+ }
+
+ public event EventHandler<ClientConnectionEventArgs> Connected = delegate { };
+ public event EventHandler<ClientConnectionEventArgs> Disconnected = delegate { };
+ public event EventHandler<ClientReconnectingEventArgs> Reconnecting = delegate { };
+ public event EventHandler<ClientClosedEventArgs> Closed = delegate { };
+ public event EventHandler<ClientErrorEventArgs> ErrorOccurred = delegate { };
+ public event EventHandler<ClientAuthenticationFailedEventArgs> AuthenticationFailed = delegate { };
+
private struct HeartbeatInfo
{
public readonly int LastPackageNumber;
View
6 src/EventStore/EventStore.ClientAPI/EventStore.ClientAPI.csproj
@@ -83,6 +83,8 @@
</ItemGroup>
<ItemGroup>
<Compile Include="AllEventsSlice.cs" />
+ <Compile Include="ClientAuthenticationFailedEventArgs.cs" />
+ <Compile Include="ClientErrorEventArgs.cs" />
<Compile Include="ClientOperations\CommitTransactionOperation.cs" />
<Compile Include="ClientOperations\ReadEventOperation.cs" />
<Compile Include="ClientOperations\SubscriptionOperation.cs" />
@@ -92,6 +94,7 @@
<Compile Include="ClientOperations\ReadStreamEventsBackwardOperation.cs" />
<Compile Include="ClientOperations\StartTransactionOperation.cs" />
<Compile Include="ClientOperations\TransactionalWriteOperation.cs" />
+ <Compile Include="ClientReconnectingEventArgs.cs" />
<Compile Include="Common\Concurrent\ConcurrentQueue.cs" />
<Compile Include="Common\Concurrent\ConcurrentStack.cs" />
<Compile Include="Common\Log\ConsoleLogger.cs" />
@@ -101,10 +104,12 @@
<Compile Include="Common\SystemNames.cs" />
<Compile Include="Common\Utils\Helper.cs" />
<Compile Include="Common\Utils\Json.cs" />
+ <Compile Include="ClientClosedEventArgs.cs" />
<Compile Include="ConnectionSettings.cs" />
<Compile Include="ConnectionSettingsBuilder.cs" />
<Compile Include="ClusterSettings.cs" />
<Compile Include="ClusterSettingsBuilder.cs" />
+ <Compile Include="ClientConnectionEventArgs.cs" />
<Compile Include="WriteResult.cs" />
<Compile Include="SystemSettings.cs" />
<Compile Include="EventReadResult.cs" />
@@ -113,7 +118,6 @@
<Compile Include="Core\OperationsManager.cs" />
<Compile Include="Core\StaticEndPointDiscoverer.cs" />
<Compile Include="Core\SubscriptionsManager.cs" />
- <Compile Include="EventStoreClusterConnection.cs" />
<Compile Include="EventStoreNodeConnection.cs" />
<Compile Include="Exceptions\ClusterException.cs" />
<Compile Include="Exceptions\NotAuthenticatedException.cs" />
View
321 src/EventStore/EventStore.ClientAPI/EventStoreClusterConnection.cs
@@ -1,321 +0,0 @@
-// Copyright (c) 2012, Event Store LLP
-// All rights reserved.
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are
-// met:
-//
-// Redistributions of source code must retain the above copyright notice,
-// this list of conditions and the following disclaimer.
-// Redistributions in binary form must reproduce the above copyright
-// notice, this list of conditions and the following disclaimer in the
-// documentation and/or other materials provided with the distribution.
-// Neither the name of the Event Store LLP nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-// HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-//
-
-using System;
-using System.Collections.Generic;
-using System.Threading.Tasks;
-using EventStore.ClientAPI.Core;
-using EventStore.ClientAPI.SystemData;
-
-namespace EventStore.ClientAPI
-{
- /// <summary>
- /// Maintains a full duplex connection to the EventStore cluster
- /// </summary>
- internal class EventStoreClusterConnection: IEventStoreConnection, IEventStoreTransactionConnection
- {
- public string ConnectionName { get { return _conn.ConnectionName; } }
-
- private readonly EventStoreNodeConnection _conn;
-
- internal EventStoreClusterConnection(ConnectionSettings connectionSettings,
- ClusterSettings clusterSettings,
- string connectionName)
- {
-
- var endPointDiscoverer = new ClusterDnsEndPointDiscoverer(connectionSettings.Log,
- clusterSettings.ClusterDns,
- clusterSettings.MaxDiscoverAttempts,
- clusterSettings.ManagerExternalHttpPort,
- clusterSettings.GossipSeeds,
- clusterSettings.GossipTimeout);
- _conn = new EventStoreNodeConnection(connectionSettings, endPointDiscoverer, connectionName);
- }
-
- public void Connect()
- {
- _conn.Connect();
- }
-
- public Task ConnectAsync()
- {
- return _conn.ConnectAsync();
- }
-
- public void Dispose()
- {
- Close();
- }
-
- public void Close()
- {
- _conn.Close();
- }
-
- public void DeleteStream(string stream, int expectedVersion, UserCredentials userCredentials = null)
- {
- _conn.DeleteStream(stream, expectedVersion, userCredentials);
- }
-
- public void DeleteStream(string stream, int expectedVersion, bool hardDelete, UserCredentials userCredentials = null)
- {
- _conn.DeleteStream(stream, expectedVersion, hardDelete, userCredentials);
- }
-
- public Task DeleteStreamAsync(string stream, int expectedVersion, UserCredentials userCredentials = null)
- {
- return _conn.DeleteStreamAsync(stream, expectedVersion, userCredentials);
- }
-
- public Task DeleteStreamAsync(string stream, int expectedVersion, bool hardDelete, UserCredentials userCredentials = null)
- {
- return _conn.DeleteStreamAsync(stream, expectedVersion, hardDelete, userCredentials);
- }
-
- public WriteResult AppendToStream(string stream, int expectedVersion, params EventData[] events)
- {
- return _conn.AppendToStream(stream, expectedVersion, events);
- }
-
- public WriteResult AppendToStream(string stream, int expectedVersion, UserCredentials userCredentials, params EventData[] events)
- {
- return _conn.AppendToStream(stream, expectedVersion, userCredentials, events);
- }
-
- public WriteResult AppendToStream(string stream, int expectedVersion, IEnumerable<EventData> events, UserCredentials userCredentials = null)
- {
- return _conn.AppendToStream(stream, expectedVersion, events, userCredentials);
- }
-
- public Task<WriteResult> AppendToStreamAsync(string stream, int expectedVersion, params EventData[] events)
- {
- return _conn.AppendToStreamAsync(stream, expectedVersion, events);
- }
-
- public Task<WriteResult> AppendToStreamAsync(string stream, int expectedVersion, UserCredentials userCredentials, params EventData[] events)
- {
- return _conn.AppendToStreamAsync(stream, expectedVersion, userCredentials, events);
- }
-
- public Task<WriteResult> AppendToStreamAsync(string stream, int expectedVersion, IEnumerable<EventData> events, UserCredentials userCredentials = null)
- {
- return _conn.AppendToStreamAsync(stream, expectedVersion, events, userCredentials);
- }
-
- public EventStoreTransaction StartTransaction(string stream, int expectedVersion, UserCredentials userCredentials = null)
- {
- return _conn.StartTransaction(stream, expectedVersion, userCredentials);
- }
-
- public Task<EventStoreTransaction> StartTransactionAsync(string stream, int expectedVersion, UserCredentials userCredentials = null)
- {
- return _conn.StartTransactionAsync(stream, expectedVersion, userCredentials);
- }
-
- public EventStoreTransaction ContinueTransaction(long transactionId, UserCredentials userCredentials = null)
- {
- return _conn.ContinueTransaction(transactionId, userCredentials);
- }
-
- public EventReadResult ReadEvent(string stream, int eventNumber, bool resolveLinkTos, UserCredentials userCredentials = null)
- {
- return _conn.ReadEvent(stream, eventNumber, resolveLinkTos, userCredentials);
- }
-
- public Task<EventReadResult> ReadEventAsync(string stream, int eventNumber, bool resolveLinkTos, UserCredentials userCredentials = null)
- {
- return _conn.ReadEventAsync(stream, eventNumber, resolveLinkTos, userCredentials);
- }
-
- public Task TransactionalWriteAsync(EventStoreTransaction transaction, IEnumerable<EventData> events, UserCredentials userCredentials = null)
- {
- return ((IEventStoreTransactionConnection)_conn).TransactionalWriteAsync(transaction, events, userCredentials);
- }
-
- public Task<WriteResult> CommitTransactionAsync(EventStoreTransaction transaction, UserCredentials userCredentials = null)
- {
- return ((IEventStoreTransactionConnection)_conn).CommitTransactionAsync(transaction, userCredentials);
- }
-
- public StreamEventsSlice ReadStreamEventsForward(string stream, int start, int count, bool resolveLinkTos, UserCredentials userCredentials = null)
- {
- return _conn.ReadStreamEventsForward(stream, start, count, resolveLinkTos, userCredentials);
- }
-
- public Task<StreamEventsSlice> ReadStreamEventsForwardAsync(string stream, int start, int count, bool resolveLinkTos, UserCredentials userCredentials = null)
- {
- return _conn.ReadStreamEventsForwardAsync(stream, start, count, resolveLinkTos, userCredentials);
- }
-
- public StreamEventsSlice ReadStreamEventsBackward(string stream, int start, int count, bool resolveLinkTos, UserCredentials userCredentials = null)
- {
- return _conn.ReadStreamEventsBackward(stream, start, count, resolveLinkTos, userCredentials);
- }
-
- public Task<StreamEventsSlice> ReadStreamEventsBackwardAsync(string stream, int start, int count, bool resolveLinkTos, UserCredentials userCredentials = null)
- {
- return _conn.ReadStreamEventsBackwardAsync(stream, start, count, resolveLinkTos, userCredentials);
- }
-
- public AllEventsSlice ReadAllEventsForward(Position position, int maxCount, bool resolveLinkTos, UserCredentials userCredentials = null)
- {
- return _conn.ReadAllEventsForward(position, maxCount, resolveLinkTos, userCredentials);
- }
-
- public Task<AllEventsSlice> ReadAllEventsForwardAsync(Position position, int maxCount, bool resolveLinkTos, UserCredentials userCredentials = null)
- {
- return _conn.ReadAllEventsForwardAsync(position, maxCount, resolveLinkTos, userCredentials);
- }
-
- public AllEventsSlice ReadAllEventsBackward(Position position, int maxCount, bool resolveLinkTos, UserCredentials userCredentials = null)
- {
- return _conn.ReadAllEventsBackward(position, maxCount, resolveLinkTos, userCredentials);
- }
-
- public Task<AllEventsSlice> ReadAllEventsBackwardAsync(Position position, int maxCount, bool resolveLinkTos, UserCredentials userCredentials = null)
- {
- return _conn.ReadAllEventsBackwardAsync(position, maxCount, resolveLinkTos, userCredentials);
- }
-
- public EventStoreSubscription SubscribeToStream(
- string stream,
- bool resolveLinkTos,
- Action<EventStoreSubscription, ResolvedEvent> eventAppeared,
- Action<EventStoreSubscription, SubscriptionDropReason, Exception> subscriptionDropped = null,
- UserCredentials userCredentials = null)
- {
- return _conn.SubscribeToStream(stream, resolveLinkTos, eventAppeared, subscriptionDropped, userCredentials);
- }
-
- public Task<EventStoreSubscription> SubscribeToStreamAsync(
- string stream,
- bool resolveLinkTos,
- Action<EventStoreSubscription, ResolvedEvent> eventAppeared,
- Action<EventStoreSubscription, SubscriptionDropReason, Exception> subscriptionDropped = null,
- UserCredentials userCredentials = null)
- {
- return _conn.SubscribeToStreamAsync(stream, resolveLinkTos, eventAppeared, subscriptionDropped, userCredentials);
- }
-
- public EventStoreStreamCatchUpSubscription SubscribeToStreamFrom(
- string stream,
- int? fromEventNumberExclusive,
- bool resolveLinkTos,
- Action<EventStoreCatchUpSubscription, ResolvedEvent> eventAppeared,
- Action<EventStoreCatchUpSubscription> liveProcessingStarted = null,
- Action<EventStoreCatchUpSubscription, SubscriptionDropReason, Exception> subscriptionDropped = null,
- UserCredentials userCredentials = null,
- int readBatchSize = 500)
- {
- return _conn.SubscribeToStreamFrom(stream, fromEventNumberExclusive, resolveLinkTos,
- eventAppeared, liveProcessingStarted,
- subscriptionDropped, userCredentials, readBatchSize);
- }
-
- public EventStoreSubscription SubscribeToAll(
- bool resolveLinkTos,
- Action<EventStoreSubscription, ResolvedEvent> eventAppeared,
- Action<EventStoreSubscription, SubscriptionDropReason, Exception> subscriptionDropped = null,
- UserCredentials userCredentials = null)
- {
- return _conn.SubscribeToAll(resolveLinkTos, eventAppeared, subscriptionDropped, userCredentials);
- }
-
- public Task<EventStoreSubscription> SubscribeToAllAsync(
- bool resolveLinkTos,
- Action<EventStoreSubscription, ResolvedEvent> eventAppeared,
- Action<EventStoreSubscription, SubscriptionDropReason, Exception> subscriptionDropped = null,
- UserCredentials userCredentials = null)
- {
- return _conn.SubscribeToAllAsync(resolveLinkTos, eventAppeared, subscriptionDropped, userCredentials);
- }
-
- public EventStoreAllCatchUpSubscription SubscribeToAllFrom(
- Position? fromPositionExclusive,
- bool resolveLinkTos,
- Action<EventStoreCatchUpSubscription, ResolvedEvent> eventAppeared,
- Action<EventStoreCatchUpSubscription> liveProcessingStarted = null,
- Action<EventStoreCatchUpSubscription, SubscriptionDropReason, Exception> subscriptionDropped = null,
- UserCredentials userCredentials = null,
- int readBatchSize = 500)
- {
- return _conn.SubscribeToAllFrom(fromPositionExclusive, resolveLinkTos,
- eventAppeared, liveProcessingStarted, subscriptionDropped, userCredentials, readBatchSize);
- }
-
- public WriteResult SetStreamMetadata(string stream, int expectedMetastreamVersion, StreamMetadata metadata, UserCredentials userCredentials = null)
- {
- return _conn.SetStreamMetadata(stream, expectedMetastreamVersion, metadata, userCredentials);
- }
-
- public Task<WriteResult> SetStreamMetadataAsync(string stream, int expectedMetastreamVersion, StreamMetadata metadata, UserCredentials userCredentials = null)
- {
- return _conn.SetStreamMetadataAsync(stream, expectedMetastreamVersion, metadata, userCredentials);
- }
-
- public WriteResult SetStreamMetadata(string stream, int expectedMetastreamVersion, byte[] metadata, UserCredentials userCredentials = null)
- {
- return _conn.SetStreamMetadata(stream, expectedMetastreamVersion, metadata, userCredentials);
- }
-
- public Task<WriteResult> SetStreamMetadataAsync(string stream, int expectedMetastreamVersion, byte[] metadata, UserCredentials userCredentials = null)
- {
- return _conn.SetStreamMetadataAsync(stream, expectedMetastreamVersion, metadata, userCredentials);
- }
-
- public StreamMetadataResult GetStreamMetadata(string stream, UserCredentials userCredentials = null)
- {
- return _conn.GetStreamMetadata(stream, userCredentials);
- }
-
- public Task<StreamMetadataResult> GetStreamMetadataAsync(string stream, UserCredentials userCredentials = null)
- {
- return _conn.GetStreamMetadataAsync(stream, userCredentials);
- }
-
- public RawStreamMetadataResult GetStreamMetadataAsRawBytes(string stream, UserCredentials userCredentials = null)
- {
- return _conn.GetStreamMetadataAsRawBytes(stream, userCredentials);
- }
-
- public Task<RawStreamMetadataResult> GetStreamMetadataAsRawBytesAsync(string stream, UserCredentials userCredentials = null)
- {
- return _conn.GetStreamMetadataAsRawBytesAsync(stream, userCredentials);
- }
-
- public void SetSystemSettings(SystemSettings settings, UserCredentials userCredentials = null)
- {
- _conn.SetSystemSettings(settings, userCredentials);
- }
-
- public Task SetSystemSettingsAsync(SystemSettings settings, UserCredentials userCredentials = null)
- {
- return _conn.SetSystemSettingsAsync(settings, userCredentials);
- }
- }
-}
View
13 src/EventStore/EventStore.ClientAPI/EventStoreConnection.cs
@@ -32,6 +32,9 @@
namespace EventStore.ClientAPI
{
+ /// <summary>
+ /// Contains factory methods for building connections to an Event Store server.
+ /// </summary>
public static class EventStoreConnection
{
/// <summary>
@@ -71,7 +74,15 @@ public static IEventStoreConnection Create(ConnectionSettings connectionSettings
{
Ensure.NotNull(connectionSettings, "connectionSettings");
Ensure.NotNull(clusterSettings, "clusterSettings");
- return new EventStoreClusterConnection(connectionSettings, clusterSettings, connectionName);
+
+ var endPointDiscoverer = new ClusterDnsEndPointDiscoverer(connectionSettings.Log,
+ clusterSettings.ClusterDns,
+ clusterSettings.MaxDiscoverAttempts,
+ clusterSettings.ManagerExternalHttpPort,
+ clusterSettings.GossipSeeds,
+ clusterSettings.GossipTimeout);
+
+ return new EventStoreNodeConnection(connectionSettings, endPointDiscoverer, connectionName);
}
}
}
View
72 src/EventStore/EventStore.ClientAPI/EventStoreNodeConnection.cs
@@ -24,7 +24,6 @@
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-//
using System;
using System.Collections.Generic;
@@ -495,5 +494,76 @@ public Task SetSystemSettingsAsync(SystemSettings settings, UserCredentials user
return AppendToStreamAsync(SystemStreams.SettingsStream, ExpectedVersion.Any, userCredentials,
new EventData(Guid.NewGuid(), SystemEventTypes.Settings, true, settings.ToJsonBytes(), null));
}
+
+ public event EventHandler<ClientConnectionEventArgs> Connected
+ {
+ add
+ {
+ _handler.Connected += value;
+ }
+ remove
+ {
+ _handler.Connected -= value;
+ }
+ }
+
+ public event EventHandler<ClientConnectionEventArgs> Disconnected
+ {
+ add
+ {
+ _handler.Disconnected += value;
+ }
+ remove
+ {
+ _handler.Disconnected -= value;
+ }
+ }
+
+ public event EventHandler<ClientReconnectingEventArgs> Reconnecting
+ {
+ add
+ {
+ _handler.Reconnecting += value;
+ }
+ remove
+ {
+ _handler.Reconnecting -= value;
+ }
+ }
+
+ public event EventHandler<ClientClosedEventArgs> Closed
+ {
+ add
+ {
+ _handler.Closed += value;
+ }
+ remove
+ {
+ _handler.Closed -= value;
+ }
+ }
+
+ public event EventHandler<ClientErrorEventArgs> ErrorOccurred
+ {
+ add
+ {
+ _handler.ErrorOccurred += value;
+ }
+ remove
+ {
+ _handler.ErrorOccurred -= value;
+ }
+ }
+ public event EventHandler<ClientAuthenticationFailedEventArgs> AuthenticationFailed
+ {
+ add
+ {
+ _handler.AuthenticationFailed += value;
+ }
+ remove
+ {
+ _handler.AuthenticationFailed -= value;
+ }
+ }
}
}
View
37 src/EventStore/EventStore.ClientAPI/IEventStoreConnection.cs
@@ -50,6 +50,10 @@ namespace EventStore.ClientAPI
/// </remarks>
public interface IEventStoreConnection : IDisposable
{
+ /// <summary>
+ /// Gets the name of this connection. A connection name can be used for disambiguation
+ /// in log files.
+ /// </summary>
string ConnectionName { get; }
/// <summary>
@@ -427,5 +431,38 @@ public interface IEventStoreConnection : IDisposable
void SetSystemSettings(SystemSettings settings, UserCredentials userCredentials = null);
Task SetSystemSettingsAsync(SystemSettings settings, UserCredentials userCredentials = null);
+
+ /// <summary>
+ /// Fired when an <see cref="IEventStoreConnection"/> connects to an Event Store server.
+ /// </summary>
+ event EventHandler<ClientConnectionEventArgs> Connected;
+
+ /// <summary>
+ /// Fired when an <see cref="IEventStoreConnection"/> is disconnected from an Event Store server
+ /// by some means other than by calling the <see cref="Close"/> method.
+ /// </summary>
+ event EventHandler<ClientConnectionEventArgs> Disconnected;
+
+ /// <summary>
+ /// Fired when an <see cref="IEventStoreConnection"/> is attempting to reconnect to an Event Store
+ /// server following a disconnection.
+ /// </summary>
+ event EventHandler<ClientReconnectingEventArgs> Reconnecting;
+
+ /// <summary>
+ /// Fired when an <see cref="IEventStoreConnection"/> is closed either using the <see cref="Close"/>
+ /// method, or when reconnection limits are reached without a successful connection being established.
+ /// </summary>
+ event EventHandler<ClientClosedEventArgs> Closed;
+
+ /// <summary>
+ /// Fired when an error is thrown on an <see cref="IEventStoreConnection"/>.
+ /// </summary>
+ event EventHandler<ClientErrorEventArgs> ErrorOccurred;
+
+ /// <summary>
+ /// Fired when a client fails to authenticate to an Event Store server.
+ /// </summary>
+ event EventHandler<ClientAuthenticationFailedEventArgs> AuthenticationFailed;
}
}
View
1  src/EventStore/EventStore.Core.Tests/ClientAPI/Helpers/TestConnection.cs
@@ -59,7 +59,6 @@ private static ConnectionSettingsBuilder Settings(TcpType tcpType, UserCredentia
.SetDefaultUserCredentials(userCredentials)
.UseCustomLogger(ClientApiLoggerBridge.Default)
.EnableVerboseLogging()
- //.DisableVerboseLogging()
.LimitReconnectionsTo(10)
.LimitRetriesForOperationTo(100)
.SetTimeoutCheckPeriodTo(TimeSpan.FromMilliseconds(100))
View
27 src/EventStore/EventStore.Core.Tests/ClientAPI/connect.cs
@@ -74,7 +74,6 @@ public void should_throw_exception_when_trying_to_reopen_closed_connection()
.UseCustomLogger(ClientApiLoggerBridge.Default)
.LimitReconnectionsTo(0)
.SetReconnectionDelayTo(TimeSpan.FromMilliseconds(0))
- .OnClosed((x, r) => closed.Set())
.FailOnNoServerResponse();
if (_tcpType == TcpType.Ssl)
settings.UseSslConnection("ES", false);
@@ -85,6 +84,8 @@ public void should_throw_exception_when_trying_to_reopen_closed_connection()
{
using (var connection = EventStoreConnection.Create(settings, new IPEndPoint(ip, port)))
{
+ connection.Closed += (s, e) => closed.Set();
+
connection.Connect();
if (!closed.Wait(TimeSpan.FromSeconds(120))) // TCP connection timeout might be even 60 seconds
@@ -111,11 +112,6 @@ public void should_close_connection_after_configured_amount_of_failed_reconnecti
.UseCustomLogger(ClientApiLoggerBridge.Default)
.LimitReconnectionsTo(1)
.SetReconnectionDelayTo(TimeSpan.FromMilliseconds(0))
- .OnClosed((x, r) => closed.Set())
- .OnConnected((x, ep) => Console.WriteLine("EventStoreConnection '{0}': connected to [{1}]...", x.ConnectionName, ep))
- .OnReconnecting(x => Console.WriteLine("EventStoreConnection '{0}': reconnecting...", x.ConnectionName))
- .OnDisconnected((x, ep) => Console.WriteLine("EventStoreConnection '{0}': disconnected from [{1}]...", x.ConnectionName, ep))
- .OnErrorOccurred((x, exc) => Console.WriteLine("EventStoreConnection '{0}': error = {1}", x.ConnectionName, exc))
.FailOnNoServerResponse();
if (_tcpType == TcpType.Ssl)
settings.UseSslConnection("ES", false);
@@ -126,7 +122,11 @@ public void should_close_connection_after_configured_amount_of_failed_reconnecti
{
using (var connection = EventStoreConnection.Create(settings, new IPEndPoint(ip, port)))
{
- connection.Connect();
+ connection.Closed += (s, e) => closed.Set();
+ connection.Connected += (s, e) => Console.WriteLine("EventStoreConnection '{0}': connected to [{1}]...", e.Connection.ConnectionName, e.RemoteEndPoint);
+ connection.Reconnecting += (s, e) => Console.WriteLine("EventStoreConnection '{0}': reconnecting...", e.Connection.ConnectionName);
+ connection.Disconnected += (s, e) => Console.WriteLine("EventStoreConnection '{0}': disconnected from [{1}]...", e.Connection.ConnectionName, e.RemoteEndPoint);
+ connection.ErrorOccurred += (s, e) => Console.WriteLine("EventStoreConnection '{0}': error = {1}", e.Connection.ConnectionName, e.Exception); connection.Connect();
if (!closed.Wait(TimeSpan.FromSeconds(120))) // TCP connection timeout might be even 60 seconds
Assert.Fail("Connection timeout took too long.");
@@ -160,20 +160,21 @@ public void should_timeout_connection_after_configured_amount_time_on_conenct()
.UseCustomLogger(ClientApiLoggerBridge.Default)
.LimitReconnectionsTo(0)
.SetReconnectionDelayTo(TimeSpan.FromMilliseconds(0))
- .OnClosed((x, r) => closed.Set())
- .OnConnected((x, ep) => Console.WriteLine("EventStoreConnection '{0}': connected to [{1}]...", x.ConnectionName, ep))
- .OnReconnecting(x => Console.WriteLine("EventStoreConnection '{0}': reconnecting...", x.ConnectionName))
- .OnDisconnected((x, ep) => Console.WriteLine("EventStoreConnection '{0}': disconnected from [{1}]...", x.ConnectionName, ep))
- .OnErrorOccurred((x, exc) => Console.WriteLine("EventStoreConnection '{0}': error = {1}", x.ConnectionName, exc))
.FailOnNoServerResponse()
.WithConnectionTimeoutOf(TimeSpan.FromMilliseconds(1000));
+
if (_tcpType == TcpType.Ssl)
settings.UseSslConnection("ES", false);
var ip = new IPAddress(new byte[] {8, 8, 8, 8}); //NOTE: This relies on Google DNS server being configured to swallow nonsense traffic
- int port = 4567;
+ const int port = 4567;
using (var connection = EventStoreConnection.Create(settings, new IPEndPoint(ip, port)))
{
+ connection.Closed += (s, e) => closed.Set();
+ connection.Connected += (s, e) => Console.WriteLine("EventStoreConnection '{0}': connected to [{1}]...", e.Connection.ConnectionName, e.RemoteEndPoint);
+ connection.Reconnecting += (s, e) => Console.WriteLine("EventStoreConnection '{0}': reconnecting...", e.Connection.ConnectionName);
+ connection.Disconnected += (s, e) => Console.WriteLine("EventStoreConnection '{0}': disconnected from [{1}]...", e.Connection.ConnectionName, e.RemoteEndPoint);
+ connection.ErrorOccurred += (s, e) => Console.WriteLine("EventStoreConnection '{0}': error = {1}", e.Connection.ConnectionName, e.Exception);
connection.Connect();
if (!closed.Wait(TimeSpan.FromSeconds(5)))
View
14 src/EventStore/EventStore.TestClient/Commands/RunTestScenarios/ScenarioBase.cs
@@ -24,7 +24,6 @@
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-//
using System;
using System.Collections.Generic;
@@ -160,19 +159,18 @@ public void Run()
{
_connections[i] = EventStoreConnection.Create(
ConnectionSettings.Create()
- .DisableVerboseLogging()
.UseCustomLogger(ApiLogger)
.LimitConcurrentOperationsTo(MaxConcurrentRequests)
.LimitRetriesForOperationTo(maxReconnections)
.LimitReconnectionsTo(maxOperationRetries)
- .FailOnNoServerResponse()
- .OnClosed((c, s) => Log.Debug("[SCENARIO] {0} closed.", c.ConnectionName))
- .OnConnected((c, ep) => Log.Debug("[SCENARIO] {0} connected to [{1}].", c.ConnectionName, ep))
- .OnDisconnected((c, ep) => Log.Debug("[SCENARIO] {0} disconnected from [{1}].", c.ConnectionName, ep))
- .OnErrorOccurred((c, e) => Log.DebugException(e, "[SCENARIO] {0} error occurred.", c.ConnectionName))
- .OnReconnecting(c => Log.Debug("[SCENARIO] {0} reconnecting.", c.ConnectionName)),
+ .FailOnNoServerResponse(),
new IPEndPoint(_nodeConnection.IpAddress, _nodeConnection.TcpPort),
string.Format("ESConn-{0}", i));
+ _connections[i].Closed += (s, e) => Log.Debug("[SCENARIO] {0} closed.", e.Connection.ConnectionName);
+ _connections[i].Connected += (s, e) => Log.Debug("[SCENARIO] {0} connected to [{1}].", e.Connection.ConnectionName, e.RemoteEndPoint);
+ _connections[i].Disconnected += (s, e) => Log.Debug("[SCENARIO] {0} disconnected from [{1}].", e.Connection.ConnectionName, e.RemoteEndPoint);
+ _connections[i].Reconnecting += (s, e) => Log.Debug("[SCENARIO] {0} reconnecting.", e.Connection.ConnectionName);
+ _connections[i].ErrorOccurred += (s, e) => Log.DebugException(e.Exception, "[SCENARIO] {0} error occurred.", e.Connection.ConnectionName);
_connections[i].Connect();
}
RunInternal();
View
4 src/EventStore/EventStore.TestClient/Commands/WriteFloodClientApiProcessor.cs
@@ -90,15 +90,12 @@ private void WriteFlood(CommandProcessorContext context, int clientsCnt, long re
var rnd = new Random();
var settings = ConnectionSettings.Create()
- .DisableVerboseLogging()
.UseConsoleLogger()
.PerformOnAnyNode()
.LimitReconnectionsTo(10)
.LimitRetriesForOperationTo(10)
.LimitOperationsQueueTo(10000)
.LimitConcurrentOperationsTo(context.Client.Options.WriteWindow/clientsCnt)
- .OnClosed((conn, reason) => { })
- .OnErrorOccurred((conn, exc) => context.Fail(exc, "Error on connection."))
.FailOnNoServerResponse();
var client = EventStoreConnection.Create(settings, context.Client.TcpEndpoint);
@@ -106,6 +103,7 @@ private void WriteFlood(CommandProcessorContext context, int clientsCnt, long re
threads.Add(new Thread(_ =>
{
+ client.ErrorOccurred += (s, e) => context.Fail(e.Exception, "Error on connection");
client.Connect();
for (int j = 0; j < count; ++j)
View
5 src/Style.DotSettings
@@ -14,6 +14,9 @@
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/WRAP_BEFORE_FIRST_TYPE_PARAMETER_CONSTRAINT/@EntryValue">True</s:Boolean>
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/WRAP_EXTENDS_LIST_STYLE/@EntryValue">CHOP_IF_LONG</s:String>
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/WRAP_FOR_STMT_HEADER_STYLE/@EntryValue">WRAP_IF_LONG</s:String>
+ <s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/JavaScriptCodeFormatting/ALIGN_MULTIPLE_DECLARATION/@EntryValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/JavaScriptCodeFormatting/JavaScriptFormatOther/ALIGN_MULTIPLE_DECLARATION/@EntryValue">True</s:Boolean>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/EventHandlerPatternLong/@EntryValue">$object$_On$event$</s:String>
- <s:String x:Key="/Default/CodeStyle/Naming/VBNaming/EventHandlerPatternLong/@EntryValue">$object$_On$event$</s:String></wpf:ResourceDictionary>
+ <s:String x:Key="/Default/CodeStyle/Naming/VBNaming/EventHandlerPatternLong/@EntryValue">$object$_On$event$</s:String>
+ <s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EMigrateBlankLinesAroundFieldToBlankLinesAroundProperty/@EntryIndexedValue">True</s:Boolean>
+ <s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002EJavaScript_002ECodeStyle_002ESettingsUpgrade_002EJsCodeFormatterSettingsUpgrader/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
Please sign in to comment.
Something went wrong with that request. Please try again.