Package org.osgi.framework

Examples of org.osgi.framework.BundleEvent


  }

  public void dumpAll() {
    for (int i = 0; i < eventList.size(); i++) {
      BundleEvent fe = (BundleEvent) eventList.get(i);
      dump(fe);
    }
  }
View Full Code Here


    }
  }

  boolean exists(String bundleName) {
    for (int i = 0; i < eventList.size(); i++) {
      BundleEvent fe = (BundleEvent) eventList.get(i);
      Bundle b = fe.getBundle();
      System.out.println("===["+b+"]");
      if (bundleName.equals(b.getSymbolicName())) {
        return true;
      }
    }
View Full Code Here

      Bundle[] bl = Activator.getBundles();

      // do something reasonable with bundles already installed
      for(int i = 0; bl != null && i < bl.length; i++) {
        BundleEvent ev = null;
        switch(bl[i].getState()) {
        case Bundle.ACTIVE:
          ev = new BundleEvent(BundleEvent.STARTED, bl[i]);
          break;
        default:
          ev = new BundleEvent(BundleEvent.INSTALLED, bl[i]);
          break;
        }
        bundleChanged(ev);
        if(delay > 0) {
          Thread.sleep(delay);
View Full Code Here

      });
    */

    Bundle[] bl = Activator.getTargetBC_getBundles();
    for(int i = 0; bl != null && i < bl.length; i++) {
      bundleChanged(new BundleEvent(BundleEvent.INSTALLED, bl[i]));
    }
    Activator.getTargetBC().addBundleListener(this);

    try {
      ServiceReference [] srl = Activator.getTargetBC_getServiceReferences();
View Full Code Here

    }

    @Test
    public void testBundleListener() throws Exception {
        BundleListener bundleListener = mock(BundleListener.class);
        BundleEvent bundleEvent = mock(BundleEvent.class);

        bundleContext.addBundleListener(bundleListener);

        MockOsgi.sendBundleEvent(bundleContext, bundleEvent);
        verify(bundleListener).bundleChanged(bundleEvent);
View Full Code Here

     * register all classes with @Model annotation.
     * @param packageName Java package name
     */
    public void addModelsForPackage(String packageName) {
        Bundle bundle = new ModelsPackageBundle(packageName, Bundle.ACTIVE);
        BundleEvent event = new BundleEvent(BundleEvent.STARTED, bundle);
        MockOsgi.sendBundleEvent(this.bundleContext, event);
    }
View Full Code Here

            atLeast(1).of(bundle).loadClass(SCRIPT_ENGINE_FACTORY.getName());
            will(returnValue(SCRIPT_ENGINE_FACTORY));
        }});

        factory.bundleChanged(new BundleEvent(BundleEvent.STARTED, bundle));

        ScriptEngineManager second = factory.getScriptEngineManager();

        assertNotNull(second.getEngineByName("dummy"));
    }
View Full Code Here

     * @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

        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

        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<Collection<String>, String> eids2 = getEndpointIDs(lds.servicesInfo.keySet());
       
        Map<String, Object> sed3Props = new HashMap<String, Object>();
        setEndpointID(eids2, sed3Props, "org.example.SomeRelatedService", "org.example.SomeService");      
        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(dst.notifications.get(1), 0, 1, "org.example.SomeService");

        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);
       
        // Send an irrelevant bundle event
        BundleEvent be3 = new BundleEvent(BundleEvent.LAZY_ACTIVATION, b0);       
        lds.bundleChanged(be3);
        assertEquals("There should not have been any changes to the registered serviceInfos",
                3, lds.servicesInfo.size());
        assertEquals("There should not have been any extra notification",
                copiedNotifications, dst.notifications);
              
        // remove bundle b0
        BundleEvent be4 = new BundleEvent(BundleEvent.STOPPING, b0);       
        lds.bundleChanged(be4);
       
        assertEquals(1, lds.servicesInfo.size());
        assertEquals(sed3, lds.servicesInfo.keySet().iterator().next());
       
View Full Code Here

TOP

Related Classes of org.osgi.framework.BundleEvent

Copyright © 2018 www.massapicom. 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.