Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add methods to KiwiIO that can "close" any object #1162

Closed
sleberknight opened this issue Jul 11, 2024 · 0 comments · Fixed by #1176
Closed

Add methods to KiwiIO that can "close" any object #1162

sleberknight opened this issue Jul 11, 2024 · 0 comments · Fixed by #1176
Assignees
Labels
new feature A new feature such as a new class, method, package, group of classes, etc.
Milestone

Comments

@sleberknight
Copy link
Member

sleberknight commented Jul 11, 2024

Some classes have a close method but don't implement AutoCloseable or Closeable. For example, until version 3.1.0, the Jakarta REST Client has a close method but doesn't implement AutoCloseable. Similarly, java.util.concurrent.ExecutorService has shutdown and shutdownNow methods.

Sometimes, for example during an application shutdown process, it would be nice to be able to call these methods and ignore exceptions the way KiwiIO.closeQuietly does for Closeable objects.

This task adds new methods to KiwiIO that can "close" objects which do not implement AutoCloseable or Closeable, such as the Jakarta REST Client (before version 3.1.0) and the JDK's ExecutorService.

Proposed methods:

  • closeObjectQuietly(Object object)
  • closeObjectsQuietly(Object... objects)
  • closeObjectQuietly(String closeMethodName, Object object)
  • closeObjectsQuietly(String closeMethodName, Object... objects)

The methods that only accept Object will assume the method name is close. The other methods explicitly accept a method name to be used to "close" those objects. For example, shutdown or shutdownNow for an ExecutorService. The method name argument is first so that the varargs overload can be used naturally. Otherwise, you would not be able to use the varargs syntax and would need to explicitly create an Object[] array.

The proposed method names include the word "Object" to make it more clear they are doing something different from closing a Closeable, i.e., that they will attempt to "close" any Object regardless of what interfaces it implements or doesn't.

@sleberknight sleberknight added the new feature A new feature such as a new class, method, package, group of classes, etc. label Jul 11, 2024
@sleberknight sleberknight added this to the 4.2.0 milestone Jul 11, 2024
@sleberknight sleberknight self-assigned this Jul 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new feature A new feature such as a new class, method, package, group of classes, etc.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant