[infinispan-dev] Distributed Executors in write mode, need reference to Cache

Pete Muir pmuir at redhat.com
Fri Dec 23 10:18:50 EST 2011


On 21 Dec 2011, at 15:30, Vladimir Blagojevic wrote:

> Pete, a bit more guidance please :-) I read 
> http://docs.jboss.org/weld/reference/latest/en-US/html/extend.html and I 
> looked at the infinispan-cdi code and how InfinispanExtension class 
> wires into CDI container. I understand that part, well, sort of! I've 
> seen how a class whose instances are supposed to be injected 
> (DefaultCacheManager, AdvancedCache) is "prepared" for CDI in our 
> infinispan-cdi module.

Take a look at http://seamframework.org/Documentation/HowDoIDoNoncontextualInjectionForAThirdpartyFramework.

However, as I guess you don't want CDI directly in the map/reduce stuff, I'm suggesting you create an SPI so that injection frameworks can be plugged in.

> 
>> 
>> Here is the SPI that CDI has for this purpose:
>> 
>> http://docs.oracle.com/javaee/6/api/javax/enterprise/inject/spi/InjectionTarget.html
>> 
>> I would suggest modelling after it, as it's proved successful, and will make CDI integration easy. (BTW I don't mean use it directly, I mean copy and paste it into infinispan code).
> I do not understand this part. What do you mean by "copy and paste this 
> into Infinispan code"? Making sure we are on the same page: instances of 
> Mapper (or Reducer) do not need to be injected somewhere; they are 
> provided by the user and used in conjunction with MapReduceTask. 

Yep.

> Implementations of Mapper/Reducer interface need to have its field 
> injected, once they are deseralized to remote Infinispan nodes, injected 
> with appropriate Cache instance for example.

Yep. This is what CDI calls an "injection target" (an object which is the target for injection). So, what i would suggest you do is add an SPI to the map/reduce code that has callbacks which can be hooked into at the appropriate point by CDI or something else. So you would want a callback for inject(), postConstruct() and preDestroy(). You would provide a default impl for plain old java, which were basically no-ops, and then use e.g. the service loader to load other implementations, and call back to them. You then call this SPI at the relevant points in your code.

Does that make any more sense?


More information about the infinispan-dev mailing list