Merge "BUG 2820 - LLDP refactor"
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / messages / RegisterChangeListenerReply.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.ActorRef;
13 import akka.actor.ActorSystem;
14 import akka.serialization.Serialization;
15 import org.opendaylight.controller.protobuff.messages.registration.ListenerRegistrationMessages;
16
17 public class RegisterChangeListenerReply implements SerializableMessage{
18   public static final Class<ListenerRegistrationMessages.RegisterChangeListenerReply> SERIALIZABLE_CLASS =
19           ListenerRegistrationMessages.RegisterChangeListenerReply.class;
20   private final ActorRef listenerRegistration;
21
22   public RegisterChangeListenerReply(final ActorRef listenerRegistration) {
23     this.listenerRegistration = listenerRegistration;
24   }
25
26   public ActorPath getListenerRegistrationPath() {
27     return listenerRegistration.path();
28   }
29
30   @Override
31   public ListenerRegistrationMessages.RegisterChangeListenerReply toSerializable() {
32     return ListenerRegistrationMessages.RegisterChangeListenerReply.newBuilder()
33             .setListenerRegistrationPath(Serialization.serializedActorPath(listenerRegistration)).build();
34   }
35
36   public static RegisterChangeListenerReply fromSerializable(final ActorSystem actorSystem,final Object serializable){
37     ListenerRegistrationMessages.RegisterChangeListenerReply o = (ListenerRegistrationMessages.RegisterChangeListenerReply) serializable;
38     return new RegisterChangeListenerReply(
39         actorSystem.provider().resolveActorRef(o.getListenerRegistrationPath())
40         );
41   }
42 }