3 Replies Latest reply: Sep 28, 2011 3:07 AM by Galder Zamarreño RSS

How to re-autowire/inject transient fields from Spring/IoC during deserialization?

John Shields Newbie

Hi,

 

We are using Infinispan v4.2.1 as the low-level distributed cache for our Jetty HTTP sessions. We've developed an implementation of the Jetty

AbstractSessionManager for this purpose. This part is working correctly (and well I might add!).

 

The issue we have is that some of the objects in our session reference objects that are obtained via the Spring Autowire mechanism. Obviously these objects do not "work" when deserialized on a different server.

 

I've tried creating a custom implementation of StreamingMarshaller to handle autowiring during unmarshalling but unfortunately the object that comes through that class is (apparently) a SingleRcpCommand object and so our application level objects are not readily available to this marshaller.

 

Is there a better way to handle hooking into the deserialization process to handle autowiring/injecting depedencies? I also feel like this might be a common use case that maybe already has an existing implementation... Does anyone know if that's the case?

 

Assuming there are not any good solutions for v4.2.1, I'm now turning to the v5.0 Externalizer mechanism. This looks promising but I'm curious if there are any "gotchas" to be aware of before I starting designing/implementing.

 

My initial design idea follow this flow:

 

  1. In our AbstractSessionManager method that retrieves an HTTP session from the Infinispan cache, set the ApplicationContext in a ThreadLocal so that it can be obtained by the Externalizers.
  2. In the Externalizer implementations obtain the application context and autowire the dependencies.
  3. Back in the session mananger, remove the thread local application context once the session has been deserialized.

 

Should that work?

 

Thanks for the help!

 

Regards,

John