BundleState extends NotificationBroadcasterSupport implements BundleStateMBean, MBeanRegistration { public String getLocation(long bundleId) throws IOException, IllegalArgumentException { Bundle bundle = resolveBundle(bundleContext, bundleId); return bundle.getLocation(); } BundleState(BundleContext bundleContext, PackageAdmin packageAdmin, StartLevel startLevel, StateConfig stateConfig, Logger logger); String[] getExportedPackages(long bundleId); long[] getFragments(long bundleId); TabularData getHeaders(long bundleId); TabularData getHeaders(long bundleId, String locale); String getHeader(long bundleId, String key); String getHeader(long bundleId, String key, String locale); long[] getHosts(long fragmentId); String[] getImportedPackages(long bundleId); long getLastModified(long bundleId); String getLocation(long bundleId); long[] getRegisteredServices(long bundleId); long[] getRequiredBundles(long bundleIdentifier); long[] getRequiringBundles(long bundleIdentifier); long[] getServicesInUse(long bundleIdentifier); int getStartLevel(long bundleId); String getState(long bundleId); String getSymbolicName(long bundleId); String getVersion(long bundleId); boolean isFragment(long bundleId); boolean isActivationPolicyUsed(long bundleId); boolean isPersistentlyStarted(long bundleId); boolean isRemovalPending(long bundleId); boolean isRequired(long bundleId); CompositeData getBundle(long id); long[] getBundleIds(); TabularData listBundles(); TabularData listBundles(String ... items); MBeanNotificationInfo[] getNotificationInfo(); void postDeregister(); void postRegister(Boolean registrationDone); void preDeregister(); ObjectName preRegister(MBeanServer server, ObjectName name); static String BUNDLE_EVENT; }
@Test public void testNotificationsForBundleEvents() throws Exception { StateConfig stateConfig = new StateConfig(); List<Notification> received = new LinkedList<Notification>(); List<AttributeChangeNotification> attributeChanges = new LinkedList<AttributeChangeNotification>(); createBundle(stateConfig, received, attributeChanges); assertEquals(2, received.size()); Notification installed = received.get(0); assertEquals(1, installed.getSequenceNumber()); CompositeData installedCompositeData = (CompositeData) installed.getUserData(); BundleEventData installedData = BundleEventData.from(installedCompositeData); assertEquals("bundle", installedData.getBundleSymbolicName()); assertEquals(9, installedData.getBundleId()); assertEquals("file:/location", installedData.getLocation()); assertEquals(BundleEvent.INSTALLED, installedData.getEventType()); Notification resolved = received.get(1); assertEquals(2, resolved.getSequenceNumber()); CompositeData resolvedCompositeData = (CompositeData) resolved.getUserData(); BundleEventData resolvedData = BundleEventData.from(resolvedCompositeData); assertEquals("bundle", resolvedData.getBundleSymbolicName()); assertEquals(9, resolvedData.getBundleId()); assertEquals("file:/location", resolvedData.getLocation()); assertEquals(BundleEvent.RESOLVED, resolvedData.getEventType()); assertEquals(1, attributeChanges.size()); AttributeChangeNotification ac = attributeChanges.get(0); assertEquals("BundleIds", ac.getAttributeName()); assertEquals(0, ((long [])ac.getOldValue()).length); assertEquals(1, ((long [])ac.getNewValue()).length); assertEquals(9L, ((long [])ac.getNewValue())[0]); }