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.messages;
11 import akka.actor.ActorPath;
12 import akka.actor.ActorRef;
13 import akka.actor.ActorSystem;
14 import akka.serialization.Serialization;
15 import org.opendaylight.controller.cluster.datastore.util.InstanceIdentifierUtils;
16 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker;
17 import org.opendaylight.controller.protobuff.messages.registration.ListenerRegistrationMessages;
18 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
20 public class RegisterChangeListener implements SerializableMessage, ListenerRegistrationMessage {
21 public static final Class<ListenerRegistrationMessages.RegisterChangeListener> SERIALIZABLE_CLASS =
22 ListenerRegistrationMessages.RegisterChangeListener.class;
24 private final YangInstanceIdentifier path;
25 private final ActorRef dataChangeListener;
26 private final AsyncDataBroker.DataChangeScope scope;
27 private final boolean registerOnAllInstances;
30 public RegisterChangeListener(YangInstanceIdentifier path,
31 ActorRef dataChangeListener,
32 AsyncDataBroker.DataChangeScope scope, boolean registerOnAllInstances) {
34 this.dataChangeListener = dataChangeListener;
36 this.registerOnAllInstances = registerOnAllInstances;
40 public YangInstanceIdentifier getPath() {
45 public AsyncDataBroker.DataChangeScope getScope() {
49 public ActorPath getDataChangeListenerPath() {
50 return dataChangeListener.path();
54 public boolean isRegisterOnAllInstances() {
55 return registerOnAllInstances;
59 public ListenerRegistrationMessages.RegisterChangeListener toSerializable() {
60 return ListenerRegistrationMessages.RegisterChangeListener.newBuilder()
61 .setInstanceIdentifierPath(InstanceIdentifierUtils.toSerializable(path))
62 .setDataChangeListenerActorPath(Serialization.serializedActorPath(dataChangeListener))
63 .setDataChangeScope(scope.ordinal()).setRegisterOnAllInstances(registerOnAllInstances).build();
66 public static RegisterChangeListener fromSerializable(ActorSystem actorSystem, Object serializable){
67 ListenerRegistrationMessages.RegisterChangeListener o = (ListenerRegistrationMessages.RegisterChangeListener) serializable;
68 return new RegisterChangeListener(InstanceIdentifierUtils.fromSerializable(o.getInstanceIdentifierPath()),
69 actorSystem.provider().resolveActorRef(o.getDataChangeListenerActorPath()),
70 AsyncDataBroker.DataChangeScope.values()[o.getDataChangeScope()], o.getRegisterOnAllInstances());