2 * Copyright (c) 2015 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 akka.actor.PoisonPill;
11 import akka.actor.Props;
12 import akka.japi.Creator;
13 import com.google.common.base.Preconditions;
14 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
15 import org.opendaylight.controller.cluster.common.actor.AbstractUntypedActor;
16 import org.opendaylight.controller.cluster.datastore.messages.CloseDataTreeChangeListenerRegistration;
17 import org.opendaylight.controller.cluster.datastore.messages.CloseDataTreeChangeListenerRegistrationReply;
18 import org.opendaylight.controller.md.sal.dom.api.DOMDataTreeChangeListener;
19 import org.opendaylight.yangtools.concepts.ListenerRegistration;
22 * Actor co-located with a shard. It exists only to terminate the registration when
23 * asked to do so via {@link CloseDataTreeChangeListenerRegistration}.
25 public final class DataTreeChangeListenerRegistrationActor extends AbstractUntypedActor {
26 private final ListenerRegistration<DOMDataTreeChangeListener> registration;
28 public DataTreeChangeListenerRegistrationActor(final ListenerRegistration<DOMDataTreeChangeListener> registration) {
29 this.registration = Preconditions.checkNotNull(registration);
33 protected void handleReceive(Object message) throws Exception {
34 if (message instanceof CloseDataTreeChangeListenerRegistration) {
36 if (isValidSender(getSender())) {
37 getSender().tell(CloseDataTreeChangeListenerRegistrationReply.getInstance(), getSelf());
40 getSelf().tell(PoisonPill.getInstance(), getSelf());
42 unknownMessage(message);
46 public static Props props(final ListenerRegistration<DOMDataTreeChangeListener> registration) {
47 return Props.create(new DataTreeChangeListenerRegistrationCreator(registration));
50 private static final class DataTreeChangeListenerRegistrationCreator
51 implements Creator<DataTreeChangeListenerRegistrationActor> {
52 private static final long serialVersionUID = 1L;
54 @SuppressFBWarnings(value = "SE_BAD_FIELD", justification = "This field is not Serializable but we don't "
55 + "create remote instances of this actor and thus don't need it to be Serializable.")
56 final ListenerRegistration<DOMDataTreeChangeListener> registration;
58 DataTreeChangeListenerRegistrationCreator(ListenerRegistration<DOMDataTreeChangeListener> registration) {
59 this.registration = Preconditions.checkNotNull(registration);
63 public DataTreeChangeListenerRegistrationActor create() {
64 return new DataTreeChangeListenerRegistrationActor(registration);