A FieldBridge should be able to easily acquire services/resources

Description

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

Activity

Show:

Adrian Nistor September 18, 2013 at 8:05 PM

Many thanks guys!

Gunnar Morling September 17, 2013 at 8:06 AM
Edited

Sent pull request #483 which allows to pass class bridge instances via the config API.

Gunnar Morling September 12, 2013 at 11:14 AM

Assuming we stick to allowing FieldBridge s being passed to (a semi-public specialization of) the query DSL, this would apply to class bridges only.

Sanne Grinovero September 6, 2013 at 10:33 AM

it's not possible now, but we're discussing it now as a possible alternative solution (to be implemented)

Adrian Nistor September 6, 2013 at 10:12 AM

That was my initial instinct too, but Emmanuel said it's not possible.

Fixed

Details

Assignee

Reporter

Labels

Components

Fix versions

Priority

Created August 30, 2013 at 10:13 AM
Updated September 18, 2013 at 8:05 PM
Resolved September 18, 2013 at 6:34 PM