Class CloseableMonitor
- java.lang.Object
-
- com.google.cloud.pubsublite.internal.CloseableMonitor
-
public class CloseableMonitor extends Object
Wraps a Monitor with methods that can be used with try-with-resources.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description class
CloseableMonitor.Hold
This is meant for use in the try-with-resources pattern.
-
Field Summary
Fields Modifier and Type Field Description com.google.common.util.concurrent.Monitor
monitor
-
Constructor Summary
Constructors Constructor Description CloseableMonitor()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description CloseableMonitor.Hold
enter()
try-with-resources wrapper for enter.CloseableMonitor.Hold
enterWhenUninterruptibly(com.google.common.util.concurrent.Monitor.Guard condition)
try-with-resources wrapper for enterWhenUninterruptibly.
-
-
-
Method Detail
-
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
public CloseableMonitor.Hold enter()
try-with-resources wrapper for enter. For example...try (CloseableMonitor.Hold h = monitor.enter()) { // Do stuff } // Monitor is automatically released
-
-