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