2 * Copyright (c) 2014 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.client;
12 import javassist.ClassPool;
14 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ConsumerContext;
15 import org.opendaylight.controller.sal.binding.api.BindingAwareConsumer;
16 import org.opendaylight.controller.sal.restconf.broker.SalRemoteServiceBroker;
17 import org.opendaylight.yangtools.restconf.client.RestconfClientFactory;
18 import org.opendaylight.yangtools.restconf.client.api.RestconfClientContext;
19 import org.opendaylight.yangtools.restconf.client.api.UnsupportedProtocolException;
20 import org.opendaylight.yangtools.sal.binding.generator.impl.ModuleInfoBackedContext;
21 import org.opendaylight.yangtools.sal.binding.generator.impl.RuntimeGeneratedMappingServiceImpl;
22 import org.opendaylight.yangtools.yang.binding.util.BindingReflections;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
26 import com.google.common.base.Preconditions;
28 class SalRemoteClientImpl implements SalRemoteClient {
30 private static final Logger logger = LoggerFactory.getLogger(SalRemoteClientImpl.class);
32 private final RestconfClientContext restconfClientContext;
33 private final SalRemoteServiceBroker salRemoteBroker;
34 private final RuntimeGeneratedMappingServiceImpl mappingService;
36 public SalRemoteClientImpl(final URL url) {
37 Preconditions.checkNotNull(url);
39 this.mappingService = new RuntimeGeneratedMappingServiceImpl(ClassPool.getDefault());
41 final ModuleInfoBackedContext moduleInfo = ModuleInfoBackedContext.create();
42 moduleInfo.addModuleInfos(BindingReflections.loadModuleInfos());
43 this.mappingService.onGlobalContextUpdated(moduleInfo.tryToCreateSchemaContext().get());
46 this.restconfClientContext = new RestconfClientFactory().getRestconfClientContext(url, this.mappingService,
49 this.salRemoteBroker = new SalRemoteServiceBroker("remote-broker", restconfClientContext);
50 this.salRemoteBroker.start();
51 } catch (UnsupportedProtocolException e) {
52 logger.error("Unsupported protocol {}.", url.getProtocol(), e);
53 throw new IllegalArgumentException("Unsupported protocol.", e);
58 public ConsumerContext registerConsumer() {
59 return this.salRemoteBroker.registerConsumer(new BindingAwareConsumer() {
62 public void onSessionInitialized(ConsumerContext session) {
68 public void close() throws Exception {
69 this.restconfClientContext.close();
70 this.salRemoteBroker.close();