Beispiel #1
0
 // static methods
 private static string FormatMessage(ConnectionId connectionId, long cursorId)
 {
     return(string.Format(
                "Cursor {0} not found on server {1} using connection {2}.",
                cursorId,
                EndPointHelper.ToString(connectionId.ServerId.EndPoint),
                connectionId.ServerValue));
 }
Beispiel #2
0
        // static methods
        internal static MongoWaitQueueFullException ForConnectionPool(EndPoint endPoint)
        {
            var message = string.Format(
                "The wait queue for acquiring a connection to server {0} is full.",
                EndPointHelper.ToString(endPoint));

            return(new MongoWaitQueueFullException(message));
        }
Beispiel #3
0
        // constructors
        public ExclusiveConnectionPool(
            ServerId serverId,
            EndPoint endPoint,
            ConnectionPoolSettings settings,
            IConnectionFactory connectionFactory,
            IEventSubscriber eventSubscriber,
            IConnectionExceptionHandler connectionExceptionHandler)
        {
            _serverId                   = Ensure.IsNotNull(serverId, nameof(serverId));
            _endPoint                   = Ensure.IsNotNull(endPoint, nameof(endPoint));
            _settings                   = Ensure.IsNotNull(settings, nameof(settings));
            _connectionFactory          = Ensure.IsNotNull(connectionFactory, nameof(connectionFactory));
            _connectionExceptionHandler = Ensure.IsNotNull(connectionExceptionHandler, nameof(connectionExceptionHandler));
            Ensure.IsNotNull(eventSubscriber, nameof(eventSubscriber));

            _maintenanceHelper     = new MaintenanceHelper(MaintainSize, _settings.MaintenanceInterval);
            _poolState             = new PoolState(EndPointHelper.ToString(_endPoint));
            _checkOutReasonCounter = new CheckOutReasonCounter();

            _maxConnectingQueue  = new SemaphoreSlimSignalable(settings.MaxConnecting);
            _connectionHolder    = new ListConnectionHolder(eventSubscriber, _maxConnectingQueue);
            _maxConnectionsQueue = new SemaphoreSlimSignalable(settings.MaxConnections);

            _serviceStates = new ServiceStates();
#pragma warning disable 618
            _waitQueueFreeSlots = settings.WaitQueueSize;
#pragma warning restore 618

            eventSubscriber.TryGetEventHandler(out _checkingOutConnectionEventHandler);
            eventSubscriber.TryGetEventHandler(out _checkedOutConnectionEventHandler);
            eventSubscriber.TryGetEventHandler(out _checkingOutConnectionFailedEventHandler);
            eventSubscriber.TryGetEventHandler(out _checkingInConnectionEventHandler);
            eventSubscriber.TryGetEventHandler(out _checkedInConnectionEventHandler);
            eventSubscriber.TryGetEventHandler(out _addingConnectionEventHandler);
            eventSubscriber.TryGetEventHandler(out _addedConnectionEventHandler);
            eventSubscriber.TryGetEventHandler(out _openingEventHandler);
            eventSubscriber.TryGetEventHandler(out _openedEventHandler);
            eventSubscriber.TryGetEventHandler(out _closingEventHandler);
            eventSubscriber.TryGetEventHandler(out _closedEventHandler);
            eventSubscriber.TryGetEventHandler(out _readyEventHandler);
            eventSubscriber.TryGetEventHandler(out _addingConnectionEventHandler);
            eventSubscriber.TryGetEventHandler(out _addedConnectionEventHandler);
            eventSubscriber.TryGetEventHandler(out _clearingEventHandler);
            eventSubscriber.TryGetEventHandler(out _clearedEventHandler);
            eventSubscriber.TryGetEventHandler(out _connectionCreatedEventHandler);
        }
        private static string FormatMessage(ClusterDescription description)
        {
            var incompatibleServer = description.Servers.FirstOrDefault(IsServerIncompatible);

            if (incompatibleServer == null)
            {
                return($"This version of the driver requires wire version {Cluster.SupportedWireVersionRange}");
            }

            if (incompatibleServer.WireVersionRange.Max < Cluster.SupportedWireVersionRange.Min)
            {
                return($"Server at {EndPointHelper.ToString(incompatibleServer.EndPoint)} reports wire version {incompatibleServer.WireVersionRange.Max},"
                       + $" but this version of the driver requires at least {Cluster.SupportedWireVersionRange.Min} (MongoDB {Cluster.MinSupportedServerVersion}).");
            }

            return($"Server at {EndPointHelper.ToString(incompatibleServer.EndPoint)} requires wire version {incompatibleServer.WireVersionRange.Min},"
                   + $" but this version of the driver only supports up to {Cluster.SupportedWireVersionRange.Max}.");
        }
        public void ResolveSrvRecords_should_return_expected_result(string service, string[] expectedEndPoints, bool async)
        {
            var subject = CreateSubject();

            List <SrvRecord> result;

            if (async)
            {
                result = subject.ResolveSrvRecordsAsync(service, CancellationToken.None).GetAwaiter().GetResult();
            }
            else
            {
                result = subject.ResolveSrvRecords(service, CancellationToken.None);
            }

            var actualEndPoints = result.Select(s => EndPointHelper.ToString(s.EndPoint)).ToList();

            actualEndPoints.Should().BeEquivalentTo(expectedEndPoints);
        }
 /// <inheritdoc/>
 public override string ToString()
 {
     return(string.Format("EndPointServerSelector{{ EndPoint = {0} }}", EndPointHelper.ToString(_endPoint)));
 }
Beispiel #7
0
 internal static MongoConnectionPoolPausedException ForConnectionPool(EndPoint endPoint) =>
 ForConnectionPool(EndPointHelper.ToString(endPoint));