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 org.opendaylight.controller.cluster.common.actor.AbstractUntypedActor;
15 import org.opendaylight.controller.cluster.datastore.messages.CloseDataTreeChangeListenerRegistration;
16 import org.opendaylight.controller.cluster.datastore.messages.CloseDataTreeChangeListenerRegistrationReply;
17 import org.opendaylight.controller.md.sal.dom.api.DOMDataTreeChangeListener;
18 import org.opendaylight.yangtools.concepts.ListenerRegistration;
21 * Actor co-located with a shard. It exists only to terminate the registration when
22 * asked to do so via {@link CloseDataTreeChangeListenerRegistration}.
24 public final class DataTreeChangeListenerRegistrationActor extends AbstractUntypedActor {
25 private final ListenerRegistration<DOMDataTreeChangeListener> registration;
27 public DataTreeChangeListenerRegistrationActor(final ListenerRegistration<DOMDataTreeChangeListener> registration) {
28 this.registration = Preconditions.checkNotNull(registration);
32 protected void handleReceive(Object message) throws Exception {
33 if (message instanceof CloseDataTreeChangeListenerRegistration) {
35 if (isValidSender(getSender())) {
36 getSender().tell(CloseDataTreeChangeListenerRegistrationReply.getInstance(), getSelf());
39 getSelf().tell(PoisonPill.getInstance(), getSelf());
41 unknownMessage(message);
45 public static Props props(final ListenerRegistration<DOMDataTreeChangeListener> registration) {
46 return Props.create(new DataTreeChangeListenerRegistrationCreator(registration));
49 private static final class DataTreeChangeListenerRegistrationCreator
50 implements Creator<DataTreeChangeListenerRegistrationActor> {
51 private static final long serialVersionUID = 1L;
52 final ListenerRegistration<DOMDataTreeChangeListener> registration;
54 DataTreeChangeListenerRegistrationCreator(ListenerRegistration<DOMDataTreeChangeListener> registration) {
55 this.registration = Preconditions.checkNotNull(registration);
59 public DataTreeChangeListenerRegistrationActor create() {
60 return new DataTreeChangeListenerRegistrationActor(registration);