Esempio n. 1
0
        public EventStoreConnectionLogicHandler(IEventStoreConnection esConnection, ConnectionSettings settings)
        {
            Ensure.NotNull(esConnection, "esConnection");
            Ensure.NotNull(settings, "settings");

            _esConnection = esConnection;
            _settings     = settings;

            _operations    = new OperationsManager(_esConnection.ConnectionName, settings);
            _subscriptions = new SubscriptionsManager(_esConnection.ConnectionName, settings);

            _queue.RegisterHandler <StartConnectionMessage>(msg => StartConnection(msg.Task, msg.EndPointDiscoverer));
            _queue.RegisterHandler <CloseConnectionMessage>(msg => CloseConnection(msg.Reason, msg.Exception));

            _queue.RegisterHandler <StartOperationMessage>(msg => StartOperation(msg.Operation, msg.MaxRetries, msg.Timeout));
            _queue.RegisterHandler <StartSubscriptionMessage>(StartSubscription);
            _queue.RegisterHandler <StartPersistentSubscriptionMessage>(StartSubscription);

            _queue.RegisterHandler <EstablishTcpConnectionMessage>(msg => EstablishTcpConnection(msg.EndPoints));
            _queue.RegisterHandler <TcpConnectionEstablishedMessage>(msg => TcpConnectionEstablished(msg.Connection));
            _queue.RegisterHandler <TcpConnectionErrorMessage>(msg => TcpConnectionError(msg.Connection, msg.Exception));
            _queue.RegisterHandler <TcpConnectionClosedMessage>(msg => TcpConnectionClosed(msg.Connection));
            _queue.RegisterHandler <HandleTcpPackageMessage>(msg => HandleTcpPackage(msg.Connection, msg.Package));

            _queue.RegisterHandler <TimerTickMessage>(msg => TimerTick());

            _timer = new Timer(_ => EnqueueMessage(TimerTickMessage), null, Consts.TimerPeriod, Consts.TimerPeriod);
        }
        public EventStoreConnectionLogicHandler(IEventStoreConnection esConnection, ConnectionSettings settings)
        {
            Ensure.NotNull(esConnection, "esConnection");
            Ensure.NotNull(settings, "settings");

            _esConnection = esConnection;
            _settings     = settings;

            // NOTE: It can happen the user submitted operations before the connection was available and got postponed
            // by the operation or subscription manager. This leads the first operation to take time before being
            // executed. By initializing _lastTimeoutsTimeStamp like this we prevent the first operation from taking a
            // huge amount of time to complete.
            _lastTimeoutsTimeStamp = _settings.OperationTimeoutCheckPeriod.Negate();

            _operations    = new OperationsManager(_esConnection.ConnectionName, settings);
            _subscriptions = new SubscriptionsManager(_esConnection.ConnectionName, settings);
            _queue         = new SimpleQueuedHandler(_settings.Log);
            _queue.RegisterHandler <StartConnectionMessage>(msg => StartConnection(msg.Task, msg.EndPointDiscoverer));
            _queue.RegisterHandler <CloseConnectionMessage>(msg => CloseConnection(msg.Reason, msg.Exception));

            _queue.RegisterHandler <StartOperationMessage>(msg =>
                                                           StartOperation(msg.Operation, msg.MaxRetries, msg.Timeout));
            _queue.RegisterHandler <StartSubscriptionMessage>(StartSubscription);
            _queue.RegisterHandler <StartFilteredSubscriptionMessage>(StartFilteredSubscription);
            _queue.RegisterHandler <StartPersistentSubscriptionMessage>(StartSubscription);

            _queue.RegisterHandler <EstablishTcpConnectionMessage>(msg => EstablishTcpConnection(msg.EndPoints));
            _queue.RegisterHandler <TcpConnectionEstablishedMessage>(msg => TcpConnectionEstablished(msg.Connection));
            _queue.RegisterHandler <TcpConnectionErrorMessage>(msg => TcpConnectionError(msg.Connection, msg.Exception));
            _queue.RegisterHandler <TcpConnectionClosedMessage>(msg => TcpConnectionClosed(msg.Connection));
            _queue.RegisterHandler <HandleTcpPackageMessage>(msg => HandleTcpPackage(msg.Connection, msg.Package));

            _queue.RegisterHandler <TimerTickMessage>(msg => TimerTick());

            _timer = new Timer(_ => EnqueueMessage(TimerTickMessage), null, Consts.TimerPeriod, Consts.TimerPeriod);

            _compatibilityMode = CompatibilityMode.Create(_settings.CompatibilityMode);
        }