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.netconf.sal.restconf.broker;
11 import static com.google.common.base.Preconditions.checkState;
13 import com.google.common.collect.ImmutableClassToInstanceMap;
14 import org.opendaylight.controller.md.sal.binding.util.BindingContextUtils;
15 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
16 import org.opendaylight.controller.sal.binding.api.BindingAwareConsumer;
17 import org.opendaylight.controller.sal.binding.api.BindingAwareProvider;
18 import org.opendaylight.controller.sal.binding.api.BindingAwareService;
19 import org.opendaylight.controller.sal.binding.api.NotificationService;
20 import org.opendaylight.controller.sal.binding.api.RpcConsumerRegistry;
21 import org.opendaylight.controller.sal.binding.api.data.DataBrokerService;
22 import org.opendaylight.netconf.sal.restconf.broker.impl.RemoteServicesFactory;
23 import org.opendaylight.yangtools.restconf.client.api.RestconfClientContext;
24 import org.osgi.framework.BundleContext;
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
28 public class SalRemoteServiceBroker implements BindingAwareBroker,AutoCloseable {
31 private static final Logger logger = LoggerFactory.getLogger(SalRemoteServiceBroker.class.toString());
32 private ImmutableClassToInstanceMap<BindingAwareService> supportedConsumerServices;
34 private final String identifier;
36 private RpcConsumerRegistry rpcBroker;
37 private NotificationService notificationBroker;
38 private DataBrokerService dataBroker;
39 private final RemoteServicesFactory servicesFactory;
41 public SalRemoteServiceBroker(String instanceName,RestconfClientContext clientContext){
42 this.identifier = instanceName;
43 this.servicesFactory = new RemoteServicesFactory(clientContext);
47 logger.info("Starting Binding Aware Broker: {}", identifier);
49 supportedConsumerServices = ImmutableClassToInstanceMap.<BindingAwareService> builder()
50 .put(NotificationService.class, servicesFactory.getNotificationService()) //
51 .put(DataBrokerService.class,servicesFactory.getDataBrokerService() ) //
52 .put(RpcConsumerRegistry.class,servicesFactory.getRpcConsumerRegistry() ).build();
55 public ProviderContext registerProvider(BindingAwareProvider provider) {
56 throw new UnsupportedOperationException();
59 public void close() throws Exception {
60 //TODO decide if serviceFactory should close clientContext or it has to be closed by consumer
63 public ConsumerContext registerConsumer(BindingAwareConsumer consumer) {
64 checkState(supportedConsumerServices != null, "Broker is not initialized.");
65 return BindingContextUtils.createConsumerContextAndInitialize(consumer, supportedConsumerServices);
69 public ConsumerContext registerConsumer(BindingAwareConsumer consumer,
71 return registerConsumer(consumer);
75 public ProviderContext registerProvider(BindingAwareProvider provider,
77 return registerProvider(provider);