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

Expose DatastoreStorageFactory SPI API in a developer-friendlier way #152

Open
yuri-sergiichuk opened this issue Oct 13, 2020 · 1 comment

Comments

@yuri-sergiichuk
Copy link
Contributor

TL;DR
Improve SPI-related APIs of DatastoreStorageFactory, e.g. expose converterFactory field setter as Builder public API.

The DatastoreStorageFactory provides an SPI API that allows configuring how the InboxStorage instance is created with overring the inboxStorageWith(DatastoreWrapper wrapper, boolean multitenant) method.
But at the same time, the DatastoreStorageFactory itself can only be instantiated with an instance of the respective Builder that has a converterFactory which is essential for the factory. The problem is that this converterFactory field cannot be set via Builder public API and thus the factory cannot be properly instantiated.

The only way to instantiate the factory with a properly built builder right now without reimplementing the factory itself is to use reflection API and set the converterFactory directly, e.g. like this:

    private static synchronized void
    setConverterFactory(DatastoreStorageFactory.Builder builder, NsConverterFactory factory) {
        try {
            Field converterFactory = DatastoreStorageFactory.Builder.class
                    .getDeclaredField("converterFactory");
            boolean accessible = converterFactory.isAccessible();
            converterFactory.setAccessible(true);
            converterFactory.set(builder, factory);
            converterFactory.setAccessible(accessible);
        } catch (IllegalAccessException | IllegalArgumentException | NoSuchFieldException | SecurityException e) {
            throw newIllegalStateException(
                    e, "Cannot set `converterFactory` for `DatastoreStorageFactory.Builder`."
            );
        }
    }

The other desirable change should be a public API that allows configuring the DatastoreMode of the DsInboxStorage instances created with the DatastoreStorageFactory.

@alexander-yevsyukov
Copy link
Contributor

These changes depend on storage changes that we're going to introduce in v2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Development

No branches or pull requests

2 participants