Service-notification handling for Renderer
[transportpce.git] / servicehandler / src / main / java / org / opendaylight / transportpce / servicehandler / stub / StubRendererServiceOperations.java
1 /*
2  * Copyright © 2018 Orange, 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.transportpce.servicehandler.stub;
9
10 import com.google.common.util.concurrent.ListenableFuture;
11 import com.google.common.util.concurrent.ListeningExecutorService;
12 import com.google.common.util.concurrent.MoreExecutors;
13
14 import java.util.concurrent.Callable;
15 import java.util.concurrent.ExecutionException;
16 import java.util.concurrent.Executors;
17
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;
29
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;
34
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));
40     }
41
42     @Override
43     public ListenableFuture<ServiceImplementationRequestOutput>
44             serviceImplementation(ServiceImplementationRequestInput input) {
45         return executor.submit(new Callable<ServiceImplementationRequestOutput>() {
46
47             @Override
48             public ServiceImplementationRequestOutput call() {
49                 ListenableFuture<RpcResult<ServiceImplementationRequestOutput>> rpcResultFuture =
50                         stubrendererImpl.serviceImplementation(input);
51                 try {
52                     return rpcResultFuture.get().getResult();
53                 } catch (InterruptedException | ExecutionException e) {
54                     LOG.error("RPC serviceImplementation failed !", e);
55                 }
56                 return null;
57             }
58         });
59     }
60
61     @Override
62     public ListenableFuture<ServiceDeleteOutput> serviceDelete(ServiceDeleteInput input) {
63         return executor.submit(new Callable<ServiceDeleteOutput>() {
64
65             @Override
66             public ServiceDeleteOutput call() {
67                 ListenableFuture<RpcResult<ServiceDeleteOutput>> rpcResultFuture =
68                         stubrendererImpl.serviceDelete(input);
69                 try {
70                     return rpcResultFuture.get().getResult();
71                 } catch (InterruptedException | ExecutionException e) {
72                     LOG.error("RPC serviceDelete failed !", e);
73                 }
74                 return null;
75             }
76         });
77     }
78 }