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.utils.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 SERIALIZABLE_CLASS = ListenerRegistrationMessages.RegisterChangeListener.class;
20 private final YangInstanceIdentifier path;
21 private final ActorPath dataChangeListenerPath;
22 private final AsyncDataBroker.DataChangeScope scope;
25 public RegisterChangeListener(YangInstanceIdentifier path,
26 ActorPath dataChangeListenerPath,
27 AsyncDataBroker.DataChangeScope scope) {
29 this.dataChangeListenerPath = dataChangeListenerPath;
33 public YangInstanceIdentifier getPath() {
38 public AsyncDataBroker.DataChangeScope getScope() {
42 public ActorPath getDataChangeListenerPath() {
43 return dataChangeListenerPath;
48 public ListenerRegistrationMessages.RegisterChangeListener toSerializable() {
49 return ListenerRegistrationMessages.RegisterChangeListener.newBuilder()
50 .setInstanceIdentifierPath(InstanceIdentifierUtils.toSerializable(path))
51 .setDataChangeListenerActorPath(dataChangeListenerPath.toString())
52 .setDataChangeScope(scope.ordinal()).build();
55 public static RegisterChangeListener fromSerializable(ActorSystem actorSystem,Object serializable){
56 ListenerRegistrationMessages.RegisterChangeListener o = (ListenerRegistrationMessages.RegisterChangeListener) serializable;
57 return new RegisterChangeListener(InstanceIdentifierUtils.fromSerializable(o.getInstanceIdentifierPath()),
58 actorSystem.actorFor(o.getDataChangeListenerActorPath()).path(),
59 AsyncDataBroker.DataChangeScope.values()[o.getDataChangeScope()]);