Service-notification handling for Renderer
[transportpce.git] / servicehandler / src / main / java / org / opendaylight / transportpce / servicehandler / stub / StubRendererServiceOperations.java
index d87a4a7f794e1f3ce078ee871d0ad44279e5ed51..504d4e941bcbaa0b97357c61c42c8c140cae8136 100644 (file)
@@ -8,7 +8,16 @@
 package org.opendaylight.transportpce.servicehandler.stub;
 
 import com.google.common.util.concurrent.ListenableFuture;
+import com.google.common.util.concurrent.ListeningExecutorService;
+import com.google.common.util.concurrent.MoreExecutors;
+
+import java.util.concurrent.Callable;
 import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Executors;
+
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
+import org.opendaylight.transportpce.renderer.NetworkModelWavelengthService;
 import org.opendaylight.transportpce.renderer.provisiondevice.RendererServiceOperations;
 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017.ServiceDeleteInput;
 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017.ServiceDeleteOutput;
@@ -20,31 +29,50 @@ import org.slf4j.LoggerFactory;
 
 public class StubRendererServiceOperations implements RendererServiceOperations {
     private static final Logger LOG = LoggerFactory.getLogger(StubRendererServiceOperations.class);
+    private StubrendererImpl stubrendererImpl;
+    private final ListeningExecutorService executor;
+
+    public StubRendererServiceOperations(NetworkModelWavelengthService networkModelWavelengthService,
+            DataBroker dataBroker, NotificationPublishService notificationPublishService) {
+        this.stubrendererImpl =
+                new StubrendererImpl(networkModelWavelengthService, dataBroker, notificationPublishService);
+        executor = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(2));
+    }
 
     @Override
-    public ServiceImplementationRequestOutput serviceImplementation(ServiceImplementationRequestInput input) {
-        ListenableFuture<RpcResult<ServiceImplementationRequestOutput>> rpcResultFuture = StubrendererImpl
-                .serviceImplementation(input);
-        try {
-            return rpcResultFuture.get().getResult();
-        } catch (InterruptedException e) {
-            LOG.error("RPC serviceImplementation failed !",e);
-        } catch (ExecutionException e) {
-            LOG.error("RPC serviceImplementation failed !",e);
-        }
-        return null;
+    public ListenableFuture<ServiceImplementationRequestOutput>
+            serviceImplementation(ServiceImplementationRequestInput input) {
+        return executor.submit(new Callable<ServiceImplementationRequestOutput>() {
+
+            @Override
+            public ServiceImplementationRequestOutput call() {
+                ListenableFuture<RpcResult<ServiceImplementationRequestOutput>> rpcResultFuture =
+                        stubrendererImpl.serviceImplementation(input);
+                try {
+                    return rpcResultFuture.get().getResult();
+                } catch (InterruptedException | ExecutionException e) {
+                    LOG.error("RPC serviceImplementation failed !", e);
+                }
+                return null;
+            }
+        });
     }
 
     @Override
-    public ServiceDeleteOutput serviceDelete(ServiceDeleteInput input) {
-        ListenableFuture<RpcResult<ServiceDeleteOutput>> rpcResultFuture = StubrendererImpl.serviceDelete(input);
-        try {
-            return rpcResultFuture.get().getResult();
-        } catch (InterruptedException e) {
-            LOG.error("RPC serviceDelete failed !",e);
-        } catch (ExecutionException e) {
-            LOG.error("RPC serviceDelete failed !",e);
-        }
-        return null;
+    public ListenableFuture<ServiceDeleteOutput> serviceDelete(ServiceDeleteInput input) {
+        return executor.submit(new Callable<ServiceDeleteOutput>() {
+
+            @Override
+            public ServiceDeleteOutput call() {
+                ListenableFuture<RpcResult<ServiceDeleteOutput>> rpcResultFuture =
+                        stubrendererImpl.serviceDelete(input);
+                try {
+                    return rpcResultFuture.get().getResult();
+                } catch (InterruptedException | ExecutionException e) {
+                    LOG.error("RPC serviceDelete failed !", e);
+                }
+                return null;
+            }
+        });
     }
 }