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

Enabled ClientStateListener to be used on FailoverClient #19090

Conversation

sancar
Copy link
Contributor

@sancar sancar commented Jul 14, 2021

Due to nature of how failover client works, we don't allow different
listeners to be registered at different client configs.

Since ClientStateListener registers itself to the ClientConfig,
this prevents it to be used via FailoverClient.

The reasoning behind constructor register itself is to force the
user to use this via config rather than registering it after client
starts.

So, sticking with the same decision we introduce another constructor
which accepts ClientFailoverConfig and registers same listener(itself)
to all the client configs.

Also on the ClientStateListener I have ignored CLIENT_CHANGED_CLUSTER.
This is rather a temporal event. We fire CLIENT_CONNECTED than
CLIENT_CHANGED_CLUSTER, in those cases we want the current state to
remain CLIENT_CONNECTED.

Fixes #18351

EE PR: https://github.com/hazelcast/hazelcast-enterprise/pull/4142

Checklist:

  • Labels (Team:, Type:, Source:, Module:) and Milestone set
  • Add Add to Release Notes label if changes should be mentioned in release notes or Not Release Notes content if changes are not relevant for release notes
  • Request reviewers if possible
  • New public APIs have @Nonnull/@Nullable annotations
  • New public APIs have @since tags in Javadoc
  • Send backports/forwardports if fix needs to be applied to past/future releases

Due to nature of how failover client works, we don't allow different
listeners to be registered at different client configs.

Since ClientStateListener registers itself to the ClientConfig,
this prevents it to be used via FailoverClient.

The reasoning behind constructor register itself is to force the
user to use this via config rather than registering it after client
starts.

So, sticking with the same decision we introduce another constructor
which accepts ClientFailoverConfig and registers same listener(itself)
to all the client configs.

Also on the ClientStateListener I have ignored `CLIENT_CHANGED_CLUSTER`.
This is rather a temporal event. We fire CLIENT_CONNECTED than
CLIENT_CHANGED_CLUSTER, in those cases we want the current state to
remain CLIENT_CONNECTED.

fixes hazelcast#18351
public ClientStateListener(@Nonnull ClientFailoverConfig clientFailoverConfig) {
List<ClientConfig> clientConfigs = clientFailoverConfig.getClientConfigs();
for (ClientConfig clientConfig : clientConfigs) {
clientConfig.addListenerConfig(new ListenerConfig(this));
Copy link
Member

Choose a reason for hiding this comment

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

asking to be sure, I think the problem is resolved since the listeners registered to each config is the same object here, isn't it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes.

for (ClientConfig clientConfig : clientConfigs) {
clientConfig.addListenerConfig(new ListenerConfig(this));
}

Copy link
Member

Choose a reason for hiding this comment

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

nit: you might delete this line

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Add to Release Notes All Languages Should Check Used by clients team to track fixes on the java client that should potentially backported to others Source: Internal PR or issue was opened by an employee Team: Client Type: Defect
Projects
None yet
Development

Successfully merging this pull request may close these issues.

com.hazelcast.client.util.ClientStateListener doesn't work well with failover client
3 participants