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 akka.util.Timeout;
17 import com.google.common.collect.Sets;
19 import javax.annotation.Nonnull;
20 import org.opendaylight.controller.cluster.schema.provider.RemoteYangTextSourceProvider;
21 import org.opendaylight.controller.cluster.schema.provider.impl.YangTextSchemaSourceSerializationProxy;
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;
31 private final Timeout actorResponseWaitTime;
33 public ProxyYangTextSourceProvider(final ActorRef masterRef, final ActorContext actorContext,
34 final Timeout actorResponseWaitTime) {
35 this.masterRef = masterRef;
36 this.actorContext = actorContext;
37 this.actorResponseWaitTime = actorResponseWaitTime;
41 public Future<Set<SourceIdentifier>> getProvidedSources() {
43 return Futures.successful(Sets.newHashSet());
47 public Future<YangTextSchemaSourceSerializationProxy> getYangTextSchemaSource(
48 @Nonnull final SourceIdentifier sourceIdentifier) {
50 final Future<Object> scalaFuture = Patterns.ask(masterRef,
51 new YangTextSchemaSourceRequest(sourceIdentifier), actorResponseWaitTime);
53 final Promise.DefaultPromise<YangTextSchemaSourceSerializationProxy> promise = new Promise.DefaultPromise<>();
55 scalaFuture.onComplete(new OnComplete<Object>() {
57 public void onComplete(final Throwable failure, final Object success) throws Throwable {
58 if (failure != null) {
59 promise.failure(failure);
62 if (success instanceof Throwable) {
63 promise.failure((Throwable) success);
66 promise.success((YangTextSchemaSourceSerializationProxy) success);
68 }, actorContext.dispatcher());
70 return promise.future();