Skip to content

Commit 0de7d22

Browse files
author
Zhen Li
committed
Renamed a few classes and added more java docs
1 parent 71ec73c commit 0de7d22

File tree

8 files changed

+50
-51
lines changed

8 files changed

+50
-51
lines changed

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

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public class RoutingTableHandler implements RoutingErrorHandler
3636
{
3737
private final RoutingTable routingTable;
3838
private final String databaseName;
39-
private final RoutingTables routingTables;
39+
private final RoutingTableRegistry routingTableRegistry;
4040
private volatile CompletableFuture<RoutingTable> refreshRoutingTableFuture;
4141
private final ConnectionPool connectionPool;
4242
private final Rediscovery rediscovery;
@@ -46,14 +46,13 @@ public class RoutingTableHandler implements RoutingErrorHandler
4646
// TODO make this a configuration option
4747
public static final Duration STALE_ROUTING_TABLE_PURGE_TIMEOUT = Duration.ofSeconds( 30 );
4848

49-
50-
public RoutingTableHandler( RoutingTable routingTable, Rediscovery rediscovery, ConnectionPool connectionPool, RoutingTables routingTables, Logger log )
49+
public RoutingTableHandler( RoutingTable routingTable, Rediscovery rediscovery, ConnectionPool connectionPool, RoutingTableRegistry routingTableRegistry, Logger log )
5150
{
5251
this.routingTable = routingTable;
5352
this.databaseName = routingTable.database();
5453
this.rediscovery = rediscovery;
5554
this.connectionPool = connectionPool;
56-
this.routingTables = routingTables;
55+
this.routingTableRegistry = routingTableRegistry;
5756
this.log = log;
5857
}
5958

@@ -113,8 +112,8 @@ private synchronized void freshClusterCompositionFetched( ClusterComposition com
113112
try
114113
{
115114
routingTable.update( composition );
116-
routingTables.purgeAged();
117-
connectionPool.retainAll( routingTables.allServers() );
115+
routingTableRegistry.purgeAged();
116+
connectionPool.retainAll( routingTableRegistry.allServers() );
118117

119118
log.info( "Updated routing table for database '%s'. %s", databaseName, routingTable );
120119

@@ -131,7 +130,7 @@ private synchronized void freshClusterCompositionFetched( ClusterComposition com
131130
private synchronized void clusterCompositionLookupFailed( Throwable error )
132131
{
133132
log.error( String.format( "Failed to update routing table for database '%s'. Current routing table: %s.", databaseName, routingTable ), error );
134-
routingTables.remove( databaseName );
133+
routingTableRegistry.remove( databaseName );
135134
CompletableFuture<RoutingTable> routingTableFuture = refreshRoutingTableFuture;
136135
refreshRoutingTableFuture = null;
137136
routingTableFuture.completeExceptionally( error );

driver/src/main/java/org/neo4j/driver/internal/cluster/RoutingTables.java renamed to driver/src/main/java/org/neo4j/driver/internal/cluster/RoutingTableRegistry.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,22 +28,22 @@
2828
* A generic interface to access all routing tables as a whole.
2929
* It also provides methods to obtain a routing table or manage a routing table for a specified database.
3030
*/
31-
public interface RoutingTables
31+
public interface RoutingTableRegistry
3232
{
3333
/**
34-
* Fresh the routing table for the database and given access mode.
35-
* For server version lower than 4.0, the database name will be ignored while refresh routing table.
34+
* Fresh the routing table for the database with given access mode.
35+
* For server version lower than 4.0, the database name will be ignored while refreshing routing table.
3636
* @return The future of a new routing table handler.
3737
*/
3838
CompletionStage<RoutingTableHandler> refreshRoutingTable( String databaseName, AccessMode mode );
3939

4040
/**
41-
* @return all servers in all routing tables
41+
* @return all servers in the registry
4242
*/
4343
Set<BoltServerAddress> allServers();
4444

4545
/**
46-
* Removes a routing table of the given database from all tables.
46+
* Removes a routing table of the given database from registry.
4747
*/
4848
void remove( String databaseName );
4949

driver/src/main/java/org/neo4j/driver/internal/cluster/RoutingTablesImpl.java renamed to driver/src/main/java/org/neo4j/driver/internal/cluster/RoutingTableRegistryImpl.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,18 @@
3030
import org.neo4j.driver.internal.spi.ConnectionPool;
3131
import org.neo4j.driver.internal.util.Clock;
3232

33-
public class RoutingTablesImpl implements RoutingTables
33+
public class RoutingTableRegistryImpl implements RoutingTableRegistry
3434
{
3535
private final ConcurrentMap<String,RoutingTableHandler> routingTables;
3636
private final RoutingTableHandlerFactory factory;
3737
private final Logger logger;
3838

39-
public RoutingTablesImpl( ConnectionPool connectionPool, Rediscovery rediscovery, Clock clock, Logger logger )
39+
public RoutingTableRegistryImpl( ConnectionPool connectionPool, Rediscovery rediscovery, Clock clock, Logger logger )
4040
{
4141
this( new ConcurrentHashMap<>(), new RoutingTableHandlerFactory( connectionPool, rediscovery, clock, logger ), logger );
4242
}
4343

44-
RoutingTablesImpl( ConcurrentMap<String,RoutingTableHandler> routingTables, RoutingTableHandlerFactory factory, Logger logger )
44+
RoutingTableRegistryImpl( ConcurrentMap<String,RoutingTableHandler> routingTables, RoutingTableHandlerFactory factory, Logger logger )
4545
{
4646
this.factory = factory;
4747
this.routingTables = routingTables;
@@ -118,7 +118,7 @@ static class RoutingTableHandlerFactory
118118
this.log = log;
119119
}
120120

121-
RoutingTableHandler newInstance( String databaseName, RoutingTables allTables )
121+
RoutingTableHandler newInstance( String databaseName, RoutingTableRegistry allTables )
122122
{
123123
ClusterRoutingTable routingTable = new ClusterRoutingTable( databaseName, clock );
124124
return new RoutingTableHandler( routingTable, rediscovery, connectionPool, allTables, log );

driver/src/main/java/org/neo4j/driver/internal/cluster/loadbalancing/LoadBalancer.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@
3737
import org.neo4j.driver.internal.cluster.RoutingProcedureClusterCompositionProvider;
3838
import org.neo4j.driver.internal.cluster.RoutingSettings;
3939
import org.neo4j.driver.internal.cluster.RoutingTable;
40-
import org.neo4j.driver.internal.cluster.RoutingTables;
41-
import org.neo4j.driver.internal.cluster.RoutingTablesImpl;
40+
import org.neo4j.driver.internal.cluster.RoutingTableRegistry;
41+
import org.neo4j.driver.internal.cluster.RoutingTableRegistryImpl;
4242
import org.neo4j.driver.internal.spi.Connection;
4343
import org.neo4j.driver.internal.spi.ConnectionPool;
4444
import org.neo4j.driver.internal.spi.ConnectionProvider;
@@ -53,7 +53,7 @@ public class LoadBalancer implements ConnectionProvider
5353
{
5454
private static final String LOAD_BALANCER_LOG_NAME = "LoadBalancer";
5555
private final ConnectionPool connectionPool;
56-
private final RoutingTables routingTables;
56+
private final RoutingTableRegistry routingTables;
5757
private final LoadBalancingStrategy loadBalancingStrategy;
5858
private final EventExecutorGroup eventExecutorGroup;
5959
private final Logger log;
@@ -66,7 +66,7 @@ public LoadBalancer( BoltServerAddress initialRouter, RoutingSettings settings,
6666
loadBalancerLogger( logging ), loadBalancingStrategy, eventExecutorGroup );
6767
}
6868

69-
LoadBalancer( ConnectionPool connectionPool, RoutingTables routingTables, Logger log, LoadBalancingStrategy loadBalancingStrategy,
69+
LoadBalancer( ConnectionPool connectionPool, RoutingTableRegistry routingTables, Logger log, LoadBalancingStrategy loadBalancingStrategy,
7070
EventExecutorGroup eventExecutorGroup )
7171
{
7272
this.connectionPool = connectionPool;
@@ -168,12 +168,12 @@ private BoltServerAddress selectAddress( AccessMode mode, AddressSet servers )
168168
}
169169
}
170170

171-
private static RoutingTables createRoutingTables( ConnectionPool connectionPool, EventExecutorGroup eventExecutorGroup, BoltServerAddress initialRouter,
171+
private static RoutingTableRegistry createRoutingTables( ConnectionPool connectionPool, EventExecutorGroup eventExecutorGroup, BoltServerAddress initialRouter,
172172
ServerAddressResolver resolver, RoutingSettings settings, Clock clock, Logging logging )
173173
{
174174
Logger log = loadBalancerLogger( logging );
175175
Rediscovery rediscovery = createRediscovery( eventExecutorGroup, initialRouter, resolver, settings, clock, log );
176-
return new RoutingTablesImpl( connectionPool, rediscovery, clock, log );
176+
return new RoutingTableRegistryImpl( connectionPool, rediscovery, clock, log );
177177
}
178178

179179
private static Rediscovery createRediscovery( EventExecutorGroup eventExecutorGroup, BoltServerAddress initialRouter, ServerAddressResolver resolver,

driver/src/test/java/org/neo4j/driver/internal/cluster/RoutingTableHandlerTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ void shouldRetainAllFetchedAddressesInConnectionPoolAfterFetchingOfRoutingTable(
155155
when( rediscovery.lookupClusterComposition( any(), any() ) ).thenReturn( completedFuture(
156156
new ClusterComposition( 42, asOrderedSet( A, B ), asOrderedSet( B, C ), asOrderedSet( A, C ) ) ) );
157157

158-
RoutingTables routingTables = new RoutingTables()
158+
RoutingTableRegistry routingTables = new RoutingTableRegistry()
159159
{
160160
@Override
161161
public CompletionStage<RoutingTableHandler> refreshRoutingTable( String databaseName, AccessMode mode )
@@ -200,7 +200,7 @@ void shouldRemoveRoutingTableHandlerIfFailedToLookup() throws Throwable
200200
when( rediscovery.lookupClusterComposition( any(), any() ) ).thenReturn( Futures.failedFuture( new RuntimeException( "Bang!" ) ) );
201201

202202
ConnectionPool connectionPool = newConnectionPoolMock();
203-
RoutingTables routingTables = newRoutingTablesMock();
203+
RoutingTableRegistry routingTables = newRoutingTablesMock();
204204
// When
205205

206206
RoutingTableHandler handler = new RoutingTableHandler( routingTable, rediscovery, connectionPool, routingTables, DEV_NULL_LOGGER );
@@ -258,9 +258,9 @@ private static RoutingTable newStaleRoutingTableMock( AccessMode mode )
258258
return routingTable;
259259
}
260260

261-
private static RoutingTables newRoutingTablesMock()
261+
private static RoutingTableRegistry newRoutingTablesMock()
262262
{
263-
return mock( RoutingTables.class );
263+
return mock( RoutingTableRegistry.class );
264264
}
265265

266266
private static Rediscovery newRediscoveryMock()

driver/src/test/java/org/neo4j/driver/internal/cluster/RoutingTablesImplTest.java renamed to driver/src/test/java/org/neo4j/driver/internal/cluster/RoutingTableRegistryImplTest.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232

3333
import org.neo4j.driver.AccessMode;
3434
import org.neo4j.driver.internal.BoltServerAddress;
35-
import org.neo4j.driver.internal.cluster.RoutingTablesImpl.RoutingTableHandlerFactory;
35+
import org.neo4j.driver.internal.cluster.RoutingTableRegistryImpl.RoutingTableHandlerFactory;
3636
import org.neo4j.driver.internal.spi.ConnectionPool;
3737
import org.neo4j.driver.internal.util.Clock;
3838

@@ -60,7 +60,7 @@
6060
import static org.neo4j.driver.internal.util.ClusterCompositionUtil.F;
6161
import static org.neo4j.driver.util.TestUtil.await;
6262

63-
class RoutingTablesImplTest
63+
class RoutingTableRegistryImplTest
6464
{
6565
@Test
6666
void factoryShouldCreateARoutingTableWithSameDatabaseName() throws Throwable
@@ -91,7 +91,7 @@ void shouldCreateRoutingTableHandlerIfAbsentWhenFreshRoutingTable( String databa
9191
// Given
9292
ConcurrentMap<String,RoutingTableHandler> map = new ConcurrentHashMap<>();
9393
RoutingTableHandlerFactory factory = mockedHandlerFactory();
94-
RoutingTablesImpl routingTables = newRoutingTables( map, factory );
94+
RoutingTableRegistryImpl routingTables = newRoutingTables( map, factory );
9595

9696
// When
9797
routingTables.refreshRoutingTable( databaseName, AccessMode.READ );
@@ -111,7 +111,7 @@ void shouldReturnExistingRoutingTableHandlerWhenFreshRoutingTable( String databa
111111
map.put( databaseName, handler );
112112

113113
RoutingTableHandlerFactory factory = mockedHandlerFactory();
114-
RoutingTablesImpl routingTables = newRoutingTables( map, factory );
114+
RoutingTableRegistryImpl routingTables = newRoutingTables( map, factory );
115115

116116
// When
117117
RoutingTableHandler actual = await( routingTables.refreshRoutingTable( databaseName, AccessMode.READ ) );
@@ -130,7 +130,7 @@ void shouldReturnFreshRoutingTable( AccessMode mode ) throws Throwable
130130
ConcurrentMap<String,RoutingTableHandler> map = new ConcurrentHashMap<>();
131131
RoutingTableHandler handler = mockedRoutingTableHandler();
132132
RoutingTableHandlerFactory factory = mockedHandlerFactory( handler );
133-
RoutingTablesImpl routingTables = new RoutingTablesImpl( map, factory, DEV_NULL_LOGGER );
133+
RoutingTableRegistryImpl routingTables = new RoutingTableRegistryImpl( map, factory, DEV_NULL_LOGGER );
134134

135135
// When
136136
routingTables.refreshRoutingTable( ABSENT_DB_NAME, mode );
@@ -148,7 +148,7 @@ void shouldReturnServersInAllRoutingTables() throws Throwable
148148
map.put( "Banana", mockedRoutingTableHandler( B, C, D ) );
149149
map.put( "Orange", mockedRoutingTableHandler( E, F, C ) );
150150
RoutingTableHandlerFactory factory = mockedHandlerFactory();
151-
RoutingTablesImpl routingTables = new RoutingTablesImpl( map, factory, DEV_NULL_LOGGER );
151+
RoutingTableRegistryImpl routingTables = new RoutingTableRegistryImpl( map, factory, DEV_NULL_LOGGER );
152152

153153
// When
154154
Set<BoltServerAddress> servers = routingTables.allServers();
@@ -167,7 +167,7 @@ void shouldRemoveRoutingTableHandler() throws Throwable
167167
map.put( "Orange", mockedRoutingTableHandler( C ) );
168168

169169
RoutingTableHandlerFactory factory = mockedHandlerFactory();
170-
RoutingTablesImpl routingTables = newRoutingTables( map, factory );
170+
RoutingTableRegistryImpl routingTables = newRoutingTables( map, factory );
171171

172172
// When
173173
routingTables.remove( "Apple" );
@@ -185,7 +185,7 @@ void shouldRemoveStatleRoutingTableHandlers() throws Throwable
185185
map.put( "Orange", mockedRoutingTableHandler( C ) );
186186

187187
RoutingTableHandlerFactory factory = mockedHandlerFactory();
188-
RoutingTablesImpl routingTables = newRoutingTables( map, factory );
188+
RoutingTableRegistryImpl routingTables = newRoutingTables( map, factory );
189189

190190
// When
191191
routingTables.purgeAged();
@@ -201,9 +201,9 @@ private RoutingTableHandler mockedRoutingTableHandler( BoltServerAddress... serv
201201
return handler;
202202
}
203203

204-
private RoutingTablesImpl newRoutingTables( ConcurrentMap<String,RoutingTableHandler> handlers, RoutingTableHandlerFactory factory )
204+
private RoutingTableRegistryImpl newRoutingTables( ConcurrentMap<String,RoutingTableHandler> handlers, RoutingTableHandlerFactory factory )
205205
{
206-
return new RoutingTablesImpl( handlers, factory, DEV_NULL_LOGGER );
206+
return new RoutingTableRegistryImpl( handlers, factory, DEV_NULL_LOGGER );
207207
}
208208

209209
private RoutingTableHandlerFactory mockedHandlerFactory( RoutingTableHandler handler )

driver/src/test/java/org/neo4j/driver/internal/cluster/loadbalancing/LoadBalancerTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
import org.neo4j.driver.internal.cluster.ClusterRoutingTable;
4141
import org.neo4j.driver.internal.cluster.RoutingTable;
4242
import org.neo4j.driver.internal.cluster.RoutingTableHandler;
43-
import org.neo4j.driver.internal.cluster.RoutingTables;
43+
import org.neo4j.driver.internal.cluster.RoutingTableRegistry;
4444
import org.neo4j.driver.internal.spi.Connection;
4545
import org.neo4j.driver.internal.spi.ConnectionPool;
4646
import org.neo4j.driver.internal.util.FakeClock;
@@ -229,7 +229,7 @@ private static ConnectionPool newConnectionPoolMockWithFailures(
229229
private static LoadBalancer newLoadBalancer( ConnectionPool connectionPool, RoutingTable routingTable )
230230
{
231231
// Used only in testing
232-
RoutingTables routingTables = mock( RoutingTables.class );
232+
RoutingTableRegistry routingTables = mock( RoutingTableRegistry.class );
233233
RoutingTableHandler handler = mock( RoutingTableHandler.class );
234234
when( handler.routingTable() ).thenReturn( routingTable );
235235
when( routingTables.refreshRoutingTable( any( String.class ), any( AccessMode.class ) ) ).thenReturn( CompletableFuture.completedFuture( handler ) );

0 commit comments

Comments
 (0)