Skip to content

Conversation

@marvin-we
Copy link
Contributor

@marvin-we marvin-we commented Sep 10, 2020

Based on #15 - Review and merge that one first!

Fixes #21

Refactors both Singletons ('HiveJConfig' and 'ConnectionManager') to:

  • Protect them from reflection by throwing a RuntimeException in case the constructor is called again
  • Make the 'getInstance' method 'synchronized'.
    There is one difference between both Singletons now: 'HiveJConfig' now uses eager initialization, as with Allow to specifiy multiple endpoints and loadbalance requests between them #15, the HiveJConfig is the only place that adds endpoints to the ConnectionManager so it always needs to be initialized (solves the fixme in the tests too). The 'ConnectionManager' is still "lazy loading".

The following points are open for discussion:

Comment on lines 40 to 42
private int nextClient;
/** The list of endpoints known to the ConnectionManager. */
private CopyOnWriteArrayList<AbstractClient> clients;
Copy link
Collaborator

Choose a reason for hiding this comment

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

we may think about starting member variables with prefix m?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the default SQ rule for member variables https://rules.sonarsource.com/java/tag/convention/RSPEC-116 whose regex does not enforce this by default.

I still see the benefit of it (and we should agree on something for sure :P) - So should I update the rule?

Copy link
Collaborator

Choose a reason for hiding this comment

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

i dont't mind - as it is less effort lets stick to the already configured rule.

public class HttpClient implements AbstractClient {
public class HttpClient extends AbstractClient {
private static final Logger LOGGER = LoggerFactory.getLogger(HttpClient.class);
private final String CLIENT_ID;
Copy link
Collaborator

Choose a reason for hiding this comment

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

why is CLIENT_ID uppercase? shouldnt it match the usual regex pattern?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

'final' variables should be uppercase, no?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Even Sonar complains about that one - with the rule you just stated above (https://rules.sonarsource.com/java/tag/convention/RSPEC-116). Writing final variables uppercase is fine to me, but could introduce a rule for that to make sonar happy?

@marvin-we
Copy link
Contributor Author

Changes since last review:

@sonarqubecloud
Copy link

SonarCloud Quality Gate failed.

Bug B 2 Bugs
Vulnerability A 0 Vulnerabilities (and Security Hotspot 0 Security Hotspots to review)
Code Smell B 2 Code Smells

72.0% 72.0% Coverage
0.0% 0.0% Duplication

warning The version of Java (1.8.0_265) you have used to run this analysis is deprecated and we will stop accepting it from October 2020. Please update to at least Java 11.
Read more here

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.

Refactor singletons

4 participants