Skip to content

Commit 798b4a0

Browse files
committed
Added some javadocs
1 parent f40118c commit 798b4a0

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@
2121
import org.neo4j.driver.internal.net.BoltServerAddress;
2222
import org.neo4j.driver.internal.spi.ConnectionPool;
2323

24+
/**
25+
* Load balancing strategy that finds server with least amount of active (checked out of the pool) connections from
26+
* given readers or writers. It finds a start index for iteration in a round-robin fashion. This is done to prevent
27+
* choosing same first address over and over when all addresses have same amount of active connections.
28+
*/
2429
public class LeastConnectedLoadBalancingStrategy implements LoadBalancingStrategy
2530
{
2631
private final RoundRobinArrayIndex readersIndex = new RoundRobinArrayIndex();
@@ -53,12 +58,14 @@ private BoltServerAddress select( BoltServerAddress[] addresses, RoundRobinArray
5358
return null;
5459
}
5560

61+
// choose start index for iteration in round-rodin fashion
5662
int startIndex = addressesIndex.next( size );
5763
int index = startIndex;
5864

5965
BoltServerAddress leastConnectedAddress = null;
6066
int leastActiveConnections = Integer.MAX_VALUE;
6167

68+
// iterate over the array to find least connected address
6269
do
6370
{
6471
BoltServerAddress address = addresses[index];
@@ -70,6 +77,7 @@ private BoltServerAddress select( BoltServerAddress[] addresses, RoundRobinArray
7077
leastActiveConnections = activeConnections;
7178
}
7279

80+
// loop over to the start of the array when end is reached
7381
if ( index == size - 1 )
7482
{
7583
index = 0;

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,24 @@
2020

2121
import org.neo4j.driver.internal.net.BoltServerAddress;
2222

23+
/**
24+
* A facility to select most appropriate reader or writer among the given addresses for request processing.
25+
*/
2326
public interface LoadBalancingStrategy
2427
{
28+
/**
29+
* Select most appropriate read address from the given array of addresses.
30+
*
31+
* @param knownReaders array of all known readers.
32+
* @return most appropriate reader or {@code null} if it can't be selected.
33+
*/
2534
BoltServerAddress selectReader( BoltServerAddress[] knownReaders );
2635

36+
/**
37+
* Select most appropriate write address from the given array of addresses.
38+
*
39+
* @param knownWriters array of all known writers.
40+
* @return most appropriate writer or {@code null} if it can't be selected.
41+
*/
2742
BoltServerAddress selectWriter( BoltServerAddress[] knownWriters );
2843
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@
2020

2121
import org.neo4j.driver.internal.net.BoltServerAddress;
2222

23+
/**
24+
* Load balancing strategy that selects addresses in round-robin fashion. It maintains separate indices for readers and
25+
* writers.
26+
*/
2327
public class RoundRobinLoadBalancingStrategy implements LoadBalancingStrategy
2428
{
2529
private final RoundRobinArrayIndex readersIndex = new RoundRobinArrayIndex();

0 commit comments

Comments
 (0)