public void Setup()
 {
     _settings = new ClusterSettings(serverSelectionTimeout: TimeSpan.FromSeconds(2),
                                     postServerSelector: new LatencyLimitingServerSelector(TimeSpan.FromMinutes(2)));
     _serverFactory   = Substitute.For <IClusterableServerFactory>();
     _clusterListener = Substitute.For <IClusterListener>();
 }
        // constructor
        internal SingleServerCluster(ClusterSettings settings, IClusterableServerFactory serverFactory, IClusterListener listener)
            : base(settings, serverFactory, listener)
        {
            Ensure.IsEqualTo(settings.EndPoints.Count, 1, "settings.EndPoints.Count");

            _state = new InterlockedInt32(State.Initial);
        }
        public ClusterBuilder AddListener(IListener listener)
        {
            var clusterListener = listener as IClusterListener;

            if (clusterListener != null)
            {
                _clusterListener = ClusterListenerPair.Create(_clusterListener, clusterListener);
            }

            var serverListener = listener as IServerListener;

            if (serverListener != null)
            {
                _serverListener = ServerListenerPair.Create(_serverListener, serverListener);
            }

            var connectionPoolListener = listener as IConnectionPoolListener;

            if (connectionPoolListener != null)
            {
                _connectionPoolListener = ConnectionPoolListenerPair.Create(_connectionPoolListener, connectionPoolListener);
            }

            var connectionListener = listener as IConnectionListener;

            if (connectionListener != null)
            {
                _connectionListener = ConnectionListenerPair.Create(_connectionListener, connectionListener);
            }

            return(this);
        }
Exemple #4
0
 public BackupMessageProcessor(IClusterListener clusterListener,
                               ConcurrentQueue <Message> synchronizationQueue,
                               IDictionary <int, ProblemDataSet> dataSets,
                               IDictionary <int, ActiveComponent> activeComponents) :
     base(clusterListener, synchronizationQueue, dataSets, activeComponents)
 {
 }
Exemple #5
0
 /// <summary>
 /// Initializes a new instance of ComputationalServer with the specified listener.
 /// The default state of server is Backup.
 /// </summary>
 /// <param name="listener">Listener object which handle communication.</param>
 public ComputationalServer(IClusterListener listener) : this(ServerState.Primary)
 {
     if (listener == null)
     {
         throw new ArgumentNullException(nameof(listener));
     }
     _clusterListener = listener;
     Log.Debug("Creating new instance of ComputationalServer.");
 }
Exemple #6
0
 /// <summary>
 /// Initializes a new instance of ComputationalServer class withe the specified listener and
 /// a speciefied server state.
 /// </summary>
 /// <param name="backupClient"> A client used as BS request sender.</param>
 /// /// <param name="backupListener"> A listener used as BS request receiver.</param>
 public ComputationalServer(IClusterClient backupClient, IClusterListener backupListener) : this(ServerState.Backup)
 {
     if (backupClient == null)
     {
         throw new ArgumentNullException(nameof(backupClient));
     }
     _backupClient    = backupClient;
     _clusterListener = backupListener;
     Log.Debug("New instance of Backup ComputationalServer has been created.");
 }
Exemple #7
0
        // constructors
        protected Cluster(ClusterSettings settings, IClusterableServerFactory serverFactory, IClusterListener listener)
        {
            _settings      = Ensure.IsNotNull(settings, "settings");
            _serverFactory = Ensure.IsNotNull(serverFactory, "serverFactory");
            _listener      = listener;
            _state         = new InterlockedInt32(State.Initial);

            _clusterId   = new ClusterId();
            _description = ClusterDescription.CreateInitial(_clusterId, _settings.ConnectionMode.ToClusterType());
            _descriptionChangedTaskCompletionSource = new TaskCompletionSource <bool>();
        }
Exemple #8
0
        // constructors
        protected Cluster(ClusterSettings settings, IClusterableServerFactory serverFactory, IClusterListener listener)
        {
            _settings = Ensure.IsNotNull(settings, "settings");
            _serverFactory = Ensure.IsNotNull(serverFactory, "serverFactory");
            _listener = listener;
            _state = new InterlockedInt32(State.Initial);

            _clusterId = new ClusterId();
            _description = ClusterDescription.CreateInitial(_clusterId, _settings.ConnectionMode.ToClusterType());
            _descriptionChangedTaskCompletionSource = new TaskCompletionSource<bool>();
        }
        // constructors
        public MultiServerCluster(ClusterSettings settings, IClusterableServerFactory serverFactory, IClusterListener listener)
            : base(settings, serverFactory, listener)
        {
            Ensure.IsGreaterThanZero(settings.EndPoints.Count, "settings.EndPoints.Count");

            _monitorServersCancellationTokenSource = new CancellationTokenSource();
            _serverDescriptionChangedQueue = new AsyncQueue<ServerDescriptionChangedEventArgs>();
            _servers = new List<IClusterableServer>();
            _state = new InterlockedInt32(State.Initial);
            _replicaSetName = settings.ReplicaSetName;
        }
Exemple #10
0
        private ICluster BuildCluster(BsonDocument definition)
        {
            var connectionString = new ConnectionString((string)definition["uri"]);
            var settings         = new ClusterSettings(
                endPoints: Optional.Create <IEnumerable <EndPoint> >(connectionString.Hosts),
                connectionMode: connectionString.Connect,
                replicaSetName: connectionString.ReplicaSet);

            _serverFactory   = new MockClusterableServerFactory();
            _clusterListener = Substitute.For <IClusterListener>();
            return(new ClusterFactory(settings, _serverFactory, _clusterListener)
                   .CreateCluster());
        }
Exemple #11
0
        // static
        public static IClusterListener Create(IClusterListener first, IClusterListener second)
        {
            if (first == null)
            {
                return(second);
            }

            if (second == null)
            {
                return(first);
            }

            return(new ClusterListenerPair(first, second));
        }
        // static
        public static IClusterListener Create(IClusterListener first, IClusterListener second)
        {
            if (first == null)
            {
                return second;
            }

            if (second == null)
            {
                return first;
            }

            return new ClusterListenerPair(first, second);
        }
 protected MessageProcessor(IClusterListener clusterListener,
                            ConcurrentQueue <Message> synchronizationQueue,
                            IDictionary <int, ProblemDataSet> dataSets,
                            IDictionary <int, ActiveComponent> activeComponents)
 {
     ClusterListener      = clusterListener;
     SynchronizationQueue = synchronizationQueue;
     StatusThreads        = new List <Thread>();
     //run all status threads (needed if backup is getting primary status)
     if (activeComponents != null)
     {
         foreach (var activeComponent in activeComponents)
         {
             activeComponent.Value.StatusWatch.Start();
             RunStatusThread(activeComponent.Key, activeComponents, dataSets);
         }
     }
 }
Exemple #14
0
        /// <summary>
        /// Runs server as Primary server.
        /// </summary>
        public virtual void RunAsPrimary()
        {
            _messageProcessor = new PrimaryMessageProcessor
                                    (_clusterListener, _synchronizationQueue, _problemDataSets, _activeComponents);

            _backupClient = null;
            if (_clusterListener == null)
            {
                _clusterListener = ClusterListenerFactory.Factory.Create(IPAddress.Any, Properties.Settings.Default.Port);
            }
            //_backups.Clear();

            Log.Debug("Starting listening mechanism.");
            _clusterListener.Start();
            _isWorking = true;
            _currentlyWorkingThreads.Clear();
            Log.Debug("Listening mechanism has been started.");
            BackupServerStatusInterval = null;
            BackupServerId             = null;
            DoPrimaryWork();
        }
Exemple #15
0
        /// <summary>
        /// Runs server as Backup server.
        /// </summary>
        public virtual void RunAsBackup()
        {
            _messageProcessor = new BackupMessageProcessor
                                    (_clusterListener, _synchronizationQueue, _problemDataSets, _activeComponents);

            if (_backupClient == null)
            {
                _backupClient = ClusterClientFactory.Factory.Create(Properties.Settings.Default.MasterAddress,
                                                                    Properties.Settings.Default.MasterPort);
            }
            if (_clusterListener == null)
            {
                _clusterListener = ClusterListenerFactory.Factory.Create(IPAddress.Any, Properties.Settings.Default.Port);
            }
            //AZBEST314
            Log.Debug("Starting backup listening mechanism.");
            _clusterListener.Start();
            _currentlyWorkingThreads.Clear();
            _isWorking = true;
            DoBackupWork();
        }
Exemple #16
0
 // constructors
 public ClusterListenerPair(IClusterListener first, IClusterListener second)
 {
     _first  = Ensure.IsNotNull(first, "first");
     _second = Ensure.IsNotNull(second, "second");
 }
 public void Setup()
 {
     _settings        = new ClusterSettings();
     _serverFactory   = Substitute.For <IClusterableServerFactory>();
     _clusterListener = Substitute.For <IClusterListener>();
 }
 public StubCluster(ClusterSettings settings, IClusterableServerFactory serverFactory, IClusterListener listener)
     : base(settings, serverFactory, null)
 {
 }
 public void Setup()
 {
     _settings = new ClusterSettings();
     _serverFactory = Substitute.For<IClusterableServerFactory>();
     _clusterListener = Substitute.For<IClusterListener>();
 }
 // constructors
 public ClusterListenerPair(IClusterListener first, IClusterListener second)
 {
     _first = Ensure.IsNotNull(first, "first");
     _second = Ensure.IsNotNull(second, "second");
 }
            public StubCluster(ClusterSettings settings, IClusterableServerFactory serverFactory, IClusterListener listener)
                : base(settings, serverFactory, null)
            {


            }
Exemple #22
0
        // constructors
        public MultiServerCluster(ClusterSettings settings, IClusterableServerFactory serverFactory, IClusterListener listener)
            : base(settings, serverFactory, listener)
        {
            Ensure.IsGreaterThanZero(settings.EndPoints.Count, "settings.EndPoints.Count");

            _monitorServersCancellationTokenSource = new CancellationTokenSource();
            _serverDescriptionChangedQueue         = new AsyncQueue <ServerDescriptionChangedEventArgs>();
            _servers        = new List <IClusterableServer>();
            _state          = new InterlockedInt32(State.Initial);
            _replicaSetName = settings.ReplicaSetName;
        }
        // constructors
        public MultiServerCluster(ClusterSettings settings, IClusterableServerFactory serverFactory, IClusterListener listener)
            : base(settings, serverFactory, listener)
        {
            Ensure.IsGreaterThanZero(settings.EndPoints.Count, "settings.EndPoints.Count");
            if (settings.ConnectionMode == ClusterConnectionMode.Standalone)
            {
                throw new ArgumentException("ClusterConnectionMode.StandAlone is not supported for a MultiServerCluster.");
            }
            if (settings.ConnectionMode == ClusterConnectionMode.Direct)
            {
                throw new ArgumentException("ClusterConnectionMode.Direct is not supported for a MultiServerCluster.");
            }

            _monitorServersCancellationTokenSource = new CancellationTokenSource();
            _serverDescriptionChangedQueue         = new AsyncQueue <ServerDescriptionChangedEventArgs>();
            _servers        = new List <IClusterableServer>();
            _state          = new InterlockedInt32(State.Initial);
            _replicaSetName = settings.ReplicaSetName;
        }
        public ClusterBuilder AddListener(IListener listener)
        {
            var clusterListener = listener as IClusterListener;
            if (clusterListener != null)
            {
                _clusterListener = ClusterListenerPair.Create(_clusterListener, clusterListener);
            }

            var serverListener = listener as IServerListener;
            if (serverListener != null)
            {
                _serverListener = ServerListenerPair.Create(_serverListener, serverListener);
            }

            var connectionPoolListener = listener as IConnectionPoolListener;
            if (connectionPoolListener != null)
            {
                _connectionPoolListener = ConnectionPoolListenerPair.Create(_connectionPoolListener, connectionPoolListener);
            }

            var connectionListener = listener as IConnectionListener;
            if (connectionListener != null)
            {
                _connectionListener = ConnectionListenerPair.Create(_connectionListener, connectionListener);
            }

            return this;
        }
Exemple #25
0
        // constructor
        internal SingleServerCluster(ClusterSettings settings, IClusterableServerFactory serverFactory, IClusterListener listener)
            : base(settings, serverFactory, listener)
        {
            Ensure.IsEqualTo(settings.EndPoints.Count, 1, "settings.EndPoints.Count");

            _state = new InterlockedInt32(State.Initial);
        }
 // constructors
 public ClusterFactory(ClusterSettings settings, IClusterableServerFactory serverFactory, IClusterListener listener)
 {
     _settings = Ensure.IsNotNull(settings, "settings");
     _serverFactory = Ensure.IsNotNull(serverFactory, "serverFactory");
     _listener = listener;
 }
 // constructors
 public ClusterFactory(ClusterSettings settings, IClusterableServerFactory serverFactory, IClusterListener listener)
 {
     _settings      = Ensure.IsNotNull(settings, "settings");
     _serverFactory = Ensure.IsNotNull(serverFactory, "serverFactory");
     _listener      = listener;
 }
Exemple #28
0
 public void RegisterClusterListener(IClusterListener clusterListener)
 {
     this._clusterListener = clusterListener;
 }
Exemple #29
0
 public void UnregisterClusterListener(IClusterListener clusterListener)
 {
     this._clusterListener = null;
 }
 public void Setup()
 {
     _settings        = new ClusterSettings(serverSelectionTimeout: TimeSpan.FromSeconds(2));
     _serverFactory   = Substitute.For <IClusterableServerFactory>();
     _clusterListener = Substitute.For <IClusterListener>();
 }