Пример #1
0
        public override bool Equals(object o)
        {
            if (this == o)
            {
                return(true);
            }
            if (o == null || this.GetType() != o.GetType())
            {
                return(false);
            }
            ReplicatedLockTokenRequest that = ( ReplicatedLockTokenRequest )o;

            return(_candidateId == that._candidateId && Objects.Equals(_owner, that._owner));
        }
Пример #2
0
        /// <summary>
        /// Acquires a valid token id owned by us or throws.
        /// </summary>
        private int AcquireTokenOrThrow()
        {
            lock (this)
            {
                LockToken currentToken = _lockTokenStateMachine.currentToken();
                if (_myself.Equals(currentToken.Owner()))
                {
                    return(currentToken.Id());
                }

                /* If we are not the leader then we will not even attempt to get the token,
                 * since only the leader should take locks. */
                EnsureLeader();

                ReplicatedLockTokenRequest lockTokenRequest = new ReplicatedLockTokenRequest(_myself, LockToken.nextCandidateId(currentToken.Id()));

                Future <object> future;
                try
                {
                    future = _replicator.replicate(lockTokenRequest, true);
                }
                catch (ReplicationFailureException e)
                {
                    throw new AcquireLockTimeoutException(e, "Replication failure acquiring lock token.", ReplicationFailure);
                }

                try
                {
                    bool success = ( bool )future.get();
                    if (success)
                    {
                        return(lockTokenRequest.Id());
                    }
                    else
                    {
                        throw new AcquireLockTimeoutException("Failed to acquire lock token. Was taken by another candidate.", NotALeader);
                    }
                }
                catch (ExecutionException e)
                {
                    throw new AcquireLockTimeoutException(e, "Failed to acquire lock token.", NotALeader);
                }
                catch (InterruptedException e)
                {
                    Thread.CurrentThread.Interrupt();
                    throw new AcquireLockTimeoutException(e, "Failed to acquire lock token.", Interrupted);
                }
            }
        }
Пример #3
0
 public virtual void Set(ReplicatedLockTokenRequest currentToken, long ordinal)
 {
     this._currentToken = currentToken;
     this._ordinal      = ordinal;
 }
Пример #4
0
 public ReplicatedLockTokenState(long ordinal, ReplicatedLockTokenRequest currentToken)
 {
     this._ordinal      = ordinal;
     this._currentToken = currentToken;
 }
Пример #5
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public static void marshal(ReplicatedLockTokenRequest tokenRequest, org.neo4j.storageengine.api.WritableChannel channel) throws java.io.IOException
        public static void Marshal(ReplicatedLockTokenRequest tokenRequest, WritableChannel channel)
        {
            channel.PutInt(tokenRequest.Id());
            (new MemberId.Marshal()).marshal(tokenRequest.Owner(), channel);
        }