@Override @SuppressWarnings("unchecked") public void start(BundleContext context) throws Exception { osgiServiceUtil = new OsgiServiceUtil( context ); // Build a JtaPlatform specific for this OSGi context final OsgiJtaPlatform osgiJtaPlatform = new OsgiJtaPlatform( osgiServiceUtil ); final Dictionary properties = new Hashtable(); // In order to support existing persistence.xml files, register using the legacy provider name. properties.put( "javax.persistence.provider", HibernatePersistenceProvider.class.getName() ); persistenceProviderService = context.registerService( PersistenceProvider.class.getName(), new OsgiPersistenceProviderService( osgiJtaPlatform, osgiServiceUtil ), properties ); sessionFactoryService = context.registerService( SessionFactory.class.getName(), new OsgiSessionFactoryService( osgiJtaPlatform, osgiServiceUtil ), new Hashtable() ); }
static Xnio doGetOsgiService() { Bundle bundle = FrameworkUtil.getBundle(Xnio.class); BundleContext context = bundle.getBundleContext(); if (context == null) { throw new IllegalStateException("Bundle not started"); } ServiceReference<Xnio> sr = context.getServiceReference(Xnio.class); if (sr == null) { return null; } return context.getService(sr); }
@Override public String getResourceURL(long bundleID, String resource) { Bundle b = bundleContext.getBundle(bundleID); if (b == null) throw new IllegalArgumentException("Not a valid bundle ID: " + bundleID); URL res = b.getResource(resource); if (res == null) return null; else return res.toString(); } }
@Override public void start(BundleContext bundleContext) throws Exception { Bundle bundle = bundleContext.getBundle(); pluginId = bundle.getSymbolicName(); pluginHealthService = bundleContext.getService(bundleContext.getServiceReference(PluginHealthService.class)); LoggingService loggingService = bundleContext.getService(bundleContext.getServiceReference(LoggingService.class)); Logger.initialize(loggingService); getImplementersAndRegister(bundleContext, bundle); reportErrorsToHealthService(); }
@Override public void start(BundleContext context) throws Exception { bc = context; eaRef = bc.getServiceReference(EventAdmin.class.getName()); if (eaRef != null) { setEa((EventAdmin) bc.getService(eaRef)); } }
public void updateBundleFromUrl(String bundleSymbolicName, String url) throws BundleException, BundleNotAvailableException, MalformedURLException, IOException { long id = InstrumentationSupport.getBundleId(bundleSymbolicName, ac); ac.getBundleContext().getBundle(id).update((new URL(url)).openStream()); }
protected InputStream requireDataFile(String uri) throws IOException { URL url = bundleContext.getBundle().getResource(uri); if (url == null) { throw new IllegalArgumentException("Could not find file '" + uri + "' on the bundle classpath"); } return url.openStream(); }
@Override protected InputStream getResourceAsStream(String resource) throws IOException { final URL theResource = bundleContext.getBundle().getResource(resource); if (theResource != null) { return theResource.openConnection().getInputStream(); } return null; } }
final List<URL> result = new LinkedList<URL>(); for (final Bundle bundle : bundleContext.getBundles()) { while (enumeration.hasMoreElements()) { final URL url = enumeration.nextElement(); final String path = url.getPath(); while (jars.hasMoreElements()) { final URL jar = jars.nextElement(); final InputStream inputStream = classLoader.getResourceAsStream(jar.getPath()); if (inputStream == null) { LOGGER.config(LocalizationMessages.OSGI_REGISTRY_ERROR_OPENING_RESOURCE_STREAM(jar)); result.add(bundle.getResource(jarEntryName));
public synchronized void start () throws Exception { final BundleContext context = FrameworkUtil.getBundle ( EventInjectorManager.class ).getBundleContext (); this.impl = new EventInjectorImpl ( context, this.evaluator ); final Dictionary<String, Object> properties = new Hashtable<> (); properties.put ( Constants.SERVICE_DESCRIPTION, "Event injector manager" ); properties.put ( Constants.SERVICE_VENDOR, "Eclipse SCADA Project" ); properties.put ( "osgi.command.scope", "ein" ); properties.put ( "osgi.command.function", new String[] { "rules", "state" } ); properties.put ( ConfigurationAdministrator.FACTORY_ID, "org.eclipse.scada.ae.server.injector" ); context.registerService ( ConfigurationFactory.class, this.impl, properties ); }
public OSGIKillbillEventDispatcher(final BundleContext context) { symbolicName = context.getBundle().getSymbolicName(); handlerToObserver = new HashMap<Object, Observer>(); observableTracker = new ServiceTracker<Observable, Observable>(context, OBSERVABLE_SERVICE_NAME, null); observableTracker.open(); }
/** * @throws Exception */ @Test public void testAllBundlesActiveAndFeaturesInstalled() throws Exception { // Asssert all bundles except fragments are ACTIVE. for (Bundle b : bundleCtx.getBundles()) { System.out.println(String.format("Checking state of bundle [symbolicName=%s, state=%s]", b.getSymbolicName(), b.getState())); if (b.getHeaders().get(Constants.FRAGMENT_HOST) == null) assertTrue(b.getState() == Bundle.ACTIVE); } // Check that according to the FeaturesService, all Ignite features except ignite-log4j are installed. Feature[] features = featuresSvc.getFeatures(IGNITE_FEATURES_NAME_REGEX); assertNotNull(features); assertEquals(EXPECTED_FEATURES, features.length); for (Feature f : features) { if (IGNORED_FEATURES.contains(f.getName())) continue; boolean installed = featuresSvc.isInstalled(f); System.out.println(String.format("Checking if feature is installed [featureName=%s, installed=%s]", f.getName(), installed)); assertTrue(installed); assertEquals(PROJECT_VERSION.replaceAll("-", "."), f.getVersion().replaceAll("-", ".")); } }
@Activate protected void activate(ComponentContext componentContext) throws Exception { boolean enabled = PropertiesUtil.toBoolean(componentContext.getProperties().get(ENABLED), false); if (enabled) { BundleContext bundleContext = componentContext.getBundleContext(); Whiteboard whiteboard = new OsgiWhiteboard(bundleContext); executor = new WhiteboardExecutor(); executor.start(whiteboard); backgroundObserver = new BackgroundObserver(nodeStateSolrServersObserver, executor, 5); regs.add(bundleContext.registerService(Observer.class.getName(), backgroundObserver, null)); } }
Class<?> cls = null; Bundle[] bundles = bundle.getBundleContext().getBundles(); if (b.getState() <= Bundle.RESOLVED || b.getHeaders().get(Constants.FRAGMENT_HOST) != null) continue;
public void start(final BundleContext context) throws Exception { startLevelServiceReference = context.getServiceReference(StartLevel.class.getName()); startLevel = (StartLevel) context.getService(startLevelServiceReference); for (final Bundle bundle : context.getBundles()) { final String value = bundle.getHeaders().get("Service-Component"); if (value != null) { List<String> componentDescriptions = Arrays.asList(value.split("\\s*,\\s*")); for (String desc : componentDescriptions) { final URL url = bundle.getResource(desc); process(url); context.addServiceListener(new ServiceListener() { public void serviceChanged(final ServiceEvent event) { final ServiceReference sr = event.getServiceReference(); final ServiceReference[] srs = context.getServiceReferences(correspondingInterface, null); if (srs != null) { for (final ServiceReference sr : srs) {
@SuppressWarnings("squid:S1149") protected final void registerAsSlingFilter(ComponentContext ctx, int ranking, String pattern) { Dictionary<String, String> filterProps = new Hashtable<String, String>(); filterProps.put("service.ranking", String.valueOf(ranking)); filterProps.put("sling.filter.scope", "REQUEST"); filterProps.put("sling.filter.pattern", StringUtils.defaultIfEmpty(pattern, ".*")); filterRegistration = ctx.getBundleContext().registerService(Filter.class.getName(), this, filterProps); }
long registerService() { final Bundle bundle = this.cache.getBundle(); final Dictionary<String, Object> props = new Hashtable<>(); props.put(Constants.SERVICE_DESCRIPTION, "Provider of bundle based resources from bundle " + String.valueOf(bundle.getBundleId())); props.put(Constants.SERVICE_VENDOR, "The Apache Software Foundation"); props.put(ResourceProvider.PROPERTY_ROOT, this.root.getResourceRoot()); props.put(PROP_BUNDLE,bundle.getBundleId()); serviceRegistration = bundle.getBundleContext().registerService(ResourceProvider.class, this, props); return (Long) serviceRegistration.getReference().getProperty(Constants.SERVICE_ID); }
@Override public void run(final ProxyManager pm) throws Exception { String[] objectClassProperty = (String[]) originalRef.getProperty(Constants.OBJECTCLASS); ServiceFactory<Object> sf = new ProxyServiceFactory(pm, originalRef); registrationHolder.registration = originalRef.getBundle().getBundleContext().registerService( objectClassProperty, sf, proxyPropertiesRoles()); Dictionary<String, Object> actualProxyProps = copyProperties(registrationHolder.registration.getReference()); LOG.debug("Created proxy of service {} under {} with properties {}", orgServiceID, actualProxyProps.get(Constants.OBJECTCLASS), actualProxyProps); }
protected static String lookup(ComponentContext context, String property) { //Prefer property from BundleContext first if (context.getBundleContext().getProperty(property) != null) { return context.getBundleContext().getProperty(property); } if (context.getProperties().get(property) != null) { return context.getProperties().get(property).toString(); } return null; } }
private void registerInternalServices(BundleContext bundleContext) { bundleContext.registerService(PluginHealthService.class, new DefaultPluginHealthService(registry), null); bundleContext.registerService(LoggingService.class, new DefaultPluginLoggingService(systemEnvironment), null); }