Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JAVA: fix linting issues #49

Merged
merged 1 commit into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading