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 {
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;
29 public RegisterChangeListener(YangInstanceIdentifier path,
30 ActorRef dataChangeListener,
31 AsyncDataBroker.DataChangeScope scope) {
33 this.dataChangeListener = dataChangeListener;
37 public YangInstanceIdentifier getPath() {
42 public AsyncDataBroker.DataChangeScope getScope() {
46 public ActorPath getDataChangeListenerPath() {
47 return dataChangeListener.path();
52 public ListenerRegistrationMessages.RegisterChangeListener toSerializable() {
53 return ListenerRegistrationMessages.RegisterChangeListener.newBuilder()
54 .setInstanceIdentifierPath(InstanceIdentifierUtils.toSerializable(path))
55 .setDataChangeListenerActorPath(Serialization.serializedActorPath(dataChangeListener))
56 .setDataChangeScope(scope.ordinal()).build();
59 public static RegisterChangeListener fromSerializable(ActorSystem actorSystem, Object serializable){
60 ListenerRegistrationMessages.RegisterChangeListener o = (ListenerRegistrationMessages.RegisterChangeListener) serializable;
61 return new RegisterChangeListener(InstanceIdentifierUtils.fromSerializable(o.getInstanceIdentifierPath()),
62 actorSystem.provider().resolveActorRef(o.getDataChangeListenerActorPath()),
63 AsyncDataBroker.DataChangeScope.values()[o.getDataChangeScope()]);