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
9 package org.opendaylight.controller.cluster.datastore;
11 import akka.actor.ActorRef;
12 import akka.actor.ActorSystem;
13 import akka.actor.Address;
14 import akka.cluster.Cluster;
15 import akka.cluster.ClusterEvent;
16 import com.google.common.base.Preconditions;
17 import org.opendaylight.controller.cluster.access.concepts.MemberName;
19 public class ClusterWrapperImpl implements ClusterWrapper {
20 private final Cluster cluster;
21 private final MemberName currentMemberName;
22 private final Address selfAddress;
24 public ClusterWrapperImpl(ActorSystem actorSystem) {
25 Preconditions.checkNotNull(actorSystem, "actorSystem should not be null");
27 cluster = Cluster.get(actorSystem);
29 Preconditions.checkState(cluster.getSelfRoles().size() > 0,
30 "No akka roles were specified.\n"
31 + "One way to specify the member name is to pass a property on the command line like so\n"
32 + " -Dakka.cluster.roles.0=member-3\n"
33 + "member-3 here would be the name of the member");
35 currentMemberName = MemberName.forName(cluster.getSelfRoles().iterator().next());
36 selfAddress = cluster.selfAddress();
40 public void subscribeToMemberEvents(ActorRef actorRef) {
41 Preconditions.checkNotNull(actorRef, "actorRef should not be null");
43 cluster.subscribe(actorRef, ClusterEvent.initialStateAsEvents(),
44 ClusterEvent.MemberEvent.class,
45 ClusterEvent.UnreachableMember.class,
46 ClusterEvent.ReachableMember.class);
50 public MemberName getCurrentMemberName() {
51 return currentMemberName;
55 public Address getSelfAddress() {