2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.controller.cluster.datastore;
10 import static com.google.common.base.Preconditions.checkState;
11 import static java.util.Objects.requireNonNull;
13 import akka.actor.ActorRef;
14 import akka.actor.ActorSystem;
15 import akka.actor.Address;
16 import akka.cluster.Cluster;
17 import akka.cluster.ClusterEvent;
18 import org.opendaylight.controller.cluster.access.concepts.MemberName;
20 public class ClusterWrapperImpl implements ClusterWrapper {
21 private final Cluster cluster;
22 private final MemberName currentMemberName;
23 private final Address selfAddress;
25 public ClusterWrapperImpl(final ActorSystem actorSystem) {
26 cluster = Cluster.get(requireNonNull(actorSystem, "actorSystem should not be null"));
28 checkState(cluster.getSelfRoles().size() > 0,
29 "No akka roles were specified.\n"
30 + "One way to specify the member name is to pass a property on the command line like so\n"
31 + " -Dakka.cluster.roles.0=member-3\n"
32 + "member-3 here would be the name of the member");
34 currentMemberName = MemberName.forName(cluster.getSelfRoles().iterator().next());
35 selfAddress = cluster.selfAddress();
39 public void subscribeToMemberEvents(final ActorRef actorRef) {
40 cluster.subscribe(requireNonNull(actorRef, "actorRef should not be null"), ClusterEvent.initialStateAsEvents(),
41 ClusterEvent.MemberEvent.class,
42 ClusterEvent.UnreachableMember.class,
43 ClusterEvent.ReachableMember.class);
47 public MemberName getCurrentMemberName() {
48 return currentMemberName;
52 public Address getSelfAddress() {