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.ActorSystem;
13 import org.opendaylight.controller.cluster.datastore.util.InstanceIdentifierUtils;
14 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker;
15 import org.opendaylight.controller.protobuff.messages.registration.ListenerRegistrationMessages;
16 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
18 public class RegisterChangeListener implements SerializableMessage {
19 public static final Class<ListenerRegistrationMessages.RegisterChangeListener> SERIALIZABLE_CLASS =
20 ListenerRegistrationMessages.RegisterChangeListener.class;
22 private final YangInstanceIdentifier path;
23 private final ActorPath dataChangeListenerPath;
24 private final AsyncDataBroker.DataChangeScope scope;
27 public RegisterChangeListener(YangInstanceIdentifier path,
28 ActorPath dataChangeListenerPath,
29 AsyncDataBroker.DataChangeScope scope) {
31 this.dataChangeListenerPath = dataChangeListenerPath;
35 public YangInstanceIdentifier getPath() {
40 public AsyncDataBroker.DataChangeScope getScope() {
44 public ActorPath getDataChangeListenerPath() {
45 return dataChangeListenerPath;
50 public ListenerRegistrationMessages.RegisterChangeListener toSerializable() {
51 return ListenerRegistrationMessages.RegisterChangeListener.newBuilder()
52 .setInstanceIdentifierPath(InstanceIdentifierUtils.toSerializable(path))
53 .setDataChangeListenerActorPath(dataChangeListenerPath.toString())
54 .setDataChangeScope(scope.ordinal()).build();
57 public static RegisterChangeListener fromSerializable(ActorSystem actorSystem,Object serializable){
58 ListenerRegistrationMessages.RegisterChangeListener o = (ListenerRegistrationMessages.RegisterChangeListener) serializable;
59 return new RegisterChangeListener(InstanceIdentifierUtils.fromSerializable(o.getInstanceIdentifierPath()),
60 actorSystem.actorFor(o.getDataChangeListenerActorPath()).path(),
61 AsyncDataBroker.DataChangeScope.values()[o.getDataChangeScope()]);