Beispiel #1
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);
                }
            }
        }
Beispiel #2
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);
        }