A FieldBridge is currently specified by Class and HSearch controls the creation of FieldBridge instances. There is no way for the user to provide the actual instance and this creates problems when the field bridge needs to acquire non-String configuration objects or other heavy resources/services.
In infinispan we have a use-case where a custom FieldBridge needs access to a protobuf marshalling metadata registry, which is basically an infinsipan Cache. We cannot inject this into the FielBridge, so we resorted to a temporary hack that involves a static field (the distasteful static singleton pattern).
Here is a conversation on #infinispan-dev with Emmanuel which sheds some light on the potential solution:
(2013-08-23 16:30:13) anistor: emmanuel: is there any way to control the instantiation of a FieldBridge? I need to pass it some non-string parameters (2013-08-23 16:30:57) emmanuel: control per se no (2013-08-23 16:31:00) emmanuel: Let me check (2013-08-23 16:31:21) anistor: emmanuel: I have a field bridge that needs to do some heavy lifting and it needs some resources injected into it (2013-08-23 16:31:57) anistor: emmanuel: and those resources are not exactly stateless (its a protobuf metadata registry) (2013-08-23 16:34:15) anistor: emmanuel: I figured programmatic config could allow a FB instance to be specified rather than a Class. but does not seem possible right now. (2013-08-23 16:35:58) emmanuel: anistor: that's correct, I browsed the code and such things are not allowed at the moment (2013-08-23 16:36:17) emmanuel: The place where field bridges are instantiated si Bridgefactory (2013-08-23 16:39:31) emmanuel: we do have the notion of service (started by HSEARCH itself or provided by the Factory creator) (2013-08-23 16:40:12) emmanuel: we could inject the service manager to the field bridge when it is initialized
|