83542a0de285fbafe05f5b3e6540b232d6f8873f
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / messages / RegisterDataTreeChangeListener.java
1 /*
2  * Copyright (c) 2015 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 package org.opendaylight.controller.cluster.datastore.messages;
9
10 import static java.util.Objects.requireNonNull;
11
12 import akka.actor.ActorPath;
13 import akka.actor.ActorRef;
14 import java.io.Externalizable;
15 import java.io.IOException;
16 import java.io.ObjectInput;
17 import java.io.ObjectOutput;
18 import org.opendaylight.controller.cluster.datastore.node.utils.stream.SerializationUtils;
19 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
20
21 /**
22  * Request a {@link org.opendaylight.controller.md.sal.dom.api.DOMDataTreeChangeListener} registration be made on the
23  * shard leader.
24  */
25 public final class RegisterDataTreeChangeListener implements Externalizable {
26     private static final long serialVersionUID = 1L;
27
28     private ActorRef dataTreeChangeListenerPath;
29     private YangInstanceIdentifier path;
30     private boolean registerOnAllInstances;
31
32     public RegisterDataTreeChangeListener() {
33         // For Externalizable
34     }
35
36     public RegisterDataTreeChangeListener(final YangInstanceIdentifier path, final ActorRef dataTreeChangeListenerPath,
37             final boolean registerOnAllInstances) {
38         this.path = requireNonNull(path);
39         this.dataTreeChangeListenerPath = requireNonNull(dataTreeChangeListenerPath);
40         this.registerOnAllInstances = registerOnAllInstances;
41     }
42
43     public YangInstanceIdentifier getPath() {
44         return path;
45     }
46
47     public ActorPath getListenerActorPath() {
48         return dataTreeChangeListenerPath.path();
49     }
50
51     public boolean isRegisterOnAllInstances() {
52         return registerOnAllInstances;
53     }
54
55     @Override
56     public void writeExternal(final ObjectOutput out) throws IOException {
57         out.writeObject(dataTreeChangeListenerPath);
58         SerializationUtils.writePath(out, path);
59         out.writeBoolean(registerOnAllInstances);
60     }
61
62     @Override
63     public void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException {
64         dataTreeChangeListenerPath = (ActorRef) in.readObject();
65         path = SerializationUtils.deserializePath(in);
66         registerOnAllInstances = in.readBoolean();
67     }
68
69     @Override
70     public String toString() {
71         return "RegisterDataTreeChangeListener [path=" + path + ", registerOnAllInstances=" + registerOnAllInstances
72                 + ", dataTreeChangeListenerPath=" + dataTreeChangeListenerPath + "]";
73     }
74 }