Java Code Examples for org.osgi.framework.ServiceReference#getUsingBundles()
The following examples show how to use
org.osgi.framework.ServiceReference#getUsingBundles() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ServicePojo.java From concierge with Eclipse Public License 1.0 | 6 votes |
public ServicePojo(final ServiceReference<?> sref) { id = ((Long) sref.getProperty(Constants.SERVICE_ID)).longValue(); final Map<String, Object> props = new HashMap<String, Object>(); for (final String key : sref.getPropertyKeys()) { props.put(key, sref.getProperty(key)); } setProperties(props); setBundle(getBundleUri(sref.getBundle())); final List<String> usingBundlesList = new ArrayList<String>(); if (sref.getUsingBundles() != null) { for (final Bundle using : sref.getUsingBundles()) { usingBundlesList.add(getBundleUri(using)); } } setUsingBundles(usingBundlesList.toArray(new String[usingBundlesList.size()])); }
Example 2
Source File: AbstractBundle.java From concierge with Eclipse Public License 1.0 | 6 votes |
protected final ServiceReferenceDTO getServiceReferenceDTO(ServiceReference ref){ ServiceReferenceDTO dto = new ServiceReferenceDTO(); dto.bundle = bundleId; dto.id = (Long) ref.getProperty(Constants.SERVICE_ID); dto.properties = new HashMap<String, Object>(); for(String key : ref.getPropertyKeys()){ Object val = ref.getProperty(key); dto.properties.put(key, getDTOValue(val)); } Bundle[] usingBundles = ref.getUsingBundles(); if(usingBundles == null){ dto.usingBundles = new long[0]; } else { dto.usingBundles = new long[usingBundles.length]; for(int j=0;j<usingBundles.length;j++){ dto.usingBundles[j] = usingBundles[j].getBundleId(); } } return dto; }
Example 3
Source File: Activator.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 6 votes |
private boolean isUsed(ServiceReference<?> sr) { final Bundle[] ba = sr.getUsingBundles(); if (ba != null) { for (final Bundle b : ba) { try { for (int j = 0; j < drivers.size(); j++) { final DriverRef dr = drivers.elementAt(j); if (dr.sr.getBundle() == b) { return true; } } } catch (final Exception e) { return true; } } } return false; }
Example 4
Source File: Util.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 6 votes |
public static String getServiceInfo(ServiceReference<?> sr) { final StringBuffer sb = new StringBuffer(); sb.append(sr.getProperty("service.id") + ": " + getClassNames(sr)); sb.append("\n"); sb.append("from #" + sr.getBundle().getBundleId()); sb.append(" " + Util.getBundleName(sr.getBundle())); final Bundle[] bl = sr.getUsingBundles(); if (bl != null) { sb.append("\nto "); for (int i = 0; i < bl.length; i++) { sb.append("#" + bl[i].getBundleId()); sb.append(" " + Util.getBundleName(bl[i])); if (i < bl.length - 1) { sb.append("\n"); } } } return sb.toString(); }
Example 5
Source File: ServiceComponentRuntimeImpl.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 6 votes |
private ServiceReferenceDTO getServiceReferenceDTO(ServiceReference<?> sr) { ServiceReferenceDTO res = new ServiceReferenceDTO(); res.properties = new HashMap<String, Object>(); for (String key : sr.getPropertyKeys()) { Object val = safeDTOObject(sr.getProperty(key)); res.properties.put(key, val); } res.id = ((Long)sr.getProperty(Constants.SERVICE_ID)).longValue(); Bundle [] using = sr.getUsingBundles(); if (using != null) { res.usingBundles = new long [using.length]; for (int i = 0; i < using.length; i++) { res.usingBundles[i] = using[i].getBundleId(); } } else { res.usingBundles = new long [0]; } Bundle b = sr.getBundle(); if (b == null) { return null; } res.bundle = b.getBundleId(); return res; }
Example 6
Source File: ServiceListenerTestSuite.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 5 votes |
private void printUsingBundles(ServiceReference sr, String caption) { Bundle[] usingBundles = sr.getUsingBundles(); out.print(caption!=null ? caption : "Using bundles: "); for (int i=0; usingBundles!=null && i<usingBundles.length; i++) { if (i>0) out.print(", "); out.print(usingBundles[i]); } out.println(); }
Example 7
Source File: ServiceListenerTestSuite.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 4 votes |
public void serviceChanged(ServiceEvent evt) { events.add(evt); out.println("ServiceEvent: " +toString(evt) ); if (ServiceEvent.UNREGISTERING==evt.getType()) { ServiceReference sr = evt.getServiceReference(); // Validate that no bundle is marked as using the service Bundle[] usingBundles = sr.getUsingBundles(); if (checkUsingBundles && null!=usingBundles) { teststatus = false; printUsingBundles(sr, "*** Using bundles (unreg) should be null " +"but is: "); } // Check if the service can be fetched Object service = bc.getService(sr); usingBundles = sr.getUsingBundles(); if (UNREGISTERSERVICE_VALID_DURING_UNREGISTERING) { // In this mode the service shall be obtainable during // unregistration. if (null==service) { teststatus = false; out.print("*** Service should be available to ServiceListener " +"while handling unregistering event."); } out.println("Service (unreg): " +service); if (checkUsingBundles && usingBundles.length!=1) { teststatus = false; printUsingBundles(sr, "*** One using bundle expected " +"(unreg, after getService), found: "); } else { printUsingBundles(sr, "Using bundles (unreg, after getService): "); } } else { // In this mode the service shall NOT be obtainable during // unregistration. if (null!=service) { teststatus = false; out.print("*** Service should not be available to ServiceListener " +"while handling unregistering event."); } if (checkUsingBundles && null!=usingBundles) { teststatus = false; printUsingBundles(sr, "*** Using bundles (unreg, after getService), " +"should be null but is: "); } else { printUsingBundles(sr, "Using bundles (unreg, after getService): null"); } } bc.ungetService(sr); // Check that the UNREGISTERING service can not be looked up // using the service registry. try { Long sid = (Long)sr.getProperty(Constants.SERVICE_ID); String sidFilter = "(" +Constants.SERVICE_ID +"=" +sid +")"; ServiceReference[] srs = bc.getServiceReferences((String)null, sidFilter); if (null==srs || 0==srs.length) { out.println("ServiceReference for UNREGISTERING service is not" +" found in the service registry; ok."); } else { teststatus = false; out.println("*** ServiceReference for UNREGISTERING" +" service, " + sr +", not found in the service registry; fail."); out.print("Found the following Service references: "); for (int i=0; null!=srs && i<srs.length; i++) { if (i>0) out.print(", "); out.print(srs[i]); } out.println(); } } catch (Throwable t) { teststatus = false; out.println("*** Unexpected excpetion when trying to lookup a" +" service while it is in state UNREGISTERING; " +t); t.printStackTrace(out); } } }