public interface LocalMember extends GroupMember
DistributedGroup member representing a member of the group controlled by the
local process.
Local group members can only be acquired by joining a membership
group. Local members provide the interface necessary to set member properties, receive messages,
and react to the election of the member as the group leader.
To receive messages sent to the joined member of the group, register a message consumer. Messages
sent to the member are associated with a String topic, and separate handlers can be registered
for each topic supported by the local member:
LocalGroupMember member = group.join().get();
member.onMessage("foo", message -> System.out.println("received: " + message));
GroupMember.Status| Modifier and Type | Method and Description |
|---|---|
CompletableFuture<Void> |
leave()
Leaves the membership group.
|
MessageService |
messaging()
Returns the local member message service.
|
id, metadata, onStatusChange, statusMessageService messaging()
The message service can be used to receive messages sent either directly or indirectly to this
member by creating a MessageConsumer.
LocalMember localMember = group.join("foo").join();
MessageConsumer<String> consumer = localMember.messaging().consumer("bar");
consumer.onMessage(message -> {
message.ack();
});
messaging in interface GroupMemberCompletableFuture<Void> leave()
When this member leaves the membership group, the membership lists of this and all other instances
in the group are guaranteed to be updated before the CompletableFuture returned by
this method is completed. Once this instance has left the group, the returned future will be completed.
This method returns a CompletableFuture which can be used to block until the operation completes
or to be notified in a separate thread once the operation completes. To block until the operation completes,
use the CompletableFuture.join() method to block the calling thread:
member.leave().join();
Alternatively, to execute the operation asynchronous and be notified once the lock is acquired in a different
thread, use one of the many completable future callbacks:
member.leave().thenRun(() -> System.out.println("Left the group!")));
Copyright © 2013–2017. All rights reserved.