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
8 package org.opendaylight.controller.sal.restconf.broker.tools;
10 import com.google.common.util.concurrent.ListenableFuture;
11 import java.util.HashMap;
12 import java.util.Iterator;
13 import java.util.List;
16 import java.util.concurrent.ExecutionException;
17 import java.util.concurrent.Future;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.remote.rev140114.CreateNotificationStreamInputBuilder;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.remote.rev140114.CreateNotificationStreamOutput;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.remote.rev140114.QName;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.remote.rev140114.SalRemoteService;
22 import org.opendaylight.yangtools.restconf.client.api.RestconfClientContext;
23 import org.opendaylight.yangtools.restconf.client.api.event.EventStreamInfo;
24 import org.opendaylight.yangtools.yang.common.RpcResult;
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
28 public class RemoteStreamTools {
29 private static final Logger logger = LoggerFactory.getLogger(RemoteStreamTools.class.toString());
31 public static String createNotificationStream(SalRemoteService salRemoteService,List<QName> notifications){
32 CreateNotificationStreamInputBuilder notificationStreamInputBuilder = new CreateNotificationStreamInputBuilder();
34 if (null == notifications){
35 notificationStreamInputBuilder.setNotifications(notifications);
38 Future<RpcResult<CreateNotificationStreamOutput>> notificationStream = salRemoteService.createNotificationStream(notificationStreamInputBuilder.build());
40 String nofiticationStreamIdentifier = "";
42 if (notificationStream.get().isSuccessful()){
43 nofiticationStreamIdentifier = notificationStream.get().getResult().getNotificationStreamIdentifier();
45 } catch (InterruptedException e) {
46 logger.trace("Interrupted while resolving notification stream identifier due to {}",e);
47 } catch (ExecutionException e) {
48 logger.trace("Execution exception while resolving notification stream identifier due to {}",e);
50 return nofiticationStreamIdentifier;
53 public static Map<String,EventStreamInfo> createEventStream(RestconfClientContext restconfClientContext, String desiredStreamName){
54 ListenableFuture<Set<EventStreamInfo>> availableEventStreams = restconfClientContext.getAvailableEventStreams();
55 final Map<String,EventStreamInfo> desiredEventStream = new HashMap<String,EventStreamInfo>();
58 Iterator<EventStreamInfo> it = availableEventStreams.get().iterator();
60 if (it.next().getIdentifier().equals(desiredStreamName)){
61 desiredEventStream.put(desiredStreamName,it.next());
64 } catch (InterruptedException e) {
65 logger.trace("Resolving of event stream interrupted due to {}",e);
66 } catch (ExecutionException e) {
67 logger.trace("Resolving of event stream failed due to {}",e);
69 return desiredEventStream;