I have a question about what happens to class instances when bundle
containing the class unloads. Let's say I have:

1. bundle "org.foo.animal" containing interface Animal

public interface Animal
{
     String getName();
     int getType();
}

2. bundle "org.foo.animal.cat" containing class Cat

public class Cat implements Animal;

3. bundle "org.foo.supplier" containing interface AnimalSupplier

public interface AnimalSupplier
{
     Animal getAnimal();
}

4. and finally "org.foo.supplier.cat" containing class CatSupplier

public class CatSupplier implements AnimalSupplier
{
     public Animal getAnimal()
     {
          return new Cat();
     }
}

import/export dependencies are ok, and there is only one service -
CatSupplier published under AnimalSupplier

Some other bundle invokes getAnimal() on CatSupplier through AnimalSupplier
service and so obtains an instance of Cat under Animal interface. This our
bundle depends only on org.foo.animal and org.foo.supplier and knows nothing
about cats =) Next thing I unload cat bundles. This causes my bundle to
loose AnimalSupplier reference and that's ok. But what about my instance of
Cat class? I still have it as an object but the class itself is not there
(because the bundle containing it was unloaded). What happens if I try to
invoke methods on my Cat object through Animal interface?
_______________________________________________
OSGi Developer Mail List
[email protected]
https://mail.osgi.org/mailman/listinfo/osgi-dev

Reply via email to