Skip navigation links

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

E47890-01


com.tangosol.util
Interface Gate

All Known Implementing Classes:
ThreadGate, ThreadGateLite, WrapperReentrantGate

public interface Gate

The Gate interface acts as an abstraction between the ThreadGate implementation that precedes JDK 1.5 locks and the ThreadGateLite that uses the ReentrantReadWriteLock.

Note: the Gate's method names have been chosen to be backwards compatible with the legacy ThreadGate implementation.

Since:
Coherence 3.7
Author:
coh 2010-08-13

Method Summary
 boolean barEntry(long cMillis)
          Bar entry to the thread gate by other threads, but do not wait for the gate to close.
 boolean close(long cMillis)
          Close the gate.
 boolean enter(long cMillis)
          Enter the gate.
 void exit()
          Exit the gate.
 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.

 

Method Detail

close

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 open() method.
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

open

void open()
Re-open the closed gate. This method can be called only if the calling thread successfully closed the gate.
Throws:
java.lang.IllegalMonitorStateException - if the gate is not closed or was closed by a different thread

enter

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 exit() method.
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

void exit()
Exit the gate. A thread must invoke this method corresponding to each invocation of the enter(long) method.
Throws:
java.lang.IllegalMonitorStateException - if the gate is not entered by the current thread

barEntry

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()
     }
 
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

isClosedByCurrentThread

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

isEnteredByCurrentThread

boolean isEnteredByCurrentThread()
Determines if the current thread has entered the gate and not yet exited.
Returns:
true if the current thread has entered the gate

isClosed

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

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.