Class CloseableMonitor
java.lang.Object
com.google.cloud.pubsublite.internal.CloseableMonitor
Wraps a Monitor with methods that can be used with try-with-resources.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionclassThis is meant for use in the try-with-resources pattern. -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionenter()try-with-resources wrapper for enter.enterWhenUninterruptibly(com.google.common.util.concurrent.Monitor.Guard condition) try-with-resources wrapper for enterWhenUninterruptibly.
-
Field Details
-
monitor
public final com.google.common.util.concurrent.Monitor monitor
-
-
Constructor Details
-
CloseableMonitor
public CloseableMonitor()
-
-
Method Details
-
enterWhenUninterruptibly
public CloseableMonitor.Hold enterWhenUninterruptibly(com.google.common.util.concurrent.Monitor.Guard condition) try-with-resources wrapper for enterWhenUninterruptibly. For example:final Monitor.Guard guard = new Monitor.Guard(monitor.monitor) { @Override public boolean isSatisfied() { assertThat(monitor.monitor.isOccupied()).isTrue(); return state; } }; try (CloseableMonitor.Hold h = monitor.enterWhenUninterruptibly(guard)) { // Do stuff } // Monitor is automatically released -
enter
try-with-resources wrapper for enter. For example...try (CloseableMonitor.Hold h = monitor.enter()) { // Do stuff } // Monitor is automatically released
-