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 akka.dispatch.OnComplete;
11 import com.google.common.annotations.Beta;
12 import com.google.common.util.concurrent.ListenableFuture;
13 import com.google.common.util.concurrent.SettableFuture;
14 import org.opendaylight.controller.cluster.schema.provider.RemoteYangTextSourceProvider;
15 import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
16 import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
17 import org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceProvider;
18 import org.slf4j.Logger;
19 import org.slf4j.LoggerFactory;
20 import scala.concurrent.ExecutionContext;
21 import scala.concurrent.Future;
24 * Provides schema sources from {@link RemoteYangTextSourceProvider}.
27 public class RemoteSchemaProvider implements SchemaSourceProvider<YangTextSchemaSource> {
28 private static final Logger LOG = LoggerFactory.getLogger(RemoteSchemaProvider.class);
30 private final RemoteYangTextSourceProvider remoteRepo;
31 private final ExecutionContext executionContext;
33 public RemoteSchemaProvider(final RemoteYangTextSourceProvider remoteRepo,
34 final ExecutionContext executionContext) {
35 this.remoteRepo = remoteRepo;
36 this.executionContext = executionContext;
40 public ListenableFuture<YangTextSchemaSource> getSource(final SourceIdentifier sourceIdentifier) {
41 LOG.trace("Getting yang schema source for {}", sourceIdentifier.name().getLocalName());
43 Future<YangTextSchemaSourceSerializationProxy> result = remoteRepo.getYangTextSchemaSource(sourceIdentifier);
45 final SettableFuture<YangTextSchemaSource> res = SettableFuture.create();
46 result.onComplete(new OnComplete<YangTextSchemaSourceSerializationProxy>() {
48 public void onComplete(final Throwable throwable,
49 final YangTextSchemaSourceSerializationProxy yangTextSchemaSourceSerializationProxy) {
50 if (yangTextSchemaSourceSerializationProxy != null) {
51 res.set(yangTextSchemaSourceSerializationProxy.getRepresentation());
53 if (throwable != null) {
54 res.setException(throwable);