Examples of BundleEvent


Examples of org.osgi.framework.BundleEvent

            EasyMock.expect(b1.findEntries("OSGI-INF/remote-service", "*.xml", false)).
                    andReturn(rsBEnum).anyTimes();
            EasyMock.replay(b1);
   
            // Call back on the LDS just like what would have happened with the BundleListener
            BundleEvent be = new BundleEvent(BundleEvent.STARTED, b1);
            lds.bundleChanged(be);
           
            Map<String, Object> sed3Props = new HashMap<String, Object>();
            sed3Props.put("blah", "3");
            sed3Props.put("boo", "hello");
            ServiceEndpointDescription sed3 = new ServiceEndpointDescriptionImpl(
                    Arrays.asList("org.example.SomeRelatedService", "org.example.SomeService"), sed3Props);
            assertEquals(3, lds.servicesInfo.size());
            assertTrue(lds.servicesInfo.containsKey(sed1));
            assertTrue(lds.servicesInfo.containsKey(sed2));
            assertTrue(lds.servicesInfo.containsKey(sed3));
           
            assertEquals("We should have been notified of the new bundle",
                    2, dst.notifications.size());
            assertEquals(DiscoveredServiceNotification.AVAILABLE,
                    dst.notifications.get(1).getType());
            assertEquals(sed3, dst.notifications.get(1).getServiceEndpointDescription());
            verifyNotification(dsn, 1, 0, "(blah <= 5)");
           
            ArrayList<DiscoveredServiceNotification> copiedNotifications =
                    new ArrayList<DiscoveredServiceNotification>(dst.notifications);
           
            // add an unrelated bundle - no notification...
            Bundle b2 = EasyMock.createNiceMock(Bundle.class);
            EasyMock.expect(b2.getState()).andReturn(Bundle.ACTIVE).anyTimes();
            EasyMock.expect(b2.findEntries("OSGI-INF/remote-service", "*.xml", false)).
                    andReturn(rsCEnum).anyTimes();
            EasyMock.replay(b2);
           
            BundleEvent be2 = new BundleEvent(BundleEvent.STARTED, b1);
            lds.bundleChanged(be2);
            assertEquals("There should not have been any extra notification",
                    copiedNotifications, dst.notifications);
        } finally {
            LocalDiscoveryUtils.addEndpointID = true;
View Full Code Here

Examples of org.osgi.framework.BundleEvent

        CompositeBundle  cb = composite("test.composite", "1.0.0");
        assertNoTrackers();
       
        // full lifecycle
       
        sut.addingBundle(cb, new BundleEvent(BundleEvent.INSTALLED, cb));
        assertTracker(cb);

        sut.modifiedBundle(cb, new BundleEvent(BundleEvent.RESOLVED, cb), cb);
        sut.modifiedBundle(cb, new BundleEvent(BundleEvent.STARTING, cb), cb);
        sut.modifiedBundle(cb, new BundleEvent(BundleEvent.STARTED, cb), cb);
        sut.modifiedBundle(cb, new BundleEvent(BundleEvent.STOPPING, cb), cb);
        sut.removedBundle(cb, new BundleEvent(BundleEvent.STOPPED, cb), cb);
        assertNoTrackers();
       
        // short lifecycle
       
        sut.addingBundle(cb, new BundleEvent(BundleEvent.INSTALLED, cb));
        assertTracker(cb);
       
        sut.modifiedBundle(cb, new BundleEvent(BundleEvent.RESOLVED, cb), cb);       
        sut.removedBundle(cb, new BundleEvent(BundleEvent.UNRESOLVED, cb), cb);
        assertNoTrackers();
       
        // shortest lifecycle
       
        sut.addingBundle(cb, new BundleEvent(BundleEvent.INSTALLED, cb));
        assertTracker(cb);
       
        sut.removedBundle(cb, new BundleEvent(BundleEvent.UNINSTALLED, cb), cb);
        assertNoTrackers();
    }
View Full Code Here

Examples of org.osgi.framework.BundleEvent

   
    //INSTALL the bundle
   
    Skeleton.getSkeleton(persistenceBundle).setReturnValue(new MethodCall(Bundle.class, "getState"), Bundle.INSTALLED);
   
    Object o = mgr.addingBundle(persistenceBundle, new BundleEvent(BundleEvent.INSTALLED, persistenceBundle));

    //Check the persistence.xml was looked for
    Skeleton.getSkeleton(persistenceBundle).assertCalled(new MethodCall(Bundle.class, "getEntry", "META-INF/persistence.xml"));
    //Check we didn't use getResource()
    Skeleton.getSkeleton(persistenceBundle).assertNotCalled(new MethodCall(Bundle.class, "getResource", String.class));
   
    //Check we didn't get the Provider, register a service or create an EMF
    Skeleton.getSkeleton(extenderContext).assertNotCalled(new MethodCall(BundleContext.class, "getService", ServiceReference.class));
    Skeleton.getSkeleton(persistenceBundleContext).assertNotCalled(new MethodCall(BundleContext.class, "registerService", EntityManagerFactory.class.getName(), EntityManagerFactory.class, Dictionary.class));
    Skeleton.getSkeleton(pp).assertNotCalled(new MethodCall(PersistenceProvider.class, "createContainerEntityManagerFactory", PersistenceUnitInfo.class, Map.class));
    BundleContextMock.assertNoServiceExists(EntityManagerFactory.class.getName());
   
   
    //Now try Resolving
    Skeleton.getSkeleton(persistenceBundle).setReturnValue(new MethodCall(Bundle.class, "getState"), Bundle.RESOLVED);
    mgr.modifiedBundle(persistenceBundle, new BundleEvent(BundleEvent.RESOLVED, persistenceBundle), o);
   
    testSuccessfulCreationEvent(ref, extenderContext, 1);
    BundleContextMock.assertNoServiceExists(EntityManagerFactory.class.getName());
   
   
    //Now try starting (This should not create again, so check we only called 1 time)
    Skeleton.getSkeleton(persistenceBundle).setReturnValue(new MethodCall(Bundle.class, "getState"), Bundle.STARTING);
    mgr.modifiedBundle(persistenceBundle, new BundleEvent(BundleEvent.STARTING, persistenceBundle), o);
   
    testSuccessfulCreationEvent(ref, extenderContext, 1);
    testSuccessfulRegistrationEvent(ref, extenderContext, 1);
   
    //Now try active (This should not create again, so check we only called 1 time)
    Skeleton.getSkeleton(persistenceBundle).setReturnValue(new MethodCall(Bundle.class, "getState"), Bundle.ACTIVE);
    mgr.modifiedBundle(persistenceBundle, new BundleEvent(BundleEvent.STARTED, persistenceBundle), o);
   
    testSuccessfulCreationEvent(ref, extenderContext, 1);
    testSuccessfulRegistrationEvent(ref, extenderContext, 1);
   
    //Now stop the bundle, check no extra calls, and the EMFs are still open
    Skeleton.getSkeleton(persistenceBundle).setReturnValue(new MethodCall(Bundle.class, "getState"), Bundle.STOPPING);
    mgr.modifiedBundle(persistenceBundle, new BundleEvent(BundleEvent.STOPPING, persistenceBundle), o);
   
    testSuccessfulCreationEvent(ref, extenderContext, 1);
    BundleContextMock.assertNoServiceExists(EntityManagerFactory.class.getName());
    Skeleton.getSkeleton(pp).assertNotCalled(new MethodCall(EntityManagerFactory.class, "close"));
   
    //Now Mark the bundle stopped, check no extra calls, and the EMFs are still open
    Skeleton.getSkeleton(persistenceBundle).setReturnValue(new MethodCall(Bundle.class, "getState"), Bundle.RESOLVED);
    mgr.modifiedBundle(persistenceBundle, new BundleEvent(BundleEvent.STOPPING, persistenceBundle), o);
   
    testSuccessfulCreationEvent(ref, extenderContext, 1);
    BundleContextMock.assertNoServiceExists(EntityManagerFactory.class.getName());
    Skeleton.getSkeleton(pp).assertNotCalled(new MethodCall(EntityManagerFactory.class, "close"));
   
    //Now Uninstall, check no extra calls, and the EMFs are closed
    Skeleton.getSkeleton(persistenceBundle).setReturnValue(new MethodCall(Bundle.class, "getState"), Bundle.UNINSTALLED);
    mgr.removedBundle(persistenceBundle, new BundleEvent(BundleEvent.UNINSTALLED, persistenceBundle), o);
   
    testSuccessfulCreationEvent(ref, extenderContext, 1);
    BundleContextMock.assertNoServiceExists(EntityManagerFactory.class.getName());
    Skeleton.getSkeleton(pp).assertCalled(new MethodCall(EntityManagerFactory.class, "close"));
  }
View Full Code Here

Examples of org.osgi.framework.BundleEvent

    Skeleton.getSkeleton(extenderContext).clearMethodCalls();
   
    System.out.println(getTrackedObject());
    //Update the bundle
    Skeleton.getSkeleton(persistenceBundle).setReturnValue(new MethodCall(Bundle.class, "getState"), Bundle.INSTALLED);
    mgr.modifiedBundle(persistenceBundle, new BundleEvent(BundleEvent.UPDATED, persistenceBundle), getTrackedObject());
   
    //Check the persistence.xml was looked for
    Skeleton.getSkeleton(persistenceBundle).assertCalled(new MethodCall(Bundle.class, "getEntry", "META-INF/persistence.xml"));
    //Check we didn't use getResource()
    Skeleton.getSkeleton(persistenceBundle).assertNotCalled(new MethodCall(Bundle.class, "getResource", String.class));
   
    //Check we didn't get the Provider, and there is no Service in the registry
    Skeleton.getSkeleton(extenderContext).assertNotCalled(new MethodCall(BundleContext.class, "getService", ServiceReference.class));
    Skeleton.getSkeleton(pp).assertCalled(new MethodCall(EntityManagerFactory.class, "close"));
    BundleContextMock.assertNoServiceExists(EntityManagerFactory.class.getName());
   
    //Now resolve the bundle again and check we get another EMF created
    Skeleton.getSkeleton(persistenceBundle).setReturnValue(new MethodCall(Bundle.class, "getState"), Bundle.RESOLVED);
    mgr.modifiedBundle(persistenceBundle, new BundleEvent(BundleEvent.RESOLVED, persistenceBundle), getTrackedObject());
   
    //We will have created the EMF a total of 2 times
    testSuccessfulCreationEvent(ref, extenderContext, 2);
    BundleContextMock.assertNoServiceExists(EntityManagerFactory.class.getName());
  }
View Full Code Here

Examples of org.osgi.framework.BundleEvent

   
    Skeleton.getSkeleton(extenderContext).clearMethodCalls();
    Skeleton.getSkeleton(persistenceBundle).clearMethodCalls();
   
    Skeleton.getSkeleton(persistenceBundle).setReturnValue(new MethodCall(Bundle.class, "getState"), Bundle.INSTALLED);
    mgr.modifiedBundle(persistenceBundle, new BundleEvent(BundleEvent.UNRESOLVED, persistenceBundle), getTrackedObject());
   
    //Check we don't re-parse the xml
    Skeleton.getSkeleton(persistenceBundle).assertNotCalled(new MethodCall(Bundle.class, "getEntry", "META-INF/persistence.xml"));
    //Check we didn't use getResource()
    Skeleton.getSkeleton(persistenceBundle).assertNotCalled(new MethodCall(Bundle.class, "getResource", String.class));
View Full Code Here

Examples of org.osgi.framework.BundleEvent

        {
            m_state = Bundle.STARTING;

            m_context = new PojoSRBundleContext(this, m_reg, m_dispatcher,
                    m_bundles, m_config);
            m_dispatcher.fireBundleEvent(new BundleEvent(BundleEvent.STARTING,
                    this));
            if (m_activatorClass != null)
            {
                m_activator = (BundleActivator) m_loader.loadClass(
                        m_activatorClass).newInstance();
                m_activator.start(m_context);
            }
            m_state = Bundle.ACTIVE;
            m_dispatcher.fireBundleEvent(new BundleEvent(BundleEvent.STARTED,
                    this));
        }
        catch (Throwable ex)
        {
            m_state = Bundle.RESOLVED;
            m_activator = null;
            m_dispatcher.fireBundleEvent(new BundleEvent(BundleEvent.STOPPED,
                    this));
            throw new BundleException("Unable to start bundle", ex);
        }
    }
View Full Code Here

Examples of org.osgi.framework.BundleEvent

            throw new BundleException("Bundle is in wrong state for stop");
        }
        try
        {
            m_state = Bundle.STOPPING;
            m_dispatcher.fireBundleEvent(new BundleEvent(BundleEvent.STOPPING,
                    this));
            if (m_activator != null)
            {
                m_activator.stop(m_context);
            }
        }
        catch (Throwable ex)
        {
            throw new BundleException("Error while stopping bundle", ex);
        }
        finally
        {
            m_reg.unregisterServices(this);
            m_dispatcher.removeListeners(m_context);
            m_activator = null;
            m_context = null;
            m_state = Bundle.RESOLVED;
            m_dispatcher.fireBundleEvent(new BundleEvent(BundleEvent.STOPPED,
                    this));
        }
    }
View Full Code Here

Examples of org.osgi.framework.BundleEvent

              return;
            }
            m_dispatcher.startDispatching();
            m_state = Bundle.STARTING;

                m_dispatcher.fireBundleEvent(new BundleEvent(BundleEvent.STARTING,
                        this));
                m_context = new PojoSRBundleContext(this, m_reg, m_dispatcher,
                                m_bundles, bundleConfig);
                int i = 0;
                for (Bundle b : m_bundles.values()) {
                  i++;
                  try
                    {
                        if (b != this)
                        {
                            b.start();
                        }
                    }
                    catch (Throwable t)
                    {
                      System.out.println("Unable to start bundle: " + i );
                      t.printStackTrace();
                    }
                }
                m_state = Bundle.ACTIVE;
                m_dispatcher.fireBundleEvent(new BundleEvent(BundleEvent.STARTED,
                        this));

                m_dispatcher.fireFrameworkEvent(new FrameworkEvent(FrameworkEvent.STARTED, this, null));
            super.start();
          };
            @Override
            public synchronized void stop() throws BundleException
            {
              if ((m_state == Bundle.STOPPING) || m_state == Bundle.RESOLVED) {
                return;

              }
              else if (m_state != Bundle.ACTIVE) {
                throw new BundleException("Can't stop pojosr because it is not ACTIVE");
              }
              final Bundle systemBundle = this;
              Runnable r = new Runnable() {

          public void run() {
                    m_dispatcher.fireBundleEvent(new BundleEvent(BundleEvent.STOPPING,
                        systemBundle));
                    for (Bundle b : m_bundles.values())
                    {
                        try
                        {
                            if (b != systemBundle)
                            {
                                b.stop();
                            }
                        }
                        catch (Throwable t)
                        {
                            t.printStackTrace();
                        }
                    }
                    m_dispatcher.fireBundleEvent(new BundleEvent(BundleEvent.STOPPED,
                        systemBundle));
                    m_state = Bundle.RESOLVED;
                    m_dispatcher.stopDispatching();
          }
        };
View Full Code Here

Examples of org.osgi.framework.BundleEvent

     * @param type The type of bundle event to fire.
     * @param bundle The bundle associated with the event.
    **/
    void fireBundleEvent(int type, Bundle bundle)
    {
        m_dispatcher.fireBundleEvent(new BundleEvent(type, bundle), this);
    }
View Full Code Here

Examples of org.osgi.framework.BundleEvent

        m_dispatcher.fireBundleEvent(new BundleEvent(type, bundle), this);
    }

    void fireBundleEvent(int type, Bundle bundle, Bundle origin)
    {
        m_dispatcher.fireBundleEvent(new BundleEvent(type, bundle, origin), this);
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.