Search in sources :

Example 11 with BundleEvent

use of org.osgi.framework.BundleEvent in project sling by apache.

the class QuartzSchedulerTest method testBundleChangedWithStartedBundle.

@Test
public void testBundleChangedWithStartedBundle() throws SchedulerException {
    String firstJob = "testName1";
    String secondJob = "testName2";
    when(bundle.getBundleId()).thenReturn(2L);
    quartzScheduler.addJob(1L, 1L, firstJob, new Thread(), new HashMap<String, Serializable>(), "0 * * * * ?", true);
    quartzScheduler.addJob(2L, 2L, secondJob, new Thread(), new HashMap<String, Serializable>(), "0 * * * * ?", true);
    BundleEvent event = new BundleEvent(BundleEvent.STARTED, bundle);
    quartzScheduler.bundleChanged(event);
    assertTrue(proxies.get("testName").getScheduler().checkExists(JobKey.jobKey(firstJob)));
    assertTrue(proxies.get("testName").getScheduler().checkExists(JobKey.jobKey(secondJob)));
}
Also used : Serializable(java.io.Serializable) BundleEvent(org.osgi.framework.BundleEvent) Test(org.junit.Test)

Example 12 with BundleEvent

use of org.osgi.framework.BundleEvent in project sling by apache.

the class BundleEventUtil method stopDummyBundle.

/**
     * Simulate a bundle STARTED event with a given set of classes simulated to be found in the bundle's classpath. 
     */
public static void stopDummyBundle(Bundle bundle) {
    ((DummyBundle) bundle).setState(Bundle.RESOLVED);
    BundleEvent event = new BundleEvent(BundleEvent.STOPPED, bundle);
    MockOsgi.sendBundleEvent(bundle.getBundleContext(), event);
}
Also used : BundleEvent(org.osgi.framework.BundleEvent)

Example 13 with BundleEvent

use of org.osgi.framework.BundleEvent in project sling by apache.

the class Activator method start.

public void start(BundleContext context) throws Exception {
    commandMap = new OsgiMailcapCommandMap();
    for (Bundle bundle : context.getBundles()) registerBundleMailcapEntries(bundle);
    CommandMap.setDefaultCommandMap(commandMap);
    bundleTracker = new BundleTracker(context, Bundle.ACTIVE | Bundle.UNINSTALLED | Bundle.STOP_TRANSIENT, new BundleTrackerCustomizer() {

        public void removedBundle(Bundle bundle, BundleEvent event, Object object) {
            unregisterBundleMailcapEntries(bundle);
        }

        public void modifiedBundle(Bundle bundle, BundleEvent event, Object object) {
            unregisterBundleMailcapEntries(bundle);
            registerBundleMailcapEntries(bundle);
        }

        public Object addingBundle(Bundle bundle, BundleEvent event) {
            registerBundleMailcapEntries(bundle);
            return bundle;
        }
    });
    bundleTracker.open();
}
Also used : Bundle(org.osgi.framework.Bundle) BundleEvent(org.osgi.framework.BundleEvent) BundleTracker(org.osgi.util.tracker.BundleTracker) BundleTrackerCustomizer(org.osgi.util.tracker.BundleTrackerCustomizer)

Example 14 with BundleEvent

use of org.osgi.framework.BundleEvent in project sling by apache.

the class ContentLoaderServiceTest method testBundleResolvedBundleChanged.

//-------ContentLoaderService#bundleChanged(BundleEvent)-------//
//I'm not very sure how to test this method, it looks like side effect of this method goes very deep
//And more affects BundleContentLoader than ContentLoaderService
@Test
public void testBundleResolvedBundleChanged() throws NoSuchFieldException, RepositoryException {
    final Bundle bundle = createNewBundle();
    final List<Bundle> delayedBundles = (List<Bundle>) PrivateAccessor.getField(contentLoader, "delayedBundles");
    final Set<String> updatedBundles = (Set<String>) PrivateAccessor.getField(underTest, "updatedBundles");
    updatedBundles.add(bundle.getSymbolicName());
    int updatedBundlesCurrentAmout = updatedBundles.size();
    underTest.bundleChanged(new BundleEvent(BundleEvent.RESOLVED, bundle));
    //Below we check that this bundle was removed from updatedBundles set
    assertEquals(updatedBundlesCurrentAmout - 1, delayedBundles.size());
    updatedBundlesCurrentAmout = updatedBundles.size();
    underTest.bundleChanged(new BundleEvent(BundleEvent.UPDATED, bundle));
    assertEquals(updatedBundlesCurrentAmout + 1, updatedBundles.size());
    //Is it ok just to call this method to check that no exception occurs?
    underTest.bundleChanged(new BundleEvent(BundleEvent.UNINSTALLED, bundle));
}
Also used : MockBundle(org.apache.sling.testing.mock.osgi.MockBundle) Bundle(org.osgi.framework.Bundle) BundleEvent(org.osgi.framework.BundleEvent) Test(org.junit.Test)

Example 15 with BundleEvent

use of org.osgi.framework.BundleEvent in project aries by apache.

the class Activator method start.

/*
     * (non-Javadoc)
     * 
     * @see
     * org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext
     * )
     */
public void start(BundleContext context) throws Exception {
    System.out.println("bundle helloIsolation start");
    SecurityManager security = System.getSecurityManager();
    if (security != null) {
        System.out.println("HelloIsolationImpl: system manager is not null");
    } else {
        System.out.println("HelloIsolationImpl: system manager is still null");
    }
    sr = context.registerService(HelloIsolation.class.getName(), new HelloIsolationImpl(), null);
    bt = new BundleTracker(context, Bundle.INSTALLED | Bundle.UNINSTALLED | Bundle.ACTIVE, new BundleTrackerCustomizer() {

        public synchronized Object addingBundle(Bundle bundle, BundleEvent event) {
            if (event == null) {
                System.out.println("HelloIsolation " + bundle.getSymbolicName() + "_" + bundle.getVersion().toString() + " - adding Bundle: " + bundle.getSymbolicName() + " event: null");
            } else {
                System.out.println("HelloIsolation  " + bundle.getSymbolicName() + "_" + bundle.getVersion().toString() + " - adding Bundle: " + bundle.getSymbolicName() + " event: " + event.getType());
            }
            addEventCount++;
            return bundle;
        }

        public synchronized void modifiedBundle(Bundle bundle, BundleEvent event, Object object) {
            if (event == null) {
                System.out.println("HelloIsolation " + bundle.getSymbolicName() + "_" + bundle.getVersion().toString() + "  - modifying Bundle: " + bundle.getSymbolicName() + " event: null");
            } else {
                System.out.println("HelloIsolation " + bundle.getSymbolicName() + "_" + bundle.getVersion().toString() + " - modifying Bundle: " + bundle.getSymbolicName() + " event: " + event.getType());
            }
            modifyEventCount++;
        }

        public synchronized void removedBundle(Bundle bundle, BundleEvent event, Object object) {
            if (event == null) {
                System.out.println("HelloIsolation " + bundle.getSymbolicName() + "_" + bundle.getVersion().toString() + " - removing Bundle: " + bundle.getSymbolicName() + " event: null");
            } else {
                System.out.println("HelloIsolation " + bundle.getSymbolicName() + "_" + bundle.getVersion().toString() + " - removing Bundle: " + bundle.getSymbolicName() + " event: " + event.getType());
            }
            removeEventCount++;
        }
    });
    bt.open();
}
Also used : Bundle(org.osgi.framework.Bundle) BundleEvent(org.osgi.framework.BundleEvent) BundleTracker(org.osgi.util.tracker.BundleTracker) BundleTrackerCustomizer(org.osgi.util.tracker.BundleTrackerCustomizer)

Aggregations

BundleEvent (org.osgi.framework.BundleEvent)53 Bundle (org.osgi.framework.Bundle)41 Test (org.junit.Test)12 SynchronousBundleListener (org.osgi.framework.SynchronousBundleListener)12 BundleListener (org.osgi.framework.BundleListener)9 FrameworkEvent (org.osgi.framework.FrameworkEvent)7 StartLevel (org.osgi.service.startlevel.StartLevel)7 BundleException (org.osgi.framework.BundleException)6 File (java.io.File)5 BundleContext (org.osgi.framework.BundleContext)5 Serializable (java.io.Serializable)3 HashMap (java.util.HashMap)3 LinkedHashMap (java.util.LinkedHashMap)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 Endpoint (javax.xml.ws.Endpoint)3 BundleTracker (org.osgi.util.tracker.BundleTracker)3 BundleTrackerCustomizer (org.osgi.util.tracker.BundleTrackerCustomizer)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2