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

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.