Remove unused imports in the whole NETCONF project
[netconf.git] / restconf / sal-restconf-broker / src / main / java / org / opendaylight / netconf / sal / restconf / broker / SalRemoteServiceBroker.java
1 /*
2  * Copyright (c) 2013 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 package org.opendaylight.netconf.sal.restconf.broker;
9
10
11 import static com.google.common.base.Preconditions.checkState;
12
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;
27
28 public class SalRemoteServiceBroker implements BindingAwareBroker,AutoCloseable {
29
30
31     private static final Logger logger = LoggerFactory.getLogger(SalRemoteServiceBroker.class.toString());
32     private ImmutableClassToInstanceMap<BindingAwareService> supportedConsumerServices;
33
34     private final String identifier;
35
36     private RpcConsumerRegistry rpcBroker;
37     private NotificationService notificationBroker;
38     private DataBrokerService dataBroker;
39     private final RemoteServicesFactory servicesFactory;
40
41     public SalRemoteServiceBroker(String instanceName,RestconfClientContext clientContext){
42         this.identifier = instanceName;
43         this.servicesFactory = new RemoteServicesFactory(clientContext);
44     }
45
46     public void start() {
47         logger.info("Starting Binding Aware Broker: {}", identifier);
48
49         supportedConsumerServices = ImmutableClassToInstanceMap.<BindingAwareService> builder()
50                 .put(NotificationService.class, servicesFactory.getNotificationService()) //
51                 .put(DataBrokerService.class,servicesFactory.getDataBrokerService() ) //
52                 .put(RpcConsumerRegistry.class,servicesFactory.getRpcConsumerRegistry() ).build();
53     }
54
55     public ProviderContext registerProvider(BindingAwareProvider provider) {
56         throw new UnsupportedOperationException();
57     }
58     @Override
59     public void close() throws Exception {
60         //TODO decide if serviceFactory should close clientContext or it has to be closed by consumer
61     }
62     @Override
63     public ConsumerContext registerConsumer(BindingAwareConsumer consumer) {
64         checkState(supportedConsumerServices != null, "Broker is not initialized.");
65         return BindingContextUtils.createConsumerContextAndInitialize(consumer, supportedConsumerServices);
66     }
67
68     @Override
69     public ConsumerContext registerConsumer(BindingAwareConsumer consumer,
70             BundleContext ctx) {
71         return registerConsumer(consumer);
72     }
73
74     @Override
75     public ProviderContext registerProvider(BindingAwareProvider provider,
76             BundleContext ctx) {
77         return registerProvider(provider);
78     }
79
80 }