Skip to content

Commit 555158e

Browse files
Refactor distributed events (#427)
1 parent 136fc6b commit 555158e

File tree

1 file changed

+28
-19
lines changed

1 file changed

+28
-19
lines changed

README.md

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,11 @@
6767
* [7.4.12. Using PN Counter](#7412-using-pn-counter)
6868
* [7.4.13. Using Flake ID Generator](#7413-using-flake-id-generator)
6969
* [7.5. Distributed Events](#75-distributed-events)
70-
* [7.5.1. Cluster Events](#751-cluster-events)
71-
* [7.5.1.1. Listening for Member Events](#7511-listening-for-member-events)
72-
* [7.5.1.2. Listening for Distributed Object Events](#7512-listening-for-distributed-object-events)
73-
* [7.5.1.3. Listening for Lifecycle Events](#7513-listening-for-lifecycle-events)
74-
* [7.5.2. Distributed Data Structure Events](#752-distributed-data-structure-events)
70+
* [7.5.1. Listening for Cluster Events](#751-listening-for-cluster-events)
71+
* [7.5.1.1. Membership Listener](#7511-membership-listener)
72+
* [7.5.1.2. Distributed Object Listener](#7512-distributed-object-listener)
73+
* [7.5.1.3. Lifecycle Listener](#7513-lifecycle-listener)
74+
* [7.5.2. Listening for Distributed Data Structure Events](#752-listening-for-distributed-data-structure-events)
7575
* [7.5.2.1. Map Listener](#7521-map-listener)
7676
* [7.5.2.2. Entry Listener](#7522-entry-listener)
7777
* [7.5.2.3. Item Listener](#7523-item-listener)
@@ -1951,43 +1951,52 @@ hazelcastClient.getFlakeIdGenerator('myFlakeIdGenerator').then(function (gen) {
19511951

19521952
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.
19531953

1954-
### 7.5.1. Cluster Events
1954+
### 7.5.1. Listening for Cluster Events
19551955

19561956
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:
19571957

19581958
* Membership Listener: Notifies when a member joins to/leaves the cluster, or when an attribute is changed in a member.
19591959
* Distributed Object Listener: Notifies when a distributed object is created or destroyed throughout the cluster.
19601960
* Lifecycle Listener: Notifies when the client is starting, started, shutting down and shutdown.
19611961

1962-
#### 7.5.1.1. Listening for Member Events
1962+
#### 7.5.1.1. Membership Listener
19631963

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.
19651965

19661966
* `memberAdded`: A new member is added to the cluster.
19671967
* `memberRemoved`: An existing member leaves the cluster.
19681968
* `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.
19691969

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.
19711971

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.
19731975

19741976
```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());
1980+
},
1981+
};
1982+
client.clusterService.addMembershipListener(membershipListener);
19781983
```
19791984

19801985
The `memberAttributeChanged` has its own type of event named as `MemberAttributeEvent`. When there is an attribute change on the member, this event is fired.
19811986

19821987
See the following example.
19831988

19841989
```javascript
1985-
client.clusterService.on('memberAttributeChanged', function (memberAttributeEvent) {
1986-
console.log('Member Attribute Changed: The address is', memberAttributeEvent.member.address.toString());
1987-
});
1990+
1991+
var membershipListener = {
1992+
memberAttributeChanged: function (memberAttributeEvent) {
1993+
console.log('Member Attribute Changed: The address is', memberAttributeEvent.member.address.toString());
1994+
},
1995+
};
1996+
client.clusterService.addMembershipListener(membershipListener);
19881997
```
19891998

1990-
#### 7.5.1.2. Listening for Distributed Object Events
1999+
#### 7.5.1.2. Distributed Object Listener
19912000

19922001
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:
19932002

@@ -2013,7 +2022,7 @@ client.addDistributedObjectListener(function (distributedObjectEvent) {
20132022
});
20142023
```
20152024

2016-
#### 7.5.1.3. Listening for Lifecycle Events
2025+
#### 7.5.1.3. Lifecycle Listener
20172026

20182027
The `LifecycleListener` interface notifies for the following events:
20192028

@@ -2054,7 +2063,7 @@ Lifecycle Event >>> shutdown
20542063
Process finished with exit code 0
20552064
```
20562065

2057-
### 7.5.2. Distributed Data Structure Events
2066+
### 7.5.2. Listening for Distributed Data Structure Events
20582067

20592068
You can add event listeners to the distributed data structures.
20602069

0 commit comments

Comments
 (0)