|
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 | {
|
@@ -344,34 +344,4 @@ private CompletableFuture<Void> closeAllPools()
|
344 | 344 | } )
|
345 | 345 | .toArray( CompletableFuture[]::new ) );
|
346 | 346 | }
|
347 |
| - |
348 |
| - private void executeWithLock( Lock lock, Runnable runnable ) |
349 |
| - { |
350 |
| - executeWithLock( lock, () -> |
351 |
| - { |
352 |
| - runnable.run(); |
353 |
| - return null; |
354 |
| - } ); |
355 |
| - } |
356 |
| - |
357 |
| - private <T> T executeWithLock( Lock lock, Supplier<T> supplier ) |
358 |
| - { |
359 |
| - lock.lock(); |
360 |
| - try |
361 |
| - { |
362 |
| - return supplier.get(); |
363 |
| - } |
364 |
| - finally |
365 |
| - { |
366 |
| - lock.unlock(); |
367 |
| - } |
368 |
| - } |
369 |
| - |
370 |
| - private <T> void executeWithLockAsync( Lock lock, Supplier<CompletionStage<T>> stageSupplier ) |
371 |
| - { |
372 |
| - lock.lock(); |
373 |
| - CompletableFuture.completedFuture( lock ) |
374 |
| - .thenCompose( ignored -> stageSupplier.get() ) |
375 |
| - .whenComplete( ( ignored, throwable ) -> lock.unlock() ); |
376 |
| - } |
377 | 347 | }
|
0 commit comments