I have a Wildfly application with an Infinispan cache containing objects that require custom serialization.
The Infinispan documentation for Marshalling and Encoding Data recommends to use the protobuf-based Protostream marshaller.
I have generated the Protostream marshaller and serialization context initializer for the custom objects as described in the corresponding documentation section.
I have also configured the cache container to use "PROTOSTREAM" marshaller via the Wildfly Infinispan subsystem configuration attribute:
<cache-container marshaller="PROTOSTREAM" ... ><!-- ... --></cache-container>
How can I configure the Wildfly Infinispan subsystem to use my custom serialization context initializer?
According to the Infispan documentation section on Registering serialization context initializers, there are two mechanisms:
java.util.ServiceLoader
serialization/context-initializer
The documentation warns that
If you manually register one
SerializationContextInitializer
implementation, it disables automatic registration. You must then manually register all other implementations.
Now, Wildfly itself already registers various serialization context initializers of its own. Consequently, automatic detection is disabled.
Is there a way to declaratively configure custom serialization context initializers via Wildfly Infinispan subsystem configuration?
(Note that the custom serialization context initializer implementation is generated by the annotation processor into the "target/" folder. Thus, I want to avoid programmatic registration because that would involve either loading that class by name or creating a separate project in order to reference that implementation class.)
Now, Wildfly itself already registers various serialization context initializers of its own. Consequently, automatic detection is disabled.
WildFly will automatically load any SerializationContextInitializer
instances (via ServiceLoader
) that are visible from the modules associated with your cache-container. This means that you need to package your key/value types along with the associated SerializationContextInitializer
instances enumerated within /META-INF/services/org.infinispan.protstream.SerializationContextInitializer
as a WildFly module and associate this module with your cache-container.
e.g.
<cache-container name="foo" marshaller="PROTOSTREAM" modules="org.wildfly.clustering.infinispan.spi com.acme.bar">
<!--...-->
</cache-container>
This will configure the "foo" cache-container with ProtoStream marshalling using both WF's default set of SerializationContextInitializer
instances and your custom marshallers packaged within the "com.acme.bar" module.
See the WF docs specifics on creating a custom module.
I realize the need to create a custom module is awkward. I am hoping to simplify the process of configuring deployment specific cache-containers in a future release.