Skip to content

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

@yuri-sergiichuk

Description

@yuri-sergiichuk

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions