2 * Copyright (c) 2016 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.netconf.topology.singleton.impl;
11 import akka.actor.ActorContext;
12 import akka.actor.ActorRef;
13 import akka.dispatch.Futures;
14 import akka.dispatch.OnComplete;
15 import akka.pattern.Patterns;
16 import com.google.common.collect.Sets;
18 import javax.annotation.Nonnull;
19 import org.opendaylight.controller.cluster.schema.provider.RemoteYangTextSourceProvider;
20 import org.opendaylight.controller.cluster.schema.provider.impl.YangTextSchemaSourceSerializationProxy;
21 import org.opendaylight.netconf.topology.singleton.impl.utils.NetconfTopologyUtils;
22 import org.opendaylight.netconf.topology.singleton.messages.YangTextSchemaSourceRequest;
23 import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
24 import scala.concurrent.Future;
25 import scala.concurrent.impl.Promise;
27 public class ProxyYangTextSourceProvider implements RemoteYangTextSourceProvider {
29 private final ActorRef masterRef;
30 private final ActorContext actorContext;
32 public ProxyYangTextSourceProvider(final ActorRef masterRef, final ActorContext actorContext) {
33 this.masterRef = masterRef;
34 this.actorContext = actorContext;
38 public Future<Set<SourceIdentifier>> getProvidedSources() {
40 return Futures.successful(Sets.newHashSet());
44 public Future<YangTextSchemaSourceSerializationProxy> getYangTextSchemaSource(
45 @Nonnull final SourceIdentifier sourceIdentifier) {
47 final Future<Object> scalaFuture = Patterns.ask(masterRef,
48 new YangTextSchemaSourceRequest(sourceIdentifier), NetconfTopologyUtils.TIMEOUT);
50 final Promise.DefaultPromise<YangTextSchemaSourceSerializationProxy> promise = new Promise.DefaultPromise<>();
52 scalaFuture.onComplete(new OnComplete<Object>() {
54 public void onComplete(final Throwable failure, final Object success) throws Throwable {
55 if (failure != null) {
56 promise.failure(failure);
59 if (success instanceof Throwable) {
60 promise.failure((Throwable) success);
63 promise.success((YangTextSchemaSourceSerializationProxy) success);
65 }, actorContext.dispatcher());
67 return promise.future();