2 * Copyright © 2018 Orange, 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.transportpce.servicehandler.stub;
10 import com.google.common.util.concurrent.ListenableFuture;
11 import com.google.common.util.concurrent.ListeningExecutorService;
12 import com.google.common.util.concurrent.MoreExecutors;
14 import java.util.concurrent.Callable;
15 import java.util.concurrent.ExecutionException;
16 import java.util.concurrent.Executors;
18 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
19 import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
20 import org.opendaylight.transportpce.renderer.NetworkModelWavelengthService;
21 import org.opendaylight.transportpce.renderer.provisiondevice.RendererServiceOperations;
22 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017.ServiceDeleteInput;
23 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017.ServiceDeleteOutput;
24 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017.ServiceImplementationRequestInput;
25 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017.ServiceImplementationRequestOutput;
26 import org.opendaylight.yangtools.yang.common.RpcResult;
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
30 public class StubRendererServiceOperations implements RendererServiceOperations {
31 private static final Logger LOG = LoggerFactory.getLogger(StubRendererServiceOperations.class);
32 private StubrendererImpl stubrendererImpl;
33 private final ListeningExecutorService executor;
35 public StubRendererServiceOperations(NetworkModelWavelengthService networkModelWavelengthService,
36 DataBroker dataBroker, NotificationPublishService notificationPublishService) {
37 this.stubrendererImpl =
38 new StubrendererImpl(networkModelWavelengthService, dataBroker, notificationPublishService);
39 executor = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(2));
43 public ListenableFuture<ServiceImplementationRequestOutput>
44 serviceImplementation(ServiceImplementationRequestInput input) {
45 return executor.submit(new Callable<ServiceImplementationRequestOutput>() {
48 public ServiceImplementationRequestOutput call() {
49 ListenableFuture<RpcResult<ServiceImplementationRequestOutput>> rpcResultFuture =
50 stubrendererImpl.serviceImplementation(input);
52 return rpcResultFuture.get().getResult();
53 } catch (InterruptedException | ExecutionException e) {
54 LOG.error("RPC serviceImplementation failed !", e);
62 public ListenableFuture<ServiceDeleteOutput> serviceDelete(ServiceDeleteInput input) {
63 return executor.submit(new Callable<ServiceDeleteOutput>() {
66 public ServiceDeleteOutput call() {
67 ListenableFuture<RpcResult<ServiceDeleteOutput>> rpcResultFuture =
68 stubrendererImpl.serviceDelete(input);
70 return rpcResultFuture.get().getResult();
71 } catch (InterruptedException | ExecutionException e) {
72 LOG.error("RPC serviceDelete failed !", e);