Felix,
A test program is attached. If run without any changes, no events are
received by the framework listener.
If you comment out the first start and shutdown in the main method, one
event is received. If felix.shutdown() is not called inside
shutdownFelixRuntime, the event is received even with the new Felix
instance.
Thank you...
Regards,
Rajini
On 6/28/07, Felix Meschberger <[EMAIL PROTECTED]> wrote:
Hi Rajini,
Then it is strange, that it is not called ...
Do you have some sample code you might share for a quick code review ?
Regards
Felix
On 6/27/07, Rajini Sivaram <[EMAIL PROTECTED]> wrote:
>
> Felix,
>
> I create a new instance of Felix each time. Once shutdown is called, the
> instance of Felix and the system bundle context are not used again . A
> framework listener is created for the system bundle context every time
the
> runtime is restarted, but it doesn't get invoked at all after the first
> shutdown.
>
>
> Thank you...
>
> Regards,
>
> Rajini
>
> On 6/27/07, Felix Meschberger <[EMAIL PROTECTED]> wrote:
> >
> > Hi Rajini,
> >
> > How do you restart the framework ? Do you create the Felix instance
anew
> > for
> > each framework start or do start-stop the same instance multiple times
?
> >
> > For better replicability and also in view of the changes that Richard
is
> > currently implementing, I suggest you do not reuse the Felix instances
> but
> > instead recreate a new instance for each start-stop cycle.
> >
> > Anyway, I assume, that you have to register the framework listener
each
> > time
> > you start Felix.
> >
> > Hope this helps
> >
> > Regards
> > Felix
> >
> > On 6/27/07, Rajini Sivaram <[EMAIL PROTECTED]> wrote:
> > >
> > > Hello,
> > >
> > > I have a set of JUnit tests which startup a Felix runtime in the
setUp
> > > method and shut the runtime down using Felix.shutdown(). The tests
run
> > > fine
> > > when run one-by-one (single Felix runtime startup and shutdown in a
> VM),
> > > but
> > > when run together (as a sequence of Felix runtime startup and
shutdown
> > > from
> > > one VM), the framework listener is not called after the first
> shutdown.
> > > Apart from the framework listener, other operations dont run into
any
> > > problems with the restarting of the runtime, so I presume restarting
> the
> > > embedded runtime is not a problem.
> > >
> > > Is this something which will get fixed with the changes to the
> embedded
> > > APIs?
> > >
> > >
> > > Thank you...
> > >
> > > Regards,
> > >
> > > Rajini
> > >
> >
>
package test;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import org.apache.felix.framework.Felix;
import org.apache.felix.framework.util.MutablePropertyResolverImpl;
import org.apache.felix.main.Main;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.FrameworkEvent;
import org.osgi.framework.FrameworkListener;
import org.osgi.service.packageadmin.PackageAdmin;
public class FrameworkListenerTest implements FrameworkListener, BundleActivator {
public static int eventCount;
public BundleContext bundleContext;
public Felix felix;
public static void main(String [] args) throws Exception {
FrameworkListenerTest test = new FrameworkListenerTest();
// Comment out these two lines to get the test working.
test.startFelixRuntime();
test.shutdownFelixRuntime();
BundleContext bundleContext = test.startFelixRuntime();
PackageAdmin packageAdmin = null;
org.osgi.framework.ServiceReference packageAdminReference =
bundleContext.getServiceReference("org.osgi.service.packageadmin.PackageAdmin");
if (packageAdminReference != null) {
packageAdmin = (PackageAdmin) bundleContext.getService(packageAdminReference);
}
bundleContext.addFrameworkListener(test);
packageAdmin.refreshPackages(null);
Thread.sleep(2000);
test.shutdownFelixRuntime();
System.out.println("Test complete, number of framework events = " + eventCount);
System.exit(0);
}
public void frameworkEvent(FrameworkEvent event) {
eventCount++;
System.out.println("frameworkEvent " + event.getType());
}
public BundleContext startFelixRuntime() throws Exception {
if (bundleContext != null)
return bundleContext;
Properties props = (Properties)Main.loadConfigProperties();
File profileDir = File.createTempFile(".felix", null);
props.put("felix.cache.profiledir", profileDir.getAbsolutePath());
props.put("felix.embedded.execution", "true");
props.put("org.osgi.framework.system.packages",
"org.osgi.framework; version=1.3.0," +
"org.osgi.service.packageadmin; version=1.2.0, " +
"org.osgi.service.startlevel; version=1.0.0, " +
"org.osgi.service.url; version=1.0.0 ");
MutablePropertyResolverImpl mutableProps = new MutablePropertyResolverImpl(props);
felix = new Felix();
List<BundleActivator> activators = new ArrayList<BundleActivator>();
activators.add(this);
felix.start(mutableProps, activators);
synchronized (this) {
int retries = 0;
while (bundleContext == null && retries++ < 10) {
this.wait(1000);
}
}
return bundleContext;
}
public void shutdownFelixRuntime() {
if (felix != null) {
felix.shutdown();
bundleContext = null;
felix = null;
}
}
public void start(BundleContext context) throws Exception {
bundleContext = context;
synchronized (this) {
this.notify();
}
}
public void stop(BundleContext context) throws Exception {
bundleContext = null;
}
}