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;
16 import org.opendaylight.controller.cluster.schema.provider.RemoteYangTextSourceProvider;
17 import org.opendaylight.controller.cluster.schema.provider.impl.YangTextSchemaSourceSerializationProxy;
18 import org.opendaylight.netconf.topology.singleton.messages.YangTextSchemaSourceRequest;
19 import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
20 import scala.concurrent.ExecutionContext;
21 import scala.concurrent.Future;
23 public class ProxyYangTextSourceProvider implements RemoteYangTextSourceProvider {
25 private final ActorRef masterRef;
26 private final ExecutionContext executionContext;
27 private final Timeout actorResponseWaitTime;
29 public ProxyYangTextSourceProvider(final ActorRef masterRef, final ExecutionContext executionContext,
30 final Timeout actorResponseWaitTime) {
31 this.masterRef = masterRef;
32 this.executionContext = executionContext;
33 this.actorResponseWaitTime = actorResponseWaitTime;
37 public Future<Set<SourceIdentifier>> getProvidedSources() {
39 return Futures.successful(Set.of());
43 public Future<YangTextSchemaSourceSerializationProxy> getYangTextSchemaSource(
44 final SourceIdentifier sourceIdentifier) {
45 final var promise = Futures.<YangTextSchemaSourceSerializationProxy>promise();
46 Patterns.ask(masterRef, new YangTextSchemaSourceRequest(sourceIdentifier), actorResponseWaitTime).onComplete(
49 public void onComplete(final Throwable failure, final Object success) {
50 if (failure == null) {
51 promise.success((YangTextSchemaSourceSerializationProxy) success);
53 promise.failure(failure);
57 return promise.future();