Add session-id to the operational datastore
[netconf.git] / apps / netconf-topology-singleton / src / main / java / org / opendaylight / netconf / topology / singleton / impl / ProxyYangTextSourceProvider.java
1 /*
2  * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
3  *
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
7  */
8 package org.opendaylight.netconf.topology.singleton.impl;
9
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.Set;
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;
22
23 public class ProxyYangTextSourceProvider implements RemoteYangTextSourceProvider {
24
25     private final ActorRef masterRef;
26     private final ExecutionContext executionContext;
27     private final Timeout actorResponseWaitTime;
28
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;
34     }
35
36     @Override
37     public Future<Set<SourceIdentifier>> getProvidedSources() {
38         // NOOP
39         return Futures.successful(Set.of());
40     }
41
42     @Override
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(
47             new OnComplete<>() {
48                 @Override
49                 public void onComplete(final Throwable failure, final Object success) {
50                     if (failure == null) {
51                         promise.success((YangTextSchemaSourceSerializationProxy) success);
52                     } else {
53                         promise.failure(failure);
54                     }
55                 }
56             }, executionContext);
57         return promise.future();
58     }
59 }