Issue Details (XML | Word | Printable)

Key: OSGI-167
Type: Improvement Improvement
Status: Resolved Resolved
Resolution: Fixed
Priority: Critical Critical
Assignee: Andy Piper
Reporter: Andy Piper
Votes: 0
Watchers: 4
Operations

If you were logged in you would be able to see more operations.
Spring OSGi

Need to support circular FactoryBean references for Spring-OSGi

Created: 22/Jun/07 06:29 AM   Updated: 19/Dec/07 10:41 AM
Component/s: CORE
Affects Version/s: 1.0 M2
Fix Version/s: 1.0 RC2

Time Tracking:
Not Specified

Issue Links:
Related
 


 Description  « Hide
Spring-OSGi allows you to add listeners for OSGI services. Unfortunately because the services are exposed through OsgiServiceProxyFactoryBeans, you are prevented on being a listener yourself because this leads to a circular reference.
We need some kind of secret handshake in order to be able to work around this.

Typical usage:

<bean id="foo" class="Bar">
  <property name="myservice">
      <osgi:reference interface="MyService">
          <osgi:listener ref="Bar"/>
      </osgi:reference>
  </property>
</bean>

 All   Comments   Work Log   Change History   FishEye   Builds      Sort Order: Ascending order - Click to sort in descending order
Juergen Hoeller added a comment - 18/Jul/07 07:43 AM
After an analysis together with Costin, we've concluded that the Spring core container already does everything it can for resolving circular references which involve FactoryBeans (since Spring 2.0.2 already, actually!). So FactoryBean circles *do work already*; they just just require some conditions to be met.

So what needs to be done here is the following: OsgiServiceProxyFactoryBean needs to be able to expose its object early, i.e. even when "getObject()" gets called before the FactoryBean is fully initialized. If it can do that, it will be able to participate in circles. This will work out of the box with Spring 2.0.2 or higher; it is up to OsgiServiceProxyFactoryBean's implementation whether to support that or not.

Spring itself uses that early exposure mechanism for its ListFactoryBean, SetFactoryBean etc already, allowing such collections to be part of a circle. The actual logic for early exposure sits in AbstractFactoryBean, where the FactoryBean exposes a proxy for a given interface in such a case. Any call on that proxy will be delegated to the target object (that the FactoryBean usually builds), with the actual target object obtained on demand (i.e. only when a method call comes in). The actual interface to expose can be determined by the concrete FactoryBean class.

As a consequence, I'm going to move this issue to the Spring OSGi project.

Juergen

Costin Leau added a comment - 30/Sep/07 09:56 AM
To conclude, this is supported if the FactoryBean supports setting a reference to it.
In our case, the osgi:reference returns a collection that cannot be initialized unless all its listeners are specified which cannot be created unless it has the collection it needs injected into it.
While we can create the proxy eagerly to allow this there might be some race conditions of services added to the collection that do not get passed on to the listener.
I'll take a look at the problem and see whether I can improve the behavior.

Andy Piper added a comment - 06/Dec/07 06:11 AM
With Juergen's help I have fixed this.