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

Re-use RestClient across DataStores ... only need 1 per host:port:user #113

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

halfstein
Copy link

OK, starting with smaller simpler updates and I'll see how the Travis CI goes.

Copy link
Contributor

@sjudeng sjudeng left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the updates. Couple minor comments and question.

final String clientKey = String.format("%s @ %s:%d", user, hostName, defaultPort);

/* if we already have the client ... just return it so we don't needlessly create the builder */
if(clients.containsKey(clientKey))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you include {} for consistency? Also include space after if for consistency.

return clients.get(clientKey);

/* creating the builder can throw IOException so we can't do it in the following functional call */
RestClientBuilder rcb = createClientBuilder(user, password, type, hostName.split(","), defaultPort, sslRejectUnauthorized);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this block can be unindented

@@ -136,6 +137,15 @@
GRID_THRESHOLD
};

/**
* The ES RestClient instances created by this factory. We don't want to create
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can unindent these comment lines by two spaces for consistency with other formatting elsewhere

final String adminUser = getValue(USER, params);
final boolean sslRejectUnauthorized = getValue(SSL_REJECT_UNAUTHORIZED, params);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does changing these to primitives make them required parameters?

@@ -192,6 +192,47 @@ public void testBuildClientWithMultipleHosts() throws IOException {
assertNotNull(credentialsProviderCaptor.getValue().getCredentials(new AuthScope("localhost2", 9201)));
}

@Test
public void testGetRestClientSameClientKey() throws IOException {
/* multiple calls with same host:port:user should call builder once */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indentation here and below


/* note: ConcurrentHashMap performs this atomically ... only once per key */
return this.clients.computeIfAbsent(clientKey, (key) -> {
LOGGER.info(String.format("Building a %s RestClient for", type, key));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this missing a format string for key?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants