|
32 | 32 | import java.util.concurrent.TimeUnit;
|
33 | 33 | import java.util.concurrent.TimeoutException;
|
34 | 34 | import java.util.concurrent.atomic.AtomicBoolean;
|
35 |
| -import java.util.concurrent.locks.Lock; |
36 | 35 | import java.util.concurrent.locks.ReadWriteLock;
|
37 | 36 | import java.util.concurrent.locks.ReentrantReadWriteLock;
|
38 |
| -import java.util.function.Supplier; |
39 | 37 |
|
40 | 38 | import org.neo4j.driver.Logger;
|
41 | 39 | import org.neo4j.driver.Logging;
|
|
54 | 52 | import static org.neo4j.driver.internal.async.connection.ChannelAttributes.setAuthorizationStateListener;
|
55 | 53 | import static org.neo4j.driver.internal.util.Futures.combineErrors;
|
56 | 54 | import static org.neo4j.driver.internal.util.Futures.completeWithNullIfNoError;
|
| 55 | +import static org.neo4j.driver.internal.util.LockUtil.executeWithLock; |
| 56 | +import static org.neo4j.driver.internal.util.LockUtil.executeWithLockAsync; |
57 | 57 |
|
58 | 58 | public class ConnectionPoolImpl implements ConnectionPool
|
59 | 59 | {
|
@@ -342,34 +342,4 @@ private CompletableFuture<Void> closeAllPools()
|
342 | 342 | } )
|
343 | 343 | .toArray( CompletableFuture[]::new ) );
|
344 | 344 | }
|
345 |
| - |
346 |
| - private void executeWithLock( Lock lock, Runnable runnable ) |
347 |
| - { |
348 |
| - executeWithLock( lock, () -> |
349 |
| - { |
350 |
| - runnable.run(); |
351 |
| - return null; |
352 |
| - } ); |
353 |
| - } |
354 |
| - |
355 |
| - private <T> T executeWithLock( Lock lock, Supplier<T> supplier ) |
356 |
| - { |
357 |
| - lock.lock(); |
358 |
| - try |
359 |
| - { |
360 |
| - return supplier.get(); |
361 |
| - } |
362 |
| - finally |
363 |
| - { |
364 |
| - lock.unlock(); |
365 |
| - } |
366 |
| - } |
367 |
| - |
368 |
| - private <T> void executeWithLockAsync( Lock lock, Supplier<CompletionStage<T>> stageSupplier ) |
369 |
| - { |
370 |
| - lock.lock(); |
371 |
| - CompletableFuture.completedFuture( lock ) |
372 |
| - .thenCompose( ignored -> stageSupplier.get() ) |
373 |
| - .whenComplete( ( ignored, throwable ) -> lock.unlock() ); |
374 |
| - } |
375 | 345 | }
|
0 commit comments