Beispiel #1
0
        public RoundBasedRegister(IIntercomMessageHub intercomMessageHub,
                                  IBallotGenerator ballotGenerator,
                                  ISynodConfiguration synodConfig,
                                  LeaseConfiguration leaseConfig,
                                  ILogger logger)
        {
            this.logger             = logger;
            this.synodConfig        = synodConfig;
            this.leaseConfig        = leaseConfig;
            this.intercomMessageHub = intercomMessageHub;
            readBallot  = ballotGenerator.Null();
            writeBallot = ballotGenerator.Null();

            listener = intercomMessageHub.Subscribe();

            listener.Where(m => m.Equals(ConsensusMessages.LeaseRead)).Subscribe(OnReadReceived);
            listener.Where(m => m.Equals(ConsensusMessages.LeaseWrite)).Subscribe(OnWriteReceived);

            ackReadStream   = listener.Where(m => m.Equals(ConsensusMessages.LeaseAckRead));
            nackReadStream  = listener.Where(m => m.Equals(ConsensusMessages.LeaseNackRead));
            ackWriteStream  = listener.Where(m => m.Equals(ConsensusMessages.LeaseAckWrite));
            nackWriteStream = listener.Where(m => m.Equals(ConsensusMessages.LeaseNackWrite));

            WaitBeforeNextLeaseIssued(leaseConfig);
        }
        public RoundBasedRegister(IIntercomMessageHub intercomMessageHub,
                                  IBallotGenerator ballotGenerator,
                                  ISynodConfiguration synodConfig,
                                  LeaseConfiguration leaseConfig,
                                  ILogger logger)
        {
            this.logger = logger;
            this.synodConfig = synodConfig;
            this.leaseConfig = leaseConfig;
            this.intercomMessageHub = intercomMessageHub;
            intercomMessageHub.Start();
            readBallot = ballotGenerator.Null();
            writeBallot = ballotGenerator.Null();

            listener = intercomMessageHub.Subscribe();

            listener.Where(m => Unsafe.Equals(m.Identity, LeaseReadMessage.MessageIdentity))
                    .Subscribe(OnReadReceived);
            listener.Where(m => Unsafe.Equals(m.Identity, LeaseWriteMessage.MessageIdentity))
                    .Subscribe(OnWriteReceived);

            ackReadStream = listener.Where(m => Unsafe.Equals(m.Identity, LeaseAckReadMessage.MessageIdentity));
            nackReadStream = listener.Where(m => Unsafe.Equals(m.Identity, LeaseNackReadMessage.MessageIdentity));
            ackWriteStream = listener.Where(m => Unsafe.Equals(m.Identity, LeaseAckWriteMessage.MessageIdentity));
            nackWriteStream = listener.Where(m => Unsafe.Equals(m.Identity, LeaseNackWriteMessage.MessageIdentity));
        }
 public LeaderElectionMessageFilter(Ballot ballot,
                                    Func<IMessage, ILeaseMessage> payload,
                                    ISynodConfiguration synodConfig)
 {
     this.ballot = ballot;
     this.synodConfig = synodConfig;
     this.payload = payload;
 }
 public LeaderElectionMessageFilter(Ballot ballot,
                                    Func <IMessage, ILeaseMessage> payload,
                                    ISynodConfiguration synodConfig)
 {
     this.ballot      = ballot;
     this.synodConfig = synodConfig;
     this.payload     = payload;
 }
 public IntercomMessageHub(ISocketFactory socketFactory,
                           ISynodConfiguration synodConfig,
                           ILogger logger)
 {
     this.socketFactory = socketFactory;
     this.logger = logger;
     cancellationTokenSource = new CancellationTokenSource();
     this.synodConfig = synodConfig;
     inMessageQueue = new BlockingCollection<IMessage>(new ConcurrentQueue<IMessage>());
     outMessageQueue = new BlockingCollection<IntercomMessage>(new ConcurrentQueue<IntercomMessage>());
     subscriptions = new ConcurrentDictionary<Listener, object>();
 }
 public RendezvousService(ILeaseProvider leaseProvider,
                          ISynodConfiguration synodConfig,
                          ISocketFactory socketFactory,
                          RendezvousConfiguration config,
                          ILogger logger)
 {
     this.socketFactory = socketFactory;
     this.logger = logger;
     localNode = synodConfig.LocalNode;
     this.leaseProvider = leaseProvider;
     this.config = config;
     cancellationTokenSource = new CancellationTokenSource();
 }
 public IntercomMessageHub(ISocketFactory socketFactory,
                           ISynodConfiguration synodConfig,
                           IPerformanceCounterManager <KinoPerformanceCounters> performanceCounterManager,
                           ILogger logger)
 {
     this.socketFactory             = socketFactory;
     this.logger                    = logger;
     cancellationTokenSource        = new CancellationTokenSource();
     this.synodConfig               = synodConfig;
     this.performanceCounterManager = performanceCounterManager;
     inMessageQueue                 = new BlockingCollection <IMessage>(new ConcurrentQueue <IMessage>());
     outMessageQueue                = new BlockingCollection <IntercomMessage>(new ConcurrentQueue <IntercomMessage>());
     subscriptions                  = new ConcurrentDictionary <Listener, object>();
 }
Beispiel #8
0
        public LeaseProvider(IRoundBasedRegister register,
                             IBallotGenerator ballotGenerator,
                             LeaseConfiguration config,
                             ISynodConfiguration synodConfig,
                             ILogger logger)
        {
            ValidateConfiguration(config);

            localNode             = synodConfig.LocalNode;
            this.logger           = logger;
            this.config           = config;
            this.ballotGenerator  = ballotGenerator;
            this.register         = register;
            leaseRenewWaitTimeout = TimeSpan.FromMilliseconds(10);
            renewGateway          = new SemaphoreSlim(1);
            leaseTimer            = new Timer(state => ScheduledReadOrRenewLease(), null, TimeSpan.FromMilliseconds(-1), TimeSpan.FromMilliseconds(-1));
        }
Beispiel #9
0
        public LeaseProvider(IRoundBasedRegister register,
                             IBallotGenerator ballotGenerator,
                             LeaseConfiguration config,
                             ISynodConfiguration synodConfig,
                             RendezvousConfiguration rendezvousConfig,
                             ILogger logger)
        {
            ValidateConfiguration(config);

            WaitBeforeNextLeaseIssued(config);

            localNode = synodConfig.LocalNode;
            this.logger = logger;
            this.config = config;
            this.rendezvousConfig = rendezvousConfig;
            this.ballotGenerator = ballotGenerator;
            this.register = register;
            leaseRenewWaitTimeout = TimeSpan.FromMilliseconds(10);
            renewGateway = new SemaphoreSlim(1);
            leaseTimer = new Timer(state => ScheduledReadOrRenewLease(), null, TimeSpan.FromMilliseconds(-1), TimeSpan.FromMilliseconds(-1));
        }
 public RendezvousService(ILeaseProvider leaseProvider,
                          ISynodConfiguration synodConfig,
                          ISocketFactory socketFactory,
                          IMessageSerializer serializer,
                          IRendezvousConfigurationProvider configProvider,
                          IPerformanceCounterManager <KinoPerformanceCounters> performanceCounterManager,
                          ILogger logger)
 {
     this.socketFactory             = socketFactory;
     this.logger                    = logger;
     this.serializer                = serializer;
     localNode                      = synodConfig.LocalNode;
     this.leaseProvider             = leaseProvider;
     this.configProvider            = configProvider;
     this.performanceCounterManager = performanceCounterManager;
     cancellationTokenSource        = new CancellationTokenSource();
     pongMessage                    = Message.Create(new PongMessage());
     leaderPayload                  = serializer.Serialize(new RendezvousNode
     {
         BroadcastUri = configProvider.BroadcastUri.ToSocketAddress(),
         UnicastUri   = configProvider.UnicastUri.ToSocketAddress()
     });
 }