Skip to content

Commit 6c17025

Browse files
committed
Replace AddressSet with standard Java collections (neo4j#1037)
* Replace AddressSet with standard Java collections This update also prevents unnecessary connection pool closures by keeping `disused` addresses until next routing table update and reusing them. * Update reader, writer and router addresses handling and change type
1 parent c919874 commit 6c17025

File tree

16 files changed

+272
-536
lines changed

16 files changed

+272
-536
lines changed

driver/src/main/java/org/neo4j/driver/internal/async/pool/ConnectionPoolImpl.java

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,8 @@
3232
import java.util.concurrent.TimeUnit;
3333
import java.util.concurrent.TimeoutException;
3434
import java.util.concurrent.atomic.AtomicBoolean;
35-
import java.util.concurrent.locks.Lock;
3635
import java.util.concurrent.locks.ReadWriteLock;
3736
import java.util.concurrent.locks.ReentrantReadWriteLock;
38-
import java.util.function.Supplier;
3937

4038
import org.neo4j.driver.Logger;
4139
import org.neo4j.driver.Logging;
@@ -54,6 +52,8 @@
5452
import static org.neo4j.driver.internal.async.connection.ChannelAttributes.setAuthorizationStateListener;
5553
import static org.neo4j.driver.internal.util.Futures.combineErrors;
5654
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;
5757

5858
public class ConnectionPoolImpl implements ConnectionPool
5959
{
@@ -344,34 +344,4 @@ private CompletableFuture<Void> closeAllPools()
344344
} )
345345
.toArray( CompletableFuture[]::new ) );
346346
}
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-
}
377347
}

driver/src/main/java/org/neo4j/driver/internal/cluster/AddressSet.java

Lines changed: 0 additions & 113 deletions
This file was deleted.

0 commit comments

Comments
 (0)