* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-
package org.opendaylight.netconf.topology.singleton.impl;
-import akka.actor.ActorContext;
import akka.actor.ActorRef;
import akka.dispatch.Futures;
import akka.dispatch.OnComplete;
import akka.pattern.Patterns;
-import com.google.common.collect.Sets;
+import akka.util.Timeout;
import java.util.Set;
-import javax.annotation.Nonnull;
import org.opendaylight.controller.cluster.schema.provider.RemoteYangTextSourceProvider;
import org.opendaylight.controller.cluster.schema.provider.impl.YangTextSchemaSourceSerializationProxy;
-import org.opendaylight.netconf.topology.singleton.impl.utils.NetconfTopologyUtils;
import org.opendaylight.netconf.topology.singleton.messages.YangTextSchemaSourceRequest;
import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
+import scala.concurrent.ExecutionContext;
import scala.concurrent.Future;
-import scala.concurrent.impl.Promise;
public class ProxyYangTextSourceProvider implements RemoteYangTextSourceProvider {
private final ActorRef masterRef;
- private final ActorContext actorContext;
+ private final ExecutionContext executionContext;
+ private final Timeout actorResponseWaitTime;
- public ProxyYangTextSourceProvider(final ActorRef masterRef, final ActorContext actorContext) {
+ public ProxyYangTextSourceProvider(final ActorRef masterRef, final ExecutionContext executionContext,
+ final Timeout actorResponseWaitTime) {
this.masterRef = masterRef;
- this.actorContext = actorContext;
+ this.executionContext = executionContext;
+ this.actorResponseWaitTime = actorResponseWaitTime;
}
@Override
public Future<Set<SourceIdentifier>> getProvidedSources() {
// NOOP
- return Futures.successful(Sets.newHashSet());
+ return Futures.successful(Set.of());
}
@Override
public Future<YangTextSchemaSourceSerializationProxy> getYangTextSchemaSource(
- @Nonnull final SourceIdentifier sourceIdentifier) {
-
- final Future<Object> scalaFuture = Patterns.ask(masterRef,
- new YangTextSchemaSourceRequest(sourceIdentifier), NetconfTopologyUtils.TIMEOUT);
-
- final Promise.DefaultPromise<YangTextSchemaSourceSerializationProxy> promise = new Promise.DefaultPromise<>();
-
- scalaFuture.onComplete(new OnComplete<Object>() {
- @Override
- public void onComplete(final Throwable failure, final Object success) throws Throwable {
- if (failure != null) {
- promise.failure(failure);
- return;
+ final SourceIdentifier sourceIdentifier) {
+ final var promise = Futures.<YangTextSchemaSourceSerializationProxy>promise();
+ Patterns.ask(masterRef, new YangTextSchemaSourceRequest(sourceIdentifier), actorResponseWaitTime).onComplete(
+ new OnComplete<>() {
+ @Override
+ public void onComplete(final Throwable failure, final Object success) {
+ if (failure == null) {
+ promise.success((YangTextSchemaSourceSerializationProxy) success);
+ } else {
+ promise.failure(failure);
+ }
}
- if (success instanceof Throwable) {
- promise.failure((Throwable) success);
- return;
- }
- promise.success((YangTextSchemaSourceSerializationProxy) success);
- }
- }, actorContext.dispatcher());
-
+ }, executionContext);
return promise.future();
-
}
}