Hazelcast client connection status

622 views
Skip to first unread message

Allen Zhao

unread,
Mar 8, 2012, 11:22:14 AM3/8/12
to Hazelcast
Is it possible to expose client connection status (connected/
disconnected) from a member to the applications which using HC?

We have an applications in which the members really need to know what
clients are connected/disconnected to/from them?

Thanks.

Fuad Malikov

unread,
Mar 8, 2012, 11:28:22 AM3/8/12
to haze...@googlegroups.com
with 2.0 you can. 

Hazelcast.getClientService().addClientListener(new ClientListener(){
    public void clientConnected(Client client){

    }

    public void clientDisconnected(Client client){
    
    }
}
});

-fuad



--
You received this message because you are subscribed to the Google Groups "Hazelcast" group.
To post to this group, send email to haze...@googlegroups.com.
To unsubscribe from this group, send email to hazelcast+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/hazelcast?hl=en.


Allen Zhao

unread,
Mar 8, 2012, 11:57:25 AM3/8/12
to Hazelcast
It's so great.

Thank you so much, Faud.

On Mar 8, 11:28 am, Fuad Malikov <f...@hazelcast.com> wrote:
> with 2.0 you can.
>
> Hazelcast.getClientService().addClientListener(new ClientListener(){
>     public void clientConnected(Client client){
>
>     }
>
>     public void clientDisconnected(Client client){
>
>     }
>
> }
> });
>
> -fuad
>

Allen Zhao

unread,
Mar 8, 2012, 12:05:10 PM3/8/12
to Hazelcast
I just tried from HC2.0.1, there is no method getClientService() from
Hazelcast.


On Mar 8, 11:28 am, Fuad Malikov <f...@hazelcast.com> wrote:
> with 2.0 you can.
>
> Hazelcast.getClientService().addClientListener(new ClientListener(){
>     public void clientConnected(Client client){
>
>     }
>
>     public void clientDisconnected(Client client){
>
>     }
>
> }
> });
>
> -fuad
>

Talip Ozturk

unread,
Mar 8, 2012, 12:22:29 PM3/8/12
to haze...@googlegroups.com
Try this:

Hazelcast.getDefaultInstance().getClientService();

Fuad Malikov

unread,
Mar 8, 2012, 12:35:17 PM3/8/12
to haze...@googlegroups.com
I am sorry we missed to add that as a static method into Hazelcast. 

Fuad Malikov
Co-founder & Managing Partner
Hazelcast | Open source in-memory data grid
Mobile: +90.538.378.9777 | @fuadm



Allen Zhao

unread,
Mar 8, 2012, 1:10:07 PM3/8/12
to Hazelcast
It is a method of HazelcastInstance. But that's enough to use.

Thank you so much, Talip and Faud.

On Mar 8, 12:22 pm, Talip Ozturk <ta...@hazelcast.com> wrote:
> Try this:
>
> Hazelcast.getDefaultInstance().getClientService();
>

Allen Zhao

unread,
Mar 8, 2012, 2:43:55 PM3/8/12
to Hazelcast
It seems that the Client (even ClientEndpoint) doesn't provide a
string (such as hostname:port) to identify the client. The only way to
correlate a disconnected client with a client previously connected is
by object reference.

Is it possible to expose the endPoint property from the client
connection (Client/ClientEndpoint) or a string ID so that we can
identify the connected/disconnected client?

Thanks.

On Mar 8, 12:35 pm, Fuad Malikov <f...@hazelcast.com> wrote:
> I am sorry we missed to add that as a static method into Hazelcast.
>
> Fuad Malikov
> Co-founder & Managing Partner
> Hazelcast | Open source in-memory data grid
> Mobile: +90.538.378.9777 | @fuadm
>
> On Thu, Mar 8, 2012 at 7:22 PM, Talip Ozturk <ta...@hazelcast.com> wrote:
> > Try this:
>
> > Hazelcast.getDefaultInstance().getClientService();
>
> > On Thu, Mar 8, 2012 at 7:05 PM, Allen Zhao <azhao00002...@gmail.com>

Allen Zhao

unread,
Mar 9, 2012, 3:04:12 PM3/9/12
to Hazelcast
After a client is connected to the cluster, I can get client local
address by
s1=HazelcastClient.getConnectionManager().getConnection().getSocket().getLocalSocketAddress()
from client. At the same time, the connected cluster member gets
clientConnected notification, and I tried to get the client connection
remote address by s2=(ClientEndpoint)client).getSocketAddress(). What
I found is that the two string values s1 and s2 are not always the
same, But the ClientEndpoint.conn.endPoint.toString is always the
same as s1.

What I am looking for is a way to correlate a connected client with
the client passed to the clientConnected method of ClientListener.
After a member joins a cluster, the member is assigned an address,
which can be used to correlate the member with cluster change
notifications. Is it possible to have a similar identifier such as
clientAddress which can be exposed from both HazelcastClient instance
and clientConnected/clientDisconnected parameters?

Thanks.

Fuad Malikov

unread,
Apr 3, 2012, 8:34:06 AM4/3/12
to haze...@googlegroups.com
ClientService.getConnectedClients return Collection of Client object. And client object does have a socketAddress. Isn't it what you are looking for?

-fuad

Fuad Malikov

unread,
May 23, 2012, 10:20:58 AM5/23/12
to haze...@googlegroups.com
I don't know if this is possible, but you can create an enhancement request: https://github.com/hazelcast/hazelcast





On Tue, Apr 10, 2012 at 9:52 PM, Allen Zhao <azhao0...@gmail.com> wrote:
When a client connects to a member, a socket is created between the
client and the member. That socketAddress by the client object
returned  from the member side is the local (member-side) address of
the socket. Is it possible to get the remote (client-side) address of
the socket so that we can correlate a client process with the client
object in the connected client list returned by
ClientService.getConnectedClients?

Thanks.


On Apr 3, 8:34 am, Fuad Malikov <f...@hazelcast.com> wrote:
> ClientService.getConnectedClients return Collection of Client object. And
> client object does have a socketAddress. Isn't it what you are looking for?
>
> -fuad
>

Allen Zhao

unread,
May 29, 2012, 11:16:44 AM5/29/12
to Hazelcast
Thanks, Fuad, the issue #173 was created. But I don't know how to
label it as enhancement.

On May 23, 10:20 am, Fuad Malikov <f...@hazelcast.com> wrote:
> I don't know if this is possible, but you can create an enhancement
> request:https://github.com/hazelcast/hazelcast
>
Reply all
Reply to author
Forward
0 new messages