gpt4 book ai didi

java - Hazelcast 异步客户端 - 检查 'CLIENT_CONNECTED' 状态

转载 作者:行者123 更新时间:2023-12-02 09:43:53 25 4
gpt4 key购买 nike

我需要检查 Hazelcast 客户端是否已连接到集群。

我尝试这样做的方式

ClientConfig clientConfig = new XmlClientConfigBuilder(xmlConfigurationFileName).build();

ClientStateListener clientStateListener = new ClientStateListener(clientConfig);
HazelcastInstance client = HazelcastClient.newHazelcastClient(clientConfig);

final boolean connected = clientStateListener.isConnected();
final boolean started = clientStateListener.isStarted();

isStarted 方法返回 true,但 isConnected 始终为 false。在 isConnected 检查之间,我从服务器集群中放入和获取数据,因此客户端肯定已连接(我也可以在日志中看到) - 另外当我将异步设置为 false (async-start="false") 时,然后 isConnected返回 true。

LifecycleServiceImpl Hazelcast 类在 fireLifecycleEvent 方法中包含这样的代码(当状态发生变化时在 HZ 中调用)

executor.execute(new Runnable() {
@Override
public void run() {
for (LifecycleListener lifecycleListener : lifecycleListeners.values()) {
lifecycleListener.stateChanged(lifecycleEvent);
}
}
});

在同步模式下,每次都会调用 run(两次 STARTING->STARTED 和 STARTED->CLIENT_CONNECTED)。仅异步一次(STARTING->STARTED)。

Hazelcast 版本 3.12.1。

这是整个配置(tcp-ip 的服务器发现策略)

<?xml version="1.0" encoding="UTF-8"?>

<hazelcast-client xmlns="http://www.hazelcast.com/schema/client-config"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.hazelcast.com/schema/client-config
http://www.hazelcast.com/schema/client-config/hazelcast-client-config-3.12.xsd">

<group>
<name>hazelcast-group</name>
</group>

<network>
<cluster-members>
<address>XXXXXXXXXXXXXXX:XXXX</address>
<address>XXXXXXXXXXXXXXX:XXXX</address>
<address>XXXXXXXXXXXXXXX:XXXX</address>
<address>XXXXXXXXXXXXXXX:XXXX</address>
</cluster-members>
</network>

<connection-strategy async-start="true" reconnect-mode="ASYNC">
<connection-retry enabled="true">
<initial-backoff-millis>2000</initial-backoff-millis>
<max-backoff-millis>60000</max-backoff-millis>
<multiplier>3</multiplier>
<fail-on-max-backoff>false</fail-on-max-backoff>
<jitter>0.5</jitter>
</connection-retry>
</connection-strategy>

</hazelcast-client>

应该怎样做才能强制CLIENT_CONNECTED状态发生statusChange?

最佳答案

Hazelcast 客户端运行的所有日志:

Jul 02, 2019 2:00:42 PM com.hazelcast.client.HazelcastClient
INFO: hz.client_0 [hazelcast-cache-group] [3.12.1] A non-empty group password is configured for the Hazelcast client. Starting with Hazelcast version 3.11, clients with the same group name, but with different group passwords (that do not use authentication) will be accepted to a cluster. The group password configuration will be removed completely in a future release.
Jul 02, 2019 2:00:43 PM com.hazelcast.client.spi.ClientInvocationService
INFO: hz.client_0 [hazelcast-cache-group] [3.12.1] Running with 2 response threads, dynamic=false
Jul 02, 2019 2:00:43 PM com.hazelcast.core.LifecycleService
INFO: hz.client_0 [hazelcast-cache-group] [3.12.1] HazelcastClient 3.12.1 (20190611 - 0a0ee66) is STARTING
Jul 02, 2019 2:00:43 PM com.hazelcast.core.LifecycleService
INFO: hz.client_0 [hazelcast-cache-group] [3.12.1] HazelcastClient 3.12.1 (20190611 - 0a0ee66) is STARTED
Jul 02, 2019 2:00:44 PM com.hazelcast.internal.diagnostics.Diagnostics
INFO: hz.client_0 [hazelcast-cache-group] [3.12.1] Diagnostics disabled. To enable add -Dhazelcast.diagnostics.enabled=true to the JVM arguments.
Jul 02, 2019 2:00:44 PM com.hazelcast.client.connection.nio.ClusterConnectorService
INFO: hz.client_0 [hazelcast-cache-group] [3.12.1] Trying to connect to cluster with name: hazelcast-cache-group
Jul 02, 2019 2:00:44 PM com.hazelcast.client.connection.nio.ClusterConnectorService
INFO: hz.client_0 [hazelcast-cache-group] [3.12.1] Trying to connect to [FFFFFFFFF]:PORTXXXX as owner member
Jul 02, 2019 2:00:44 PM com.hazelcast.client.connection.ClientConnectionManager
INFO: hz.client_0 [hazelcast-cache-group] [3.12.1] Setting ClientConnection{alive=true, connectionId=1, channel=NioChannel{/CLIENT-IP:58235->FFFFFFFFF/IPFFF:PORTXXXX}, remoteEndpoint=[FFFFFFFFF]:PORTXXXX, lastReadTime=2019-07-02 14:00:44.898, lastWriteTime=2019-07-02 14:00:44.711, closedTime=never, connected server version=3.12.1} as owner with principal ClientPrincipal{uuid='8090fecb-294f-4a4a-9da7-168bf0a7faff', ownerUuid='TOKEN-FFFFFFFFF'}
Jul 02, 2019 2:00:44 PM com.hazelcast.client.connection.ClientConnectionManager
INFO: hz.client_0 [hazelcast-cache-group] [3.12.1] Authenticated with server [FFFFFFFFF]:PORTXXXX, server version:3.12.1 Local address: /CLIENT-IP:58235
Jul 02, 2019 2:00:45 PM com.hazelcast.client.spi.impl.ClientMembershipListener
INFO: hz.client_0 [hazelcast-cache-group] [3.12.1]

Members [6] {
Member [AAAAAAAAA]:PORTXXXX - TOKEN-AAAAAAAAA
Member [BBBBBBBBB]:PORTXXXX - TOKEN-BBBBBBBBB
Member [CCCCCCCCC]:PORTXXXX - TOKEN-CCCCCCCCC
Member [DDDDDDDDD]:PORTXXXX - TOKEN-DDDDDDDDD
Member [EEEEEEEEE]:PORTXXXX - TOKEN-EEEEEEEEE
Member [FFFFFFFFF]:PORTXXXX - TOKEN-FFFFFFFFF
}

Jul 02, 2019 2:00:45 PM com.hazelcast.core.LifecycleService
INFO: hz.client_0 [hazelcast-cache-group] [3.12.1] HazelcastClient 3.12.1 (20190611 - 0a0ee66) is CLIENT_CONNECTED
Jul 02, 2019 2:00:45 PM com.hazelcast.client.connection.ClientConnectionManager
INFO: hz.client_0 [hazelcast-cache-group] [3.12.1] Authenticated with server [AAAAAAAAA]:PORTXXXX, server version:3.12.1 Local address: /CLIENT-IP:58238
Jul 02, 2019 2:00:45 PM com.hazelcast.client.connection.ClientConnectionManager
INFO: hz.client_0 [hazelcast-cache-group] [3.12.1] Authenticated with server [BBBBBBBBB]:PORTXXXX, server version:3.12.1 Local address: /CLIENT-IP:58236
Jul 02, 2019 2:00:45 PM com.hazelcast.client.connection.ClientConnectionManager
INFO: hz.client_0 [hazelcast-cache-group] [3.12.1] Authenticated with server [CCCCCCCCC]:PORTXXXX, server version:3.12.1 Local address: /CLIENT-IP:58237
Jul 02, 2019 2:00:45 PM com.hazelcast.client.connection.ClientConnectionManager
INFO: hz.client_0 [hazelcast-cache-group] [3.12.1] Authenticated with server [EEEEEEEEE]:PORTXXXX, server version:3.12.1 Local address: /CLIENT-IP:58240
Jul 02, 2019 2:00:45 PM com.hazelcast.client.connection.ClientConnectionManager
INFO: hz.client_0 [hazelcast-cache-group] [3.12.1] Authenticated with server [DDDDDDDDD]:PORTXXXX, server version:3.12.1 Local address: /CLIENT-IP:58239

关于java - Hazelcast 异步客户端 - 检查 'CLIENT_CONNECTED' 状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56834908/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com