Merge "Bug-2842:If an install snapshot is in progress, Follower should return immedia...
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / messages / RegisterChangeListener.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.controller.cluster.datastore.messages;
10
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;
17
18 public class RegisterChangeListener implements SerializableMessage {
19     public static final Class<ListenerRegistrationMessages.RegisterChangeListener> SERIALIZABLE_CLASS =
20             ListenerRegistrationMessages.RegisterChangeListener.class;
21
22     private final YangInstanceIdentifier path;
23     private final ActorPath dataChangeListenerPath;
24     private final AsyncDataBroker.DataChangeScope scope;
25
26
27     public RegisterChangeListener(YangInstanceIdentifier path,
28         ActorPath dataChangeListenerPath,
29         AsyncDataBroker.DataChangeScope scope) {
30         this.path = path;
31         this.dataChangeListenerPath = dataChangeListenerPath;
32         this.scope = scope;
33     }
34
35     public YangInstanceIdentifier getPath() {
36         return path;
37     }
38
39
40     public AsyncDataBroker.DataChangeScope getScope() {
41         return scope;
42     }
43
44     public ActorPath getDataChangeListenerPath() {
45         return dataChangeListenerPath;
46     }
47
48
49     @Override
50     public ListenerRegistrationMessages.RegisterChangeListener toSerializable() {
51       return ListenerRegistrationMessages.RegisterChangeListener.newBuilder()
52           .setInstanceIdentifierPath(InstanceIdentifierUtils.toSerializable(path))
53           .setDataChangeListenerActorPath(dataChangeListenerPath.toString())
54           .setDataChangeScope(scope.ordinal()).build();
55     }
56
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()]);
62   }
63
64
65 }