Package org.osgi.framework

Examples of org.osgi.framework.BundleEvent


    public void init() throws Exception {
        bundleContext.addBundleListener(this);
        for (Bundle bundle : bundleContext.getBundles()) {
            if (bundle.getState() == Bundle.RESOLVED || bundle.getState() == Bundle.STARTING
                    || bundle.getState() == Bundle.ACTIVE)
            bundleChanged(new BundleEvent(BundleEvent.RESOLVED, bundle));
        }
    }
View Full Code Here


  }

  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

   
    //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

    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

   
    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

    skel.setReturnValue(new MethodCall(Bundle.class, "getVersion"), new Version("0.0.0"));
   

    mgr.start(ctx);
   
    mgr.addingBundle(persistenceBundle2, new BundleEvent(BundleEvent.STARTING, persistenceBundle2));
   
    ServiceReference[] alphas = ctx.getServiceReferences(
        EntityManagerFactory.class.getName(), "(osgi.unit.name=alpha)");
   
    EntityManager alpha1 = ((EntityManagerFactory) ctx.getService(alphas[0])).createEntityManager();
View Full Code Here

       
        Bundle b = EasyMock.createMock(Bundle.class);
        EasyMock.replay(b);
       
        assertEquals("Precondition failed", 0, called.size());
        bundleListener[0].bundleChanged(new BundleEvent(BundleEvent.INSTALLED, b));
        assertEquals(0, called.size());
       
        bundleListener[0].bundleChanged(new BundleEvent(BundleEvent.STARTED, b));
        assertEquals(Arrays.asList("addDecorations"), called);
       
        bundleListener[0].bundleChanged(new BundleEvent(BundleEvent.STOPPING, b));
        assertEquals(Arrays.asList("addDecorations", "removeDecorations"), called);
    }
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());
       
        List<String> intf3 = Arrays.asList("org.example.SomeRelatedService", "org.example.SomeService");
        Map<String, Object> sed3Props = new HashMap<String, Object>();
        sed3Props.put(ServicePublication.SERVICE_INTERFACE_NAME, intf3);
        setEndpointID(eids2, sed3Props, "org.example.SomeRelatedService", "org.example.SomeService");      
        ServiceEndpointDescription sed3 = new ServiceEndpointDescriptionImpl(intf3, 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

            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);
           
            List<String> intf3 = Arrays.asList("org.example.SomeRelatedService", "org.example.SomeService");
            Map<String, Object> sed3Props = new HashMap<String, Object>();
            sed3Props.put("blah", "3");
            sed3Props.put("boo", "hello");
            sed3Props.put(ServicePublication.SERVICE_INTERFACE_NAME, intf3);
            ServiceEndpointDescription sed3 = new ServiceEndpointDescriptionImpl(intf3, 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

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.