Skip to content

Commit

Permalink
JAVA: fix linting issues
Browse files Browse the repository at this point in the history
  • Loading branch information
dkropachev committed Jan 10, 2025
1 parent a83d1e4 commit 3af626b
Show file tree
Hide file tree
Showing 8 changed files with 880 additions and 710 deletions.
10 changes: 9 additions & 1 deletion .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ on:
push:
branches:
- master
paths:
- 'java/*'
pull_request:
paths:
- 'java/*'

jobs:
compile:
Expand All @@ -19,5 +23,9 @@ jobs:
distribution: temurin
java-version: 8
cache: maven

- name: Compile Tests
run: mvn test-compile
run: make compile compile-test

- name: Validate
run: make verify
20 changes: 20 additions & 0 deletions java/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
clean:
mvn clean

verify:
mvn verify
mvn javadoc:test-javadoc
mvn javadoc:test-aggregate
mvn javadoc:test-jar
mvn javadoc:test-resource-bundle

fix:
mvn com.coveo:fmt-maven-plugin:format
echo y | mvn javadoc:fix
echo y | mvn javadoc:test-fix

compile:
mvn compile

compile-test:
mvn test-compile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Level;
import java.util.logging.Logger;

import software.amazon.awssdk.endpoints.Endpoint;
import software.amazon.awssdk.services.dynamodb.endpoints.DynamoDbEndpointParams;
import software.amazon.awssdk.services.dynamodb.endpoints.DynamoDbEndpointProvider;
Expand All @@ -16,42 +15,63 @@
// AlternatorEndpointProvider, which maintains up-to-date knowledge of the
// live nodes in Alternator data center (by holding a AlternatorLiveNodes
// object), and choose a different node for each request.
/**
* AlternatorEndpointProvider class.
*
* @author dmitry.kropachev
*/
public class AlternatorEndpointProvider implements DynamoDbEndpointProvider {
private final AlternatorLiveNodes liveNodes;
private final Map<URI, CompletableFuture<Endpoint>> futureCache;
private static Logger logger = Logger.getLogger(AlternatorEndpointProvider.class.getName());
private final AlternatorLiveNodes liveNodes;
private final Map<URI, CompletableFuture<Endpoint>> futureCache;
private static Logger logger = Logger.getLogger(AlternatorEndpointProvider.class.getName());

public AlternatorEndpointProvider(URI seedURI) {
this(seedURI, "", "");
}
/**
* Constructor for AlternatorEndpointProvider.
*
* @param seedURI a {@link java.net.URI} object
*/
public AlternatorEndpointProvider(URI seedURI) {
this(seedURI, "", "");
}

public AlternatorEndpointProvider(URI seedURI, String datacenter, String rack) {
futureCache = new ConcurrentHashMap<>();
liveNodes = new AlternatorLiveNodes(seedURI, datacenter, rack);
try {
liveNodes.validate();
liveNodes.checkIfRackAndDatacenterSetCorrectly();
if (!datacenter.isEmpty() || !rack.isEmpty()) {
if (!liveNodes.checkIfRackDatacenterFeatureIsSupported()) {
logger.log(Level.SEVERE, String.format("server %s does not support rack or datacenter filtering", seedURI));
}
}
} catch (AlternatorLiveNodes.ValidationError | AlternatorLiveNodes.FailedToCheck e) {
throw new RuntimeException(e);
/**
* Constructor for AlternatorEndpointProvider.
*
* @param seedURI a {@link java.net.URI} object
* @param datacenter a {@link java.lang.String} object
* @param rack a {@link java.lang.String} object
* @since 1.0.1
*/
public AlternatorEndpointProvider(URI seedURI, String datacenter, String rack) {
futureCache = new ConcurrentHashMap<>();
liveNodes = new AlternatorLiveNodes(seedURI, datacenter, rack);
try {
liveNodes.validate();
liveNodes.checkIfRackAndDatacenterSetCorrectly();
if (!datacenter.isEmpty() || !rack.isEmpty()) {
if (!liveNodes.checkIfRackDatacenterFeatureIsSupported()) {
logger.log(
Level.SEVERE,
String.format("server %s does not support rack or datacenter filtering", seedURI));
}
liveNodes.start();
}
}
} catch (AlternatorLiveNodes.ValidationError | AlternatorLiveNodes.FailedToCheck e) {
throw new RuntimeException(e);
}
liveNodes.start();
}

@Override
public CompletableFuture<Endpoint> resolveEndpoint(DynamoDbEndpointParams endpointParams) {
URI uri = liveNodes.nextAsURI();
CompletableFuture<Endpoint> endpoint = futureCache.getOrDefault(uri, null);
if (endpoint != null) {
return endpoint;
}
endpoint = new CompletableFuture<>();
endpoint.complete(Endpoint.builder().url(uri).build());
futureCache.put(uri, endpoint);
return endpoint;
}
/** {@inheritDoc} */
@Override
public CompletableFuture<Endpoint> resolveEndpoint(DynamoDbEndpointParams endpointParams) {
URI uri = liveNodes.nextAsURI();
CompletableFuture<Endpoint> endpoint = futureCache.getOrDefault(uri, null);
if (endpoint != null) {
return endpoint;
}
endpoint = new CompletableFuture<>();
endpoint.complete(Endpoint.builder().url(uri).build());
futureCache.put(uri, endpoint);
return endpoint;
}
}
Loading

0 comments on commit 3af626b

Please sign in to comment.