public boolean await(long timeout, TimeUnit unit) throws InterruptedException
    {
        long waitNanos = TimeUnit.NANOSECONDS.convert(timeout, unit);

        synchronized(this)
        {
            while ( (waitNanos > 0) && (state.get() == State.STARTED) && !hasLeadership.get() )
            {
                long startNanos = System.nanoTime();
                TimeUnit.NANOSECONDS.timedWait(this, waitNanos);
                long elapsed = System.nanoTime() - startNanos;
                waitNanos -= elapsed;
            }
        }
        return hasLeadership();
    }
public boolean await ( long timeout , TimeUnit unit ) throws InterruptedException { long waitNanos = TimeUnit . NANOSECONDS . convert ( timeout , unit ) ; synchronized ( this ) { while ( ( waitNanos > 0 ) && ( state . get ( ) == State . STARTED ) && ! hasLeadership . get ( ) ) { long startNanos = System . nanoTime ( ) ; TimeUnit . NANOSECONDS . timedWait ( this , waitNanos ) ; long elapsed = System . nanoTime ( ) - startNanos ; waitNanos -= elapsed ; } } return hasLeadership ( ) ; }
<p>Causes the current thread to wait until this instance acquires leadership
unless the thread is {@linkplain Thread#interrupt interrupted},
the specified waiting time elapses or the instance is {@linkplain #close() closed}.</p>
<p></p>
<p>If this instance already is the leader then this method returns immediately
with the value {@code true}.</p>
<p></p>
<p>Otherwise the current
thread becomes disabled for thread scheduling purposes and lies
dormant until one of four things happen:</p>
<ul>
<li>This instance becomes the leader</li>
<li>Some other thread {@linkplain Thread#interrupt interrupts}
the current thread</li>
<li>The specified waiting time elapses.</li>
<li>The instance is {@linkplain #close() closed}</li>
</ul>
<p></p>
<p>If the current thread:</p>
<ul>
<li>has its interrupted status set on entry to this method; or
<li>is {@linkplain Thread#interrupt interrupted} while waiting,
</ul>
<p>then {@link InterruptedException} is thrown and the current thread's
interrupted status is cleared.</p>
<p></p>
<p>If the specified waiting time elapses or the instance is {@linkplain #close() closed}
then the value {@code false} is returned.  If the time is less than or equal to zero, the method
will not wait at all.</p>

@param timeout the maximum time to wait
@param unit    the time unit of the {@code timeout} argument
@return {@code true} if the count reached zero and {@code false}
if the waiting time elapsed before the count reached zero or the instances was closed
@throws InterruptedException if the current thread is interrupted
while waiting