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