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
8 package org.opendaylight.controller.cluster.schema.provider.impl;
10 import static java.util.Objects.requireNonNull;
12 import com.google.common.annotations.Beta;
13 import com.google.common.util.concurrent.FutureCallback;
14 import com.google.common.util.concurrent.Futures;
15 import com.google.common.util.concurrent.ListenableFuture;
16 import com.google.common.util.concurrent.MoreExecutors;
17 import java.io.IOException;
19 import org.opendaylight.controller.cluster.schema.provider.RemoteYangTextSourceProvider;
20 import org.opendaylight.yangtools.yang.model.repo.api.SchemaRepository;
21 import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
22 import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
25 import scala.concurrent.Future;
26 import scala.concurrent.Promise;
29 * Remote schema provider implementation backed by local schema provider.
32 public class RemoteYangTextSourceProviderImpl implements RemoteYangTextSourceProvider {
33 private static final Logger LOG = LoggerFactory.getLogger(RemoteYangTextSourceProviderImpl.class);
35 private final SchemaRepository repository;
36 private final Set<SourceIdentifier> providedSources;
38 public RemoteYangTextSourceProviderImpl(final SchemaRepository repository,
39 final Set<SourceIdentifier> providedSources) {
40 this.repository = requireNonNull(repository);
41 this.providedSources = providedSources;
45 public Future<Set<SourceIdentifier>> getProvidedSources() {
46 return akka.dispatch.Futures.successful(providedSources);
50 public Future<YangTextSchemaSourceSerializationProxy> getYangTextSchemaSource(final SourceIdentifier identifier) {
51 LOG.trace("Sending yang schema source for {}", identifier);
53 final Promise<YangTextSchemaSourceSerializationProxy> promise = akka.dispatch.Futures.promise();
54 ListenableFuture<YangTextSchemaSource> future =
55 repository.getSchemaSource(identifier, YangTextSchemaSource.class);
57 Futures.addCallback(future, new FutureCallback<YangTextSchemaSource>() {
59 public void onSuccess(final YangTextSchemaSource result) {
61 promise.success(new YangTextSchemaSourceSerializationProxy(result));
62 } catch (IOException e) {
63 LOG.warn("Unable to read schema source for {}", result.getIdentifier(), e);
69 public void onFailure(final Throwable failure) {
70 LOG.warn("Unable to retrieve schema source from provider", failure);
71 promise.failure(failure);
73 }, MoreExecutors.directExecutor());
75 return promise.future();