sevo
sevo

Reputation: 4609

How does OSGi approach shared objects between bundles?

Suppose there are two exported versions of an object, where both have property x but new one introduces a new property y.

How can I create bundle that can accept both versions of an object? Let's assume it will not clone objects, compare them, put into collections etc. Its interaction with object could be as simple as testing whether x != null.

Can serialization be avoided?

Upvotes: 1

Views: 269

Answers (2)

Marcel Offermans
Marcel Offermans

Reputation: 3323

Christian is correct. To add to that, this is exactly why you should not share your objects directly, but share interfaces. Whilst that still won't make both versions of the interface available to a consumer, at least it will then try to do the right thing and choose the interface that both x and y are compatible with. In such cases, it would have to pick the lowest common denominator.

Upvotes: 1

Christian Schneider
Christian Schneider

Reputation: 19626

Osgi classloading rules are only active at classloading time. If your bundle for example publishs a service that takes an Object as parameter you can give it any instance. Even ones that come from package it does not import.

Upvotes: 1

Related Questions