Skip navigation links

Oracle® Fusion Middleware Java API Reference for Oracle Coherence
12c (12.1.3.0.0)

E47890-01


com.tangosol.util
Class ThreadGateLite

java.lang.Object
  extended by com.tangosol.util.ThreadGateLite

All Implemented Interfaces:
Gate

public final class ThreadGateLite
extends java.lang.Object
implements Gate

ThreadGateLite is a Gate implementation built around the ReentrantReadWriteLock.

Since:
Coherence 3.7
Author:
coh 2010.08.09

Nested Class Summary
protected static class ThreadGateLite.Bar
          Bar represents the state of the bars placed on this gate.

 

Field Summary
protected static java.util.concurrent.atomic.AtomicReferenceFieldUpdater UPDATER_BAR
          AtomicUpdater for the internal Bar member.

 

Constructor Summary
ThreadGateLite()
           

 

Method Summary
protected  long adjustWaitTime(long cMillis, long ldtStart)
          Calculate the time remaining from the total time allotted for an operation.
 boolean barEntry(long cMillis)
          Bar entry to the thread gate by other threads, but do not wait for the gate to close.
protected  boolean casBar(ThreadGateLite.Bar barExpect, ThreadGateLite.Bar barNew)
          Atomically set the bar in this gate to the new Bar object iff the current value of the bar is the expected one.
 boolean close(long cMillis)
          Close the gate.
 boolean enter(long cMillis)
          Enter the gate.
 void exit()
          Exit the gate.
protected  ThreadGateLite.Bar getBar()
          Get this gate's bar.
 boolean isClosed()
          Determine if any thread has closed the gate and continues to hold exclusive access.
 boolean isClosedByCurrentThread()
          Determine if the calling thread has closed the gate and continues to hold exclusive access.
 boolean isEnteredByCurrentThread()
          Determines if the current thread has entered the gate and not yet exited.
 void open()
          Re-open the closed gate.
protected  void setBar(ThreadGateLite.Bar bar)
          Set this gate's bar.
 java.lang.String toString()
          
protected  long waitForOpen(ThreadGateLite.Bar bar, long cMillis)
          Wait for notification that the bar has been lifted completely, i.e. all re-entrant barEntry calls were matched.

 

Field Detail

UPDATER_BAR

protected static final java.util.concurrent.atomic.AtomicReferenceFieldUpdater UPDATER_BAR
AtomicUpdater for the internal Bar member.

Constructor Detail

ThreadGateLite

public ThreadGateLite()

Method Detail

close

public boolean close(long cMillis)
Close the gate. A thread uses this method to obtain exclusive access to the resource represented by the gate. Each invocation of this method must ultimately have a corresponding invocation of the Gate.open() method.
Specified by:
close in interface Gate
Parameters:
cMillis - maximum number of milliseconds to wait; pass -1 to wait indefinitely or 0 to return immediately
Returns:
true iff entry into the gate was successfully closed by the calling thread and no other threads remain in the gate

enter

public boolean enter(long cMillis)
Enter the gate. A thread uses this method to obtain non-exclusive access to the resource represented by the gate. Each invocation of this method must ultimately have a corresponding invocation of the Gate.exit() method.
Specified by:
enter in interface Gate
Parameters:
cMillis - maximum number of milliseconds to wait; pass -1 to wait indefinitely or 0 to return immediately
Returns:
true iff the calling thread successfully entered the gate

exit

public void exit()
Exit the gate. A thread must invoke this method corresponding to each invocation of the Gate.enter(long) method.
Specified by:
exit in interface Gate

isClosedByCurrentThread

public boolean isClosedByCurrentThread()
Determine if the calling thread has closed the gate and continues to hold exclusive access.
Specified by:
isClosedByCurrentThread in interface Gate
Returns:
true iff the calling thread holds exclusive access to the gate

isClosed

public boolean isClosed()
Determine if any thread has closed the gate and continues to hold exclusive access.
Specified by:
isClosed in interface Gate
Returns:
true iff there is a thread that holds exclusive access to the gate

isEnteredByCurrentThread

public boolean isEnteredByCurrentThread()
Determines if the current thread has entered the gate and not yet exited.
Specified by:
isEnteredByCurrentThread in interface Gate
Returns:
true if the current thread has entered the gate

open

public void open()
Re-open the closed gate. This method can be called only if the calling thread successfully closed the gate.
Specified by:
open in interface Gate

barEntry

public boolean barEntry(long cMillis)
Bar entry to the thread gate by other threads, but do not wait for the gate to close. When all other threads have exited, the status of the thread gate will be closeable by the thread which barred entry. Threads that have already entered the gate at the time of this method call should be allowed to succeed in additional #enter calls.

Each successful invocation of this method must ultimately have a corresponding invocation of the open method (assuming the thread gate is not destroyed) even if the calling thread does not subsequently close the gate.


 gate.barEntry(-1);
 try
     {
     // processing that does not require the gate to be closed
     // ...
     }
 finally
     {
     gate.close(-1);
     try
         {
         // processing that does require the gate to be closed
         // ...
         }
     finally
         {
         gate.open(); // matches gate.close()
         }
     gate.open(); // matches gate.barEntry()
     }
 
Specified by:
barEntry in interface Gate
Parameters:
cMillis - maximum number of milliseconds to wait; pass -1 for forever or 0 for no wait
Returns:
true iff entry into the thread gate was successfully barred by the calling thread

toString

public java.lang.String toString()

waitForOpen

protected long waitForOpen(ThreadGateLite.Bar bar,
                           long cMillis)
Wait for notification that the bar has been lifted completely, i.e. all re-entrant barEntry calls were matched. See open().
Parameters:
bar - the bar that needs to be lifted for this thread to proceed (cannot be null)
cMillis - time to wait or -1 for unlimited wait
Returns:
the remaining wait time, or 0 if the wait time has expired

adjustWaitTime

protected long adjustWaitTime(long cMillis,
                              long ldtStart)
Calculate the time remaining from the total time allotted for an operation.
Parameters:
cMillis - the total time allotted for an operation
ldtStart - the start of the time interval that have passed
Returns:
the remaining wait time in milliseconds. The value may be positive, zero for no time left or -1 for indefinite wait.

getBar

protected ThreadGateLite.Bar getBar()
Get this gate's bar.
Returns:
the Bar object or null

setBar

protected void setBar(ThreadGateLite.Bar bar)
Set this gate's bar.
Parameters:
bar - the new Bar value

casBar

protected boolean casBar(ThreadGateLite.Bar barExpect,
                         ThreadGateLite.Bar barNew)
Atomically set the bar in this gate to the new Bar object iff the current value of the bar is the expected one.
Parameters:
barExpect - the Bar expected to be the current value
barNew - the new Bar value
Returns:
true iff the bar was updated

Skip navigation links

Oracle® Fusion Middleware Java API Reference for Oracle Coherence
12c (12.1.3.0.0)

E47890-01


Copyright © 2000, 2014, Oracle and/or its affiliates. All rights reserved.