You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This chapter explains when various events are fired and describes how you can add event listeners on a Hazelcast Node.js client. These events can be categorized as cluster and distributed data structure events.
1953
1953
1954
-
### 7.5.1. Cluster Events
1954
+
### 7.5.1. Listening for Cluster Events
1955
1955
1956
1956
You can add event listeners to a Hazelcast Node.js client. You can configure the following listeners to listen to the events on the client side:
1957
1957
1958
1958
* Membership Listener: Notifies when a member joins to/leaves the cluster, or when an attribute is changed in a member.
1959
1959
* Distributed Object Listener: Notifies when a distributed object is created or destroyed throughout the cluster.
1960
1960
* Lifecycle Listener: Notifies when the client is starting, started, shutting down and shutdown.
1961
1961
1962
-
#### 7.5.1.1. Listening for Member Events
1962
+
#### 7.5.1.1. Membership Listener
1963
1963
1964
-
You can add the following types of member events to the `ClusterService`.
1964
+
The Membership Listener interface has functions that are invoked for the following events.
1965
1965
1966
1966
*`memberAdded`: A new member is added to the cluster.
1967
1967
*`memberRemoved`: An existing member leaves the cluster.
1968
1968
*`memberAttributeChanged`: An attribute of a member is changed. See the [Defining Member Attributes section](https://docs.hazelcast.org/docs/latest/manual/html-single/index.html#defining-member-attributes) in the Hazelcast IMDG Reference Manual to learn about member attributes.
1969
1969
1970
-
The `ClusterService` object exposes an `ClusterService.on()` function that allows one or more functions to be attached to the member events emitted by the object.
1970
+
For `memberAdded` and `memberRemoved` events, a `MembershipEvent` object is passed to the listener function.
1971
1971
1972
-
The following is a membership listener registration by using the `ClusterService.on()` function.
1972
+
After you create the listener object, you can configure your cluster to include the membership listener. You can also add one or more membership listeners.
1973
+
1974
+
The following is a membership listener registration by using the `ClusterService.addMembershipListener()` function.
1973
1975
1974
1976
```javascript
1975
-
client.clusterService.on('memberAdded', function (member) {
1976
-
console.log('Member Added: The address is', member.address.toString());
1977
-
});
1977
+
var membershipListener = {
1978
+
memberAdded:function (membershipEvent) {
1979
+
console.log('Member Added: The address is', member.address.toString());
The `memberAttributeChanged` has its own type of event named as `MemberAttributeEvent`. When there is an attribute change on the member, this event is fired.
1981
1986
1982
1987
See the following example.
1983
1988
1984
1989
```javascript
1985
-
client.clusterService.on('memberAttributeChanged', function (memberAttributeEvent) {
1986
-
console.log('Member Attribute Changed: The address is', memberAttributeEvent.member.address.toString());
#### 7.5.1.2. Listening for Distributed Object Events
1999
+
#### 7.5.1.2. Distributed Object Listener
1991
2000
1992
2001
The events for distributed objects are invoked when they are created and destroyed in the cluster. After the events, a listener callback function is called. The type of the callback function should be `DistributedObjectListener`. The parameter of the function is `DistributedObjectEvent` including following fields:
0 commit comments