OpenSearch/libs
Kartik fb9e150076
Refactoring gated and ref-counted interfaces and their implementations (#2396)
* Reducing duplication in plugins around ref-counted releasable classes

Both AmazonEc2Reference and AmazonS3Reference duplicate the same logic - a subclass of AbstractRefCounted that also implements Releasable. This change centralizes this paradigm into a AbstractRefCountedReleasable class and supports both clients via generics. It also updates all fetching implementations to use the get() method instead of client()

Signed-off-by: Kartik Ganesh <gkart@amazon.com>

* Introduce Reference classes for the Closeable and AutoCloseable interfaces

These classes allow you to wrap a reference instance with an onClose runnable that is executed when close() is invoked. Two separate classes are needed because the close() signatures for the two interfaces are different. This change takes the first step to have implementing classes extend from these generic superclasses, before attempting to remove the subclasses entirely. The get() method is also replaced throughout the code base.

Note that there is also a separate Releasable interface that has a similar access pattern, but is implemented separately. This is used in AbstractRefCountedReleasable introduced in a prior commit

Signed-off-by: Kartik Ganesh <gkart@amazon.com>

* More improvements and refactoring

* Functionality around one-way gating is now moved to a dedicated class - OneWayGate. This replaces duplicate functionality throughout the code.
* The two *Reference classes have been renamed to Gated* since that better represents their functionality
* The AbstractRefCountedReleasable has been improved to no longer be abstract by accepting the shutdown hook. This removes the need for the inner class in ReleasableBytesReference, and further simplifies the plugin subclasses (these could probably be removed entirely).
* Finally, unit tests have been added for some classes

Signed-off-by: Kartik Ganesh <gkart@amazon.com>

* Added tests for GatedCloseable

Also updated the license information in GatedAutoCloseableTests

Signed-off-by: Kartik Ganesh <gkart@amazon.com>

* Fixing license information in new files

Signed-off-by: Kartik Ganesh <gkart@amazon.com>

* Added unit tests for RefCountedReleasable

Signed-off-by: Kartik Ganesh <gkart@amazon.com>
2022-03-09 12:21:09 -08:00
..
cli Bump jopt-simple from 5.0.2 to 5.0.4 in /libs/cli (#2120) 2022-02-18 15:27:51 -08:00
core Refactoring gated and ref-counted interfaces and their implementations (#2396) 2022-03-09 12:21:09 -08:00
dissect Run spotless and exclude checkstyle on libs module (#1428) 2021-10-26 09:45:26 -05:00
geo Run spotless and exclude checkstyle on libs module (#1428) 2021-10-26 09:45:26 -05:00
grok Bump joni from 2.1.29 to 2.1.41 in /libs/grok (#2121) 2022-02-22 10:22:45 -08:00
nio Update Mockito to 4.2.x (#1830) 2022-01-03 12:00:45 -05:00
plugin-classloader Run spotless and exclude checkstyle on libs module (#1428) 2021-10-26 09:45:26 -05:00
secure-sm Replace exclusionary words whitelist and blacklist in the places that won't impact backwards compatibility (#2178) 2022-03-04 16:34:09 -08:00
ssl-config Run spotless and exclude checkstyle on libs module (#1428) 2021-10-26 09:45:26 -05:00
x-content Upgrading Jackson-Databind version (#1982) 2022-01-26 20:44:22 -08:00
build.gradle [License] Add SPDX and OpenSearch Modification license header (#509) 2021-04-09 14:28:18 -05:00