2 * Copyright (c) 2015 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
9 package org.opendaylight.controller.cluster.schema.provider.impl;
11 import com.google.common.annotations.Beta;
12 import com.google.common.util.concurrent.CheckedFuture;
13 import com.google.common.util.concurrent.FutureCallback;
14 import com.google.common.util.concurrent.Futures;
15 import java.io.IOException;
17 import javax.annotation.Nonnull;
18 import org.opendaylight.controller.cluster.schema.provider.RemoteYangTextSourceProvider;
19 import org.opendaylight.yangtools.yang.model.repo.api.SchemaRepository;
20 import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
21 import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
22 import org.slf4j.Logger;
23 import org.slf4j.LoggerFactory;
24 import scala.concurrent.Future;
25 import scala.concurrent.Promise;
28 * Remote schema provider implementation backed by local schema provider.
31 public class RemoteYangTextSourceProviderImpl implements RemoteYangTextSourceProvider {
32 private static final Logger LOG = LoggerFactory.getLogger(RemoteYangTextSourceProviderImpl.class);
34 private final SchemaRepository repository;
35 private final Set<SourceIdentifier> providedSources;
37 public RemoteYangTextSourceProviderImpl(SchemaRepository repository, Set<SourceIdentifier> providedSources) {
38 this.repository = repository;
39 this.providedSources = providedSources;
43 public Future<Set<SourceIdentifier>> getProvidedSources() {
44 return akka.dispatch.Futures.successful(providedSources);
48 public Future<YangTextSchemaSourceSerializationProxy> getYangTextSchemaSource(SourceIdentifier identifier) {
49 LOG.trace("Sending yang schema source for {}", identifier);
51 final Promise<YangTextSchemaSourceSerializationProxy> promise = akka.dispatch.Futures.promise();
52 CheckedFuture<YangTextSchemaSource, ?> future =
53 repository.getSchemaSource(identifier, YangTextSchemaSource.class);
55 Futures.addCallback(future, new FutureCallback<YangTextSchemaSource>() {
57 public void onSuccess(@Nonnull YangTextSchemaSource result) {
59 promise.success(new YangTextSchemaSourceSerializationProxy(result));
60 } catch (IOException e) {
61 LOG.warn("Unable to read schema source for {}", result.getIdentifier(), e);
67 public void onFailure(Throwable failure) {
68 LOG.warn("Unable to retrieve schema source from provider", failure);
69 promise.failure(failure);
73 return promise.future();