Bug 6714 - Use singleton service in clustered netconf topology
[netconf.git] / netconf / abstract-topology / src / main / java / org / opendaylight / netconf / topology / example / LoggingSalNodeWriter.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
9 package org.opendaylight.netconf.topology.example;
10
11 import java.util.ArrayList;
12 import java.util.Arrays;
13 import javax.annotation.Nonnull;
14 import org.opendaylight.netconf.topology.util.NodeWriter;
15 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
16 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
17 import org.slf4j.Logger;
18 import org.slf4j.LoggerFactory;
19
20 public class LoggingSalNodeWriter implements NodeWriter{
21
22     private static final Logger LOG = LoggerFactory.getLogger(LoggingSalNodeWriter.class);
23
24     private final ArrayList<NodeWriter> delegates;
25
26     public LoggingSalNodeWriter(final NodeWriter... delegates) {
27         this.delegates = new ArrayList<>(Arrays.asList(delegates));
28     }
29
30     @Override
31     public void init(@Nonnull NodeId id, @Nonnull Node operationalDataNode) {
32         LOG.warn("Init recieved");
33         LOG.warn("NodeId: {}", id.getValue());
34         LOG.warn("Node: {}", operationalDataNode);
35         for (final NodeWriter delegate : delegates) {
36             delegate.init(id, operationalDataNode);
37         }
38     }
39
40     @Override
41     public void update(@Nonnull NodeId id, @Nonnull Node operationalDataNode) {
42         LOG.warn("Update recieved");
43         LOG.warn("NodeId: {}", id.getValue());
44         LOG.warn("Node: {}", operationalDataNode);
45         for (final NodeWriter delegate : delegates) {
46             delegate.update(id, operationalDataNode);
47         }
48     }
49
50     @Override
51     public void delete(@Nonnull NodeId id) {
52         LOG.warn("Delete recieved");
53         LOG.warn("NodeId: {}", id.getValue());
54         for (final NodeWriter delegate : delegates) {
55             delegate.delete(id);
56         }
57     }
58 }