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
8 package org.opendaylight.netconf.topology.singleton.impl;
10 import akka.actor.ActorRef;
11 import akka.dispatch.Futures;
12 import akka.dispatch.OnComplete;
13 import akka.pattern.Patterns;
14 import akka.util.Timeout;
15 import java.util.Collections;
17 import org.opendaylight.controller.cluster.schema.provider.RemoteYangTextSourceProvider;
18 import org.opendaylight.controller.cluster.schema.provider.impl.YangTextSchemaSourceSerializationProxy;
19 import org.opendaylight.netconf.topology.singleton.messages.YangTextSchemaSourceRequest;
20 import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
21 import scala.concurrent.ExecutionContext;
22 import scala.concurrent.Future;
23 import scala.concurrent.impl.Promise;
25 public class ProxyYangTextSourceProvider implements RemoteYangTextSourceProvider {
27 private final ActorRef masterRef;
28 private final ExecutionContext executionContext;
29 private final Timeout actorResponseWaitTime;
31 public ProxyYangTextSourceProvider(final ActorRef masterRef, final ExecutionContext executionContext,
32 final Timeout actorResponseWaitTime) {
33 this.masterRef = masterRef;
34 this.executionContext = executionContext;
35 this.actorResponseWaitTime = actorResponseWaitTime;
39 public Future<Set<SourceIdentifier>> getProvidedSources() {
41 return Futures.successful(Collections.emptySet());
45 public Future<YangTextSchemaSourceSerializationProxy> getYangTextSchemaSource(
46 final SourceIdentifier sourceIdentifier) {
48 final Future<Object> scalaFuture = Patterns.ask(masterRef,
49 new YangTextSchemaSourceRequest(sourceIdentifier), actorResponseWaitTime);
51 final Promise.DefaultPromise<YangTextSchemaSourceSerializationProxy> promise = new Promise.DefaultPromise<>();
53 scalaFuture.onComplete(new OnComplete<Object>() {
55 public void onComplete(final Throwable failure, final Object success) {
56 if (failure != null) {
57 promise.failure(failure);
61 promise.success((YangTextSchemaSourceSerializationProxy) success);
65 return promise.future();