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;
11 import akka.actor.Props;
12 import akka.japi.Creator;
13 import org.opendaylight.controller.cluster.datastore.messages.DataChanged;
14 import org.opendaylight.controller.cluster.datastore.messages.DataChangedReply;
15 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent;
16 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeListener;
17 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
18 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
19 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
21 public class DataChangeListener extends AbstractUntypedActor {
22 private final AsyncDataChangeListener<YangInstanceIdentifier, NormalizedNode<?, ?>> listener;
23 private final SchemaContext schemaContext;
24 private final YangInstanceIdentifier pathId;
26 public DataChangeListener(SchemaContext schemaContext,
27 AsyncDataChangeListener<YangInstanceIdentifier, NormalizedNode<?, ?>> listener, YangInstanceIdentifier pathId) {
28 this.listener = listener;
29 this.schemaContext = schemaContext;
33 @Override public void handleReceive(Object message) throws Exception {
34 if(message.getClass().equals(DataChanged.SERIALIZABLE_CLASS)){
35 DataChanged reply = DataChanged.fromSerialize(schemaContext,message, pathId);
36 AsyncDataChangeEvent<YangInstanceIdentifier, NormalizedNode<?, ?>>
37 change = reply.getChange();
38 this.listener.onDataChanged(change);
40 if(getSender() != null){
41 getSender().tell(new DataChangedReply().toSerializable(), getSelf());
47 public static Props props(final SchemaContext schemaContext, final AsyncDataChangeListener<YangInstanceIdentifier, NormalizedNode<?, ?>> listener, final YangInstanceIdentifier pathId) {
48 return Props.create(new Creator<DataChangeListener>() {
50 public DataChangeListener create() throws Exception {
51 return new DataChangeListener(schemaContext,listener,pathId );