Class ThreadGateLite<R>

java.lang.Object
com.tangosol.util.ThreadGateLite<R>
All Implemented Interfaces:
com.oracle.coherence.common.util.Gate<R>, Gate<R>

public final class ThreadGateLite<R> extends Object implements Gate<R>
ThreadGateLite is a Gate implementation built around the ReentrantReadWriteLock.
Since:
Coherence 3.7
Author:
coh 2010.08.09
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    protected static class 
    Bar represents the state of the bars placed on this gate.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected final com.oracle.coherence.common.util.Sentry<R>
    Sentry to return from enter() that will exit() when the sentry is closed.
    protected final com.oracle.coherence.common.util.Sentry<R>
    Sentry to return from close() that will open() when the sentry is closed.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Default constructor.
    ThreadGateLite(R resource)
    Construct a ThreadGateLite protected the specified resource.
  • Method Summary

    Modifier and Type
    Method
    Description
    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.
    com.oracle.coherence.common.util.Sentry<R>
    Wait to close the gate.
    boolean
    close(long cMillis)
    Close the gate.
    com.oracle.coherence.common.util.Sentry<R>
    Wait to enter the gate.
    boolean
    enter(long cMillis)
    Enter the gate.
    void
    Exit the gate.
    boolean
    Determine if any thread has closed the gate and continues to hold exclusive access.
    boolean
    Determine if the calling thread has closed the gate and continues to hold exclusive access.
    boolean
    Determines if the current thread has entered the gate and not yet exited.
    void
    Re-open the closed gate.
    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.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • f_exitSentry

      protected final com.oracle.coherence.common.util.Sentry<R> f_exitSentry
      Sentry to return from enter() that will exit() when the sentry is closed.
    • f_openSentry

      protected final com.oracle.coherence.common.util.Sentry<R> f_openSentry
      Sentry to return from close() that will open() when the sentry is closed.
  • Constructor Details

    • ThreadGateLite

      public ThreadGateLite()
      Default constructor.
    • ThreadGateLite

      public ThreadGateLite(R resource)
      Construct a ThreadGateLite protected the specified resource.
      Parameters:
      resource - the resource
  • Method Details

    • close

      public com.oracle.coherence.common.util.Sentry<R> close()
      Description copied from interface: com.oracle.coherence.common.util.Gate
      Wait to close the gate.
      Specified by:
      close in interface com.oracle.coherence.common.util.Gate<R>
      Returns:
      an AutoCloseable which can be used with a try-with-resource block to perform the corresponding Gate.open().
    • 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 com.oracle.coherence.common.util.Gate<R>
      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 com.oracle.coherence.common.util.Sentry<R> enter()
      Description copied from interface: com.oracle.coherence.common.util.Gate
      Wait to enter the gate.
      Specified by:
      enter in interface com.oracle.coherence.common.util.Gate<R>
      Returns:
      an AutoCloseable which can be used with a try-with-resource block to perform the corresponding Gate.exit().
    • 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 com.oracle.coherence.common.util.Gate<R>
      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() method.
      Specified by:
      exit in interface com.oracle.coherence.common.util.Gate<R>
    • isClosedByCurrentThread

      public boolean isClosedByCurrentThread()
      Determine if the calling thread has closed the gate and continues to hold exclusive access.
      Specified by:
      isClosedByCurrentThread in interface com.oracle.coherence.common.util.Gate<R>
      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 com.oracle.coherence.common.util.Gate<R>
      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 com.oracle.coherence.common.util.Gate<R>
      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 com.oracle.coherence.common.util.Gate<R>
    • 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 com.oracle.coherence.common.util.Gate<R>
      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 String toString()
      Overrides:
      toString in class Object
    • 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.