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.base.Preconditions;
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 javax.annotation.Nonnull;
20 import org.opendaylight.controller.cluster.schema.provider.RemoteYangTextSourceProvider;
21 import org.opendaylight.yangtools.yang.model.repo.api.SchemaRepository;
22 import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
23 import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
24 import org.slf4j.Logger;
25 import org.slf4j.LoggerFactory;
26 import scala.concurrent.Future;
27 import scala.concurrent.Promise;
30 * Remote schema provider implementation backed by local schema provider.
33 public class RemoteYangTextSourceProviderImpl implements RemoteYangTextSourceProvider {
34 private static final Logger LOG = LoggerFactory.getLogger(RemoteYangTextSourceProviderImpl.class);
36 private final SchemaRepository repository;
37 private final Set<SourceIdentifier> providedSources;
39 public RemoteYangTextSourceProviderImpl(final SchemaRepository repository,
40 final Set<SourceIdentifier> providedSources) {
41 this.repository = Preconditions.checkNotNull(repository);
42 this.providedSources = providedSources;
46 public Future<Set<SourceIdentifier>> getProvidedSources() {
47 return akka.dispatch.Futures.successful(providedSources);
51 public Future<YangTextSchemaSourceSerializationProxy> getYangTextSchemaSource(final SourceIdentifier identifier) {
52 LOG.trace("Sending yang schema source for {}", identifier);
54 final Promise<YangTextSchemaSourceSerializationProxy> promise = akka.dispatch.Futures.promise();
55 ListenableFuture<YangTextSchemaSource> future =
56 repository.getSchemaSource(identifier, YangTextSchemaSource.class);
58 Futures.addCallback(future, new FutureCallback<YangTextSchemaSource>() {
60 public void onSuccess(@Nonnull final YangTextSchemaSource result) {
62 promise.success(new YangTextSchemaSourceSerializationProxy(result));
63 } catch (IOException e) {
64 LOG.warn("Unable to read schema source for {}", result.getIdentifier(), e);
70 public void onFailure(final Throwable failure) {
71 LOG.warn("Unable to retrieve schema source from provider", failure);
72 promise.failure(failure);
74 }, MoreExecutors.directExecutor());
76 return promise.future();