Seal AbstractProxyTransaction 00/109500/5
authorRobert Varga <robert.varga@pantheon.tech>
Sun, 31 Dec 2023 00:19:58 +0000 (01:19 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Sun, 31 Dec 2023 09:21:47 +0000 (10:21 +0100)
Class hierarchy here is firmly defined, express that through
seal/permits.

Change-Id: I3fc8f04133a788b0c89e156d0e8deb5a5abead7a
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/databroker/actors/dds/AbstractProxyTransaction.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/databroker/actors/dds/LocalProxyTransaction.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/databroker/actors/dds/RemoteProxyTransaction.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/databroker/actors/dds/AbstractClientHandleTest.java

index 81448cac4249fd0ae8befb344b89a259dc883db4..14ad54699161a60719ea846d353c46e73fb4adea 100644 (file)
@@ -65,11 +65,9 @@ import org.slf4j.LoggerFactory;
  * <p>
  * This class interacts with the queueing mechanism in ClientActorBehavior, hence once we arrive at a decision
  * to use either a local or remote implementation, we are stuck with it. We can re-evaluate on the next transaction.
- *
- * @author Robert Varga
  */
-// FIXME: sealed when we have JDK17+
-abstract class AbstractProxyTransaction implements Identifiable<TransactionIdentifier> {
+abstract sealed class AbstractProxyTransaction implements Identifiable<TransactionIdentifier>
+        permits LocalProxyTransaction, RemoteProxyTransaction {
     /**
      * Marker object used instead of read-type of requests, which are satisfied only once. This has a lower footprint
      * and allows compressing multiple requests into a single entry. This class is not thread-safe.
index 93c8c9350e2d4fc0c164e8c5a700b9125c494abd..6c4006e93f0a2197937ce7ff90b3b7c5a3e8b00a 100644 (file)
@@ -51,11 +51,9 @@ import org.slf4j.LoggerFactory;
  * <p>
  * This class is not thread-safe as usual with transactions. Since it does not interact with the backend until the
  * transaction is submitted, at which point this class gets out of the picture, this is not a cause for concern.
- *
- * @author Robert Varga
  */
-// FIXME: sealed when we have JDK17+
-abstract class LocalProxyTransaction extends AbstractProxyTransaction {
+abstract sealed class LocalProxyTransaction extends AbstractProxyTransaction
+        permits LocalReadOnlyProxyTransaction, LocalReadWriteProxyTransaction {
     private static final Logger LOG = LoggerFactory.getLogger(LocalProxyTransaction.class);
 
     private final @NonNull TransactionIdentifier identifier;
@@ -198,8 +196,7 @@ abstract class LocalProxyTransaction extends AbstractProxyTransaction {
     @Override
     final void forwardToRemote(final RemoteProxyTransaction successor, final TransactionRequest<?> request,
                          final Consumer<Response<?, ?>> callback) {
-        if (request instanceof CommitLocalTransactionRequest) {
-            final CommitLocalTransactionRequest req = (CommitLocalTransactionRequest) request;
+        if (request instanceof final CommitLocalTransactionRequest req) {
             final DataTreeModification mod = req.getModification();
 
             LOG.debug("Applying modification {} to successor {}", mod, successor);
index 318d64ccefa99359d0c9a4b9e36f777bc3f44087..946e3341fd8f7778fdbf940299deb72112a61284 100644 (file)
@@ -64,8 +64,6 @@ import org.slf4j.LoggerFactory;
  * <p>
  * This class is not safe to access from multiple application threads, as is usual for transactions. Its internal state
  * transitions based on backend responses are thread-safe.
- *
- * @author Robert Varga
  */
 final class RemoteProxyTransaction extends AbstractProxyTransaction {
     private static final Logger LOG = LoggerFactory.getLogger(RemoteProxyTransaction.class);
index eb6775cf3287f42ba3059d84a39eade49d35153d..37f38810ce5a8a4a344720a6a7dc2e867713fe8c 100644 (file)
@@ -147,8 +147,7 @@ public abstract class AbstractClientHandleTest<T extends AbstractClientHandle<Ab
 
     @Test
     public void testEnsureProxy() {
-        final AbstractProxyTransaction expected = mock(AbstractProxyTransaction.class);
-        final AbstractProxyTransaction proxy = handle.ensureProxy(PATH);
+        final var proxy = handle.ensureProxy(PATH);
         assertEquals(0, proxy.getIdentifier().getTransactionId());
     }