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;
10 import com.google.common.base.Preconditions;
12 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ConsumerContext;
13 import org.opendaylight.controller.sal.binding.api.BindingAwareConsumer;
14 import org.opendaylight.controller.sal.restconf.broker.SalRemoteServiceBroker;
15 import org.opendaylight.yangtools.restconf.client.RestconfClientFactory;
16 import org.opendaylight.yangtools.restconf.client.api.RestconfClientContext;
17 import org.opendaylight.yangtools.restconf.client.api.UnsupportedProtocolException;
18 import org.opendaylight.yangtools.sal.binding.generator.impl.ModuleInfoBackedContext;
19 import org.opendaylight.yangtools.yang.binding.util.BindingReflections;
20 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
21 import org.opendaylight.yangtools.yang.model.api.SchemaContextHolder;
22 import org.slf4j.Logger;
23 import org.slf4j.LoggerFactory;
25 class SalRemoteClientImpl implements SalRemoteClient, SchemaContextHolder {
27 private static final Logger logger = LoggerFactory.getLogger(SalRemoteClientImpl.class);
29 private final RestconfClientContext restconfClientContext;
30 private final SalRemoteServiceBroker salRemoteBroker;
32 private SchemaContext schemaContext;
34 public SalRemoteClientImpl(final URL url) {
35 Preconditions.checkNotNull(url);
38 final ModuleInfoBackedContext moduleInfo = ModuleInfoBackedContext.create();
39 moduleInfo.addModuleInfos(BindingReflections.loadModuleInfos());
40 schemaContext = moduleInfo.tryToCreateSchemaContext().get();
42 this.restconfClientContext = new RestconfClientFactory().getRestconfClientContext(url,this);
44 this.salRemoteBroker = new SalRemoteServiceBroker("remote-broker", restconfClientContext);
45 this.salRemoteBroker.start();
46 } catch (UnsupportedProtocolException e) {
47 logger.error("Unsupported protocol {}.", url.getProtocol(), e);
48 throw new IllegalArgumentException("Unsupported protocol.", e);
53 public ConsumerContext registerConsumer() {
54 return this.salRemoteBroker.registerConsumer(new BindingAwareConsumer() {
57 public void onSessionInitialized(ConsumerContext session) {
63 public SchemaContext getSchemaContext() {
68 public void close() throws Exception {
69 this.restconfClientContext.close();
70 this.salRemoteBroker.close();