This is an automated email from the ASF dual-hosted git repository.

adoroszlai pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ratis.git


The following commit(s) were added to refs/heads/master by this push:
     new 0d3512a72 RATIS-2469. Remove Command#close() (#1404)
0d3512a72 is described below

commit 0d3512a727d5bc3857acc4a1caf7cc4a970be972
Author: Doroszlai, Attila <[email protected]>
AuthorDate: Sun Mar 29 08:41:02 2026 +0200

    RATIS-2469. Remove Command#close() (#1404)
---
 .../java/org/apache/ratis/shell/cli/AbstractShell.java | 18 +-----------------
 .../main/java/org/apache/ratis/shell/cli/Command.java  |  9 +--------
 .../org/apache/ratis/shell/cli/sh/command/Context.java | 14 ++------------
 .../org/apache/ratis/shell/cli/sh/TestRatisShell.java  |  9 ++++-----
 .../ratis/shell/cli/sh/TestSecureRatisShell.java       |  4 ++--
 5 files changed, 10 insertions(+), 44 deletions(-)

diff --git 
a/ratis-shell/src/main/java/org/apache/ratis/shell/cli/AbstractShell.java 
b/ratis-shell/src/main/java/org/apache/ratis/shell/cli/AbstractShell.java
index e2679045e..a59e03cf8 100644
--- a/ratis-shell/src/main/java/org/apache/ratis/shell/cli/AbstractShell.java
+++ b/ratis-shell/src/main/java/org/apache/ratis/shell/cli/AbstractShell.java
@@ -19,12 +19,9 @@ package org.apache.ratis.shell.cli;
 
 import org.apache.commons.cli.CommandLine;
 import org.apache.ratis.shell.cli.sh.command.Context;
-import org.apache.ratis.thirdparty.com.google.common.io.Closer;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import java.io.Closeable;
-import java.io.IOException;
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.Map;
@@ -34,20 +31,16 @@ import java.util.TreeSet;
 /**
  * Abstract class for handling command line inputs.
  */
-public abstract class AbstractShell implements Closeable {
+public abstract class AbstractShell {
   private static final Logger LOG = 
LoggerFactory.getLogger(AbstractShell.class);
 
   private final Map<String, Command> mCommands;
-  private final Closer closer;
 
   /**
    * Creates a new instance of {@link AbstractShell}.
    */
   protected AbstractShell(Context context) {
-    closer = Closer.create();
     mCommands = loadCommands(context);
-    // Register all loaded commands under closer.
-    mCommands.values().forEach(closer::register);
   }
 
   /**
@@ -116,11 +109,6 @@ public abstract class AbstractShell implements Closeable {
     return mCommands.values();
   }
 
-  @Override
-  public void close() throws IOException {
-    closer.close();
-  }
-
   /**
    * @return name of the shell
    */
@@ -133,10 +121,6 @@ public abstract class AbstractShell implements Closeable {
    */
   protected abstract Map<String, Command> loadCommands(Context context);
 
-  protected Closer getCloser() {
-    return closer;
-  }
-
   /**
    * Prints usage for all commands.
    */
diff --git a/ratis-shell/src/main/java/org/apache/ratis/shell/cli/Command.java 
b/ratis-shell/src/main/java/org/apache/ratis/shell/cli/Command.java
index ae4e70107..bc2882bfe 100644
--- a/ratis-shell/src/main/java/org/apache/ratis/shell/cli/Command.java
+++ b/ratis-shell/src/main/java/org/apache/ratis/shell/cli/Command.java
@@ -23,7 +23,6 @@ import org.apache.commons.cli.DefaultParser;
 import org.apache.commons.cli.Options;
 import org.apache.commons.cli.ParseException;
 
-import java.io.Closeable;
 import java.io.IOException;
 import java.util.Collections;
 import java.util.Map;
@@ -32,7 +31,7 @@ import java.util.Optional;
 /**
  * An interface for all the commands that can be run from a shell.
  */
-public interface Command extends Comparable<Command>, Closeable {
+public interface Command extends Comparable<Command> {
 
   /**
    * Gets the command name as input from the shell.
@@ -119,10 +118,4 @@ public interface Command extends Comparable<Command>, 
Closeable {
    */
   String getDescription();
 
-  /**
-   * Used to close resources created by commands.
-   *
-   * @throws IOException if closing resources fails
-   */
-  default void close() throws IOException {}
 }
diff --git 
a/ratis-shell/src/main/java/org/apache/ratis/shell/cli/sh/command/Context.java 
b/ratis-shell/src/main/java/org/apache/ratis/shell/cli/sh/command/Context.java
index 6f80256d4..a29cbd026 100644
--- 
a/ratis-shell/src/main/java/org/apache/ratis/shell/cli/sh/command/Context.java
+++ 
b/ratis-shell/src/main/java/org/apache/ratis/shell/cli/sh/command/Context.java
@@ -24,11 +24,8 @@ import org.apache.ratis.conf.RaftProperties;
 import org.apache.ratis.protocol.RaftGroup;
 import org.apache.ratis.retry.ExponentialBackoffRetry;
 import org.apache.ratis.retry.RetryPolicy;
-import org.apache.ratis.thirdparty.com.google.common.io.Closer;
 import org.apache.ratis.util.TimeDuration;
 
-import java.io.Closeable;
-import java.io.IOException;
 import java.io.PrintStream;
 import java.util.Objects;
 import java.util.Properties;
@@ -37,7 +34,7 @@ import java.util.concurrent.TimeUnit;
 /**
  * A context for ratis-shell.
  */
-public final class Context implements Closeable {
+public final class Context {
   private static final TimeDuration DEFAULT_REQUEST_TIMEOUT = 
TimeDuration.valueOf(15, TimeUnit.SECONDS);
   private static final RetryPolicy DEFAULT_RETRY_POLICY = 
ExponentialBackoffRetry.newBuilder()
       .setBaseSleepTime(TimeDuration.valueOf(1000, TimeUnit.MILLISECONDS))
@@ -46,7 +43,6 @@ public final class Context implements Closeable {
       .build();
 
   private final PrintStream mPrintStream;
-  private final Closer mCloser;
 
   private final boolean cli;
   private final RetryPolicy retryPolicy;
@@ -63,8 +59,7 @@ public final class Context implements Closeable {
 
   public Context(PrintStream printStream, boolean cli, RetryPolicy retryPolicy,
       RaftProperties properties, Parameters parameters) {
-    mCloser = Closer.create();
-    mPrintStream = mCloser.register(Objects.requireNonNull(printStream, 
"printStream == null"));
+    mPrintStream = Objects.requireNonNull(printStream, "printStream == null");
 
     this.cli = cli;
     this.retryPolicy = retryPolicy != null? retryPolicy : DEFAULT_RETRY_POLICY;
@@ -115,9 +110,4 @@ public final class Context implements Closeable {
         .setRetryPolicy(getRetryPolicy())
         .build();
   }
-
-  @Override
-  public void close() throws IOException {
-    mCloser.close();
-  }
 }
diff --git 
a/ratis-test/src/test/java/org/apache/ratis/shell/cli/sh/TestRatisShell.java 
b/ratis-test/src/test/java/org/apache/ratis/shell/cli/sh/TestRatisShell.java
index 21f468512..7c42b6907 100644
--- a/ratis-test/src/test/java/org/apache/ratis/shell/cli/sh/TestRatisShell.java
+++ b/ratis-test/src/test/java/org/apache/ratis/shell/cli/sh/TestRatisShell.java
@@ -65,12 +65,11 @@ public class TestRatisShell extends BaseTest {
     final List<Command> expected = new 
ArrayList<>(loadCommands(RatisShell.class.getPackage().getName() + ".command"));
     Collections.sort(expected);
 
-    try(RatisShell shell = new RatisShell(OUT)) {
-      final List<Command> computed = new ArrayList<>(shell.getCommands());
-      Collections.sort(computed);
+    RatisShell shell = new RatisShell(OUT);
+    final List<Command> computed = new ArrayList<>(shell.getCommands());
+    Collections.sort(computed);
 
-      assertCommands(expected, computed);
-    }
+    assertCommands(expected, computed);
   }
 
   @Test
diff --git 
a/ratis-test/src/test/java/org/apache/ratis/shell/cli/sh/TestSecureRatisShell.java
 
b/ratis-test/src/test/java/org/apache/ratis/shell/cli/sh/TestSecureRatisShell.java
index 7f1149067..21e9fe229 100644
--- 
a/ratis-test/src/test/java/org/apache/ratis/shell/cli/sh/TestSecureRatisShell.java
+++ 
b/ratis-test/src/test/java/org/apache/ratis/shell/cli/sh/TestSecureRatisShell.java
@@ -85,8 +85,8 @@ public class TestSecureRatisShell extends BaseTest {
   }
 
   void runTestRatisShell(MiniRaftClusterWithGrpc cluster, boolean secure) 
throws Exception {
-    try(ByteArrayOutputStream out = new ByteArrayOutputStream(1 << 16);
-        RatisShell shell = newRatisShell(out, cluster.getProperties(), 
secure)) {
+    try (ByteArrayOutputStream out = new ByteArrayOutputStream(1 << 16)) {
+      RatisShell shell = newRatisShell(out, cluster.getProperties(), secure);
       shell.run("group", "info", "-peers", toCliArg(cluster.getPeers()));
       final String output = out.toString();
       LOG.info("output (secure? {}):\n{}", secure, output);

Reply via email to