Eliminate FutureDataFactory 89/107089/3
authorRobert Varga <robert.varga@pantheon.tech>
Wed, 26 Jul 2023 16:19:43 +0000 (18:19 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Wed, 26 Jul 2023 21:16:18 +0000 (23:16 +0200)
FutureCallbackTx now has only users dealing with transaction commit,
hence we can properly specialize it to FutureCallbackTx.

Change-Id: Ifb1425c41e8d4e860e6d3ea1547a62c6a60972f8
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/utils/FutureCallbackTx.java
restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/utils/FutureDataFactory.java [deleted file]
restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/utils/ResponseFactory.java

index 94e7e55fcb02f627e34cc94ea5d6c477aaf55704..9b31efde72462669d9a92d2df42915b0447361fb 100644 (file)
@@ -10,6 +10,7 @@ package org.opendaylight.restconf.nb.rfc8040.rests.utils;
 import com.google.common.base.Throwables;
 import com.google.common.util.concurrent.ListenableFuture;
 import java.util.concurrent.ExecutionException;
+import org.opendaylight.mdsal.common.api.CommitInfo;
 import org.opendaylight.mdsal.common.api.TransactionCommitFailedException;
 import org.opendaylight.netconf.api.DocumentedException;
 import org.opendaylight.netconf.api.NetconfDocumentedException;
@@ -45,9 +46,8 @@ final class FutureCallbackTx {
      *             if the Future throws an exception
      */
     // FIXME: this is a *synchronous operation* and has to die
-    static <T> void addCallback(final ListenableFuture<T> listenableFuture, final String txType,
-            final FutureDataFactory<? super T> dataFactory, final YangInstanceIdentifier path)
-                throws RestconfDocumentedException {
+    static void addCallback(final ListenableFuture<? extends CommitInfo> listenableFuture, final String txType,
+            final ResponseFactory dataFactory, final YangInstanceIdentifier path) throws RestconfDocumentedException {
         try {
             listenableFuture.get();
         } catch (InterruptedException e) {
diff --git a/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/utils/FutureDataFactory.java b/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/utils/FutureDataFactory.java
deleted file mode 100644 (file)
index 028fdff..0000000
+++ /dev/null
@@ -1,21 +0,0 @@
-/*
- * Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * 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.restconf.nb.rfc8040.rests.utils;
-
-class FutureDataFactory<T> {
-    private boolean statusFail = false;
-
-    void setFailureStatus() {
-        statusFail = true;
-    }
-
-    boolean getFailureStatus() {
-        return statusFail;
-    }
-
-}
index 2ba598920b8297b9f43309f7026272697d83cd8e..b653b88bb4a2e200752aa93a9aacd85a1d9b6d33 100644 (file)
@@ -12,31 +12,28 @@ import javax.ws.rs.core.Response;
 import javax.ws.rs.core.Response.ResponseBuilder;
 import javax.ws.rs.core.Response.Status;
 import org.eclipse.jdt.annotation.NonNull;
-import org.opendaylight.mdsal.common.api.CommitInfo;
 
-final class ResponseFactory extends FutureDataFactory<CommitInfo> {
-    private ResponseBuilder responseBuilder;
+final class ResponseFactory {
+    private final ResponseBuilder responseBuilder;
 
-    ResponseFactory() {
-    }
+    private boolean statusFail = false;
 
     ResponseFactory(final Status status) {
         responseBuilder = Response.status(status);
     }
 
-    ResponseFactory status(final Status status) {
-        responseBuilder = Response.status(status);
-        return this;
-    }
-
     ResponseFactory location(final URI location) {
         responseBuilder.location(location);
         return this;
     }
 
+    void setFailureStatus() {
+        statusFail = true;
+    }
+
     public @NonNull Response build() {
-        if (getFailureStatus()) {
-            responseBuilder = responseBuilder.status(Response.Status.INTERNAL_SERVER_ERROR);
+        if (statusFail) {
+            responseBuilder.status(Status.INTERNAL_SERVER_ERROR);
         }
         return responseBuilder.build();
     }