public void Setup()
 {
     ownerEndpoint = new OwnerEndpoint
                     {
                         MulticastUri = new Uri("tcp://127.0.0.1"),
                         UnicastUri = new Uri("tcp://127.0.0.1")
                     };
 }
Ejemplo n.º 2
0
        private Lease AсquireOrLearnLease(Ballot ballot, DateTime now)
        {
            var read = register.Read(ballot);
            if (read.TxOutcome == TxOutcome.Commit)
            {
                var lease = read.Lease;
                if (LeaseIsNotSafelyExpired(lease, now))
                {
                    LogStartSleep();
                    Sleep(config.ClockDrift);
                    LogAwake();

                    // TODO: Add recursion exit condition
                    return AсquireOrLearnLease(ballotGenerator.New(localNode.SocketIdentity), DateTime.UtcNow);
                }

                if (LeaseNullOrExpired(lease, now) || IsLeaseOwner(lease))
                {
                    LogLeaseProlonged(lease);
                    var ownerEndpoint = new OwnerEndpoint {UnicastUri = rendezvousConfig.UnicastUri, MulticastUri = rendezvousConfig.MulticastUri};
                    lease = new Lease(localNode.SocketIdentity, ownerEndpoint, now + config.MaxLeaseTimeSpan);
                }

                var write = register.Write(ballot, lease);
                if (write.TxOutcome == TxOutcome.Commit)
                {
                    return lease;
                }
            }

            return null;
        }
Ejemplo n.º 3
0
 public Lease(byte[] ownerIdentity, OwnerEndpoint ownerEndpoint, DateTime expiresAt)
 {
     OwnerIdentity = ownerIdentity;
     OwnerEndpoint = ownerEndpoint;
     ExpiresAt = expiresAt;
 }
Ejemplo n.º 4
0
 public Lease(byte[] ownerIdentity, OwnerEndpoint ownerEndpoint, long expiresAt)
     : this(ownerIdentity, ownerEndpoint, new DateTime(expiresAt, DateTimeKind.Utc))
 {
 }