Cleanup warnings
[controller.git] / opendaylight / md-sal / sal-clustering-commons / src / main / java / org / opendaylight / controller / cluster / schema / provider / impl / RemoteYangTextSourceProviderImpl.java
1 /*
2  * Copyright (c) 2015 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
9 package org.opendaylight.controller.cluster.schema.provider.impl;
10
11 import com.google.common.annotations.Beta;
12 import com.google.common.base.Preconditions;
13 import com.google.common.util.concurrent.FutureCallback;
14 import com.google.common.util.concurrent.Futures;
15 import com.google.common.util.concurrent.ListenableFuture;
16 import com.google.common.util.concurrent.MoreExecutors;
17 import java.io.IOException;
18 import java.util.Set;
19 import javax.annotation.Nonnull;
20 import org.opendaylight.controller.cluster.schema.provider.RemoteYangTextSourceProvider;
21 import org.opendaylight.yangtools.yang.model.repo.api.SchemaRepository;
22 import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
23 import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
24 import org.slf4j.Logger;
25 import org.slf4j.LoggerFactory;
26 import scala.concurrent.Future;
27 import scala.concurrent.Promise;
28
29 /**
30  *  Remote schema provider implementation backed by local schema provider.
31  */
32 @Beta
33 public class RemoteYangTextSourceProviderImpl implements RemoteYangTextSourceProvider {
34     private static final Logger LOG = LoggerFactory.getLogger(RemoteYangTextSourceProviderImpl.class);
35
36     private final SchemaRepository repository;
37     private final Set<SourceIdentifier> providedSources;
38
39     public RemoteYangTextSourceProviderImpl(final SchemaRepository repository,
40             final Set<SourceIdentifier> providedSources) {
41         this.repository = Preconditions.checkNotNull(repository);
42         this.providedSources = providedSources;
43     }
44
45     @Override
46     public Future<Set<SourceIdentifier>> getProvidedSources() {
47         return akka.dispatch.Futures.successful(providedSources);
48     }
49
50     @Override
51     public Future<YangTextSchemaSourceSerializationProxy> getYangTextSchemaSource(final SourceIdentifier identifier) {
52         LOG.trace("Sending yang schema source for {}", identifier);
53
54         final Promise<YangTextSchemaSourceSerializationProxy> promise = akka.dispatch.Futures.promise();
55         ListenableFuture<YangTextSchemaSource> future =
56                 repository.getSchemaSource(identifier, YangTextSchemaSource.class);
57
58         Futures.addCallback(future, new FutureCallback<YangTextSchemaSource>() {
59             @Override
60             public void onSuccess(@Nonnull final YangTextSchemaSource result) {
61                 try {
62                     promise.success(new YangTextSchemaSourceSerializationProxy(result));
63                 } catch (IOException e) {
64                     LOG.warn("Unable to read schema source for {}", result.getIdentifier(), e);
65                     promise.failure(e);
66                 }
67             }
68
69             @Override
70             public void onFailure(final Throwable failure) {
71                 LOG.warn("Unable to retrieve schema source from provider", failure);
72                 promise.failure(failure);
73             }
74         }, MoreExecutors.directExecutor());
75
76         return promise.future();
77     }
78 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.