2 * Copyright (c) 2013 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.messagebus.app.impl;
11 import java.util.List;
12 import java.util.concurrent.Future;
13 import org.opendaylight.controller.mdsal.MdSAL;
14 import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.messagebus.eventaggregator.rev141202.CreateTopicInput;
15 import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.messagebus.eventaggregator.rev141202.CreateTopicOutput;
16 import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.messagebus.eventaggregator.rev141202.CreateTopicOutputBuilder;
17 import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.messagebus.eventaggregator.rev141202.DestroyTopicInput;
18 import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.messagebus.eventaggregator.rev141202.EventAggregatorService;
19 import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.messagebus.eventaggregator.rev141202.NotificationPattern;
20 import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.messagebus.eventsource.rev141202.Node1;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
22 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
23 import org.opendaylight.yangtools.yang.common.RpcResult;
24 import org.slf4j.Logger;
25 import org.slf4j.LoggerFactory;
27 // TODO: implement topic created notification
28 public class EventAggregator implements EventAggregatorService {
29 private static final Logger LOGGER = LoggerFactory.getLogger(EventAggregator.class);
31 private final MdSAL mdSAL;
32 private final EventSourceTopology eventSourceTopology;
34 public EventAggregator(final MdSAL mdSAL, final EventSourceTopology eventSourceTopology) {
36 this.eventSourceTopology = eventSourceTopology;
39 public void mdsalReady() {
40 mdSAL.addRpcImplementation(EventAggregatorService.class, this);
44 public Future<RpcResult<CreateTopicOutput>> createTopic(final CreateTopicInput input) {
45 LOGGER.info("Received Topic creation request: NotificationPattern -> {}, NodeIdPattern -> {}",
46 input.getNotificationPattern(),
47 input.getNodeIdPattern());
49 Topic topic = new Topic(new NotificationPattern(input.getNotificationPattern()), input.getNodeIdPattern().getValue(), mdSAL);
51 //# Make sure we capture all nodes from now on
52 eventSourceTopology.registerDataChangeListener(topic);
54 //# Notify existing nodes
55 //# Code reader note: Context of Node type is NetworkTopology
56 List<Node> nodes = eventSourceTopology.snapshot();
57 for (Node node : nodes) {
58 NodeId nodeIdToNotify = node.getAugmentation(Node1.class).getEventSourceNode();
59 topic.notifyNode(nodeIdToNotify);
62 CreateTopicOutput cto = new CreateTopicOutputBuilder()
63 .setTopicId(topic.getTopicId())
66 return Util.resultFor(cto);
70 public Future<RpcResult<Void>> destroyTopic(final DestroyTopicInput input) {
71 // 1. UNREGISTER DATA CHANGE LISTENER -> ?