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 getSender().tell(CloseDataTreeChangeListenerRegistrationReply.getInstance(), getSelf());
36 getSelf().tell(PoisonPill.getInstance(), getSelf());
40 public static Props props(final ListenerRegistration<DOMDataTreeChangeListener> registration) {
41 return Props.create(new DataTreeChangeListenerRegistrationCreator(registration));
44 private static final class DataTreeChangeListenerRegistrationCreator implements Creator<DataTreeChangeListenerRegistrationActor> {
45 private static final long serialVersionUID = 1L;
46 final ListenerRegistration<DOMDataTreeChangeListener> registration;
48 DataTreeChangeListenerRegistrationCreator(ListenerRegistration<DOMDataTreeChangeListener> registration) {
49 this.registration = Preconditions.checkNotNull(registration);
53 public DataTreeChangeListenerRegistrationActor create() {
54 return new DataTreeChangeListenerRegistrationActor(registration);