/** * Returns the bundle context that is associated with this bundle. * * @return the bundle context */ public BundleContext getBC() { return m_manager.getBundleContext(); }
/** * Returns the list of currently created dependency managers. * @return the list of currently created dependency managers */ public static List<DependencyManager> getDependencyManagers() { List<DependencyManager> result = new ArrayList<>(); synchronized (m_dependencyManagers) { Iterator<WeakReference<DependencyManager>> iterator = m_dependencyManagers.iterator(); while (iterator.hasNext()) { WeakReference<DependencyManager> reference = iterator.next(); DependencyManager manager = reference.get(); if (manager != null) { try { manager.getBundleContext().getBundle(); result.add(manager); continue; } catch (IllegalStateException e) { } } iterator.remove(); } } return result; }
/** * Called by Felix DM when starting this component. */ public void start() throws IOException { File root = m_dm.getBundleContext().getDataFile(""); if (root == null) { throw new IOException("No file system support"); } m_persistencyManager = new PersistencyManager(root); }
private Bundle getBundle(String bundleLocation, boolean isFactory) throws ResourceProcessorException { Bundle bundle = null; if (!isFactory) { // singleton configuration, no foreign bundles allowed, use source deployment package to find specified bundle if (bundleLocation.startsWith(LOCATION_PREFIX)) { DeploymentSession session = m_sessionRef.get(); bundle = session.getSourceDeploymentPackage().getBundle(bundleLocation.substring(LOCATION_PREFIX.length())); } } else { // factory configuration, foreign bundles allowed, use bundle context to find the specified bundle Bundle[] bundles = m_dm.getBundleContext().getBundles(); for (int i = 0; i < bundles.length; i++) { String location = bundles[i].getLocation(); if (bundleLocation.equals(location)) { bundle = bundles[i]; break; } } } return bundle; }
/** * Called by Felix DM when stopping this component. */ protected void stop( final Component component ) throws IOException { BundleContext context = component.getDependencyManager().getBundleContext(); File repositoryFile = getRepositoryFile( context ); // Store the earlier provisioned configurations (just to be sure)... this.repository.store( repositoryFile ); }
private boolean mayStartNow(Component c) { ComponentExecutorFactory execFactory = m_componentExecutorFactory; BundleContext ctx = c.getDependencyManager().getBundleContext(); String parallel = ctx.getProperty(PARALLEL); if (execFactory == null) { // No ComponentExecutorFactory available. If a "parallel" OSGi system property is specified, // we have to wait for a ComponentExecutorFactory servoce if the component class name is matching one of the // prefixes specified in the "parallel" system property. if (parallel != null && requiresThreadPool(c, parallel)) { return false; // wait for a threadpool } else { return true; // no threadpool required, start the component now, synchronously } } else { // A threadpool is there. If the "parallel" OSGi system property is not specified, we can start the component // now and we'll use the threadpool for it. // But if the "parallel" system property is specified, the component will use the threadpool only if it's // classname is starting with one of the prefixes specified in the property. if (parallel == null || requiresThreadPool(c, parallel)) { createComponentExecutor(execFactory, c); } return true; // start the component now, possibly using the threadpool (see above). } }
/** * Called by Felix DM when starting this component. */ protected void start( final Component component ) throws IOException { BundleContext context = component.getDependencyManager().getBundleContext(); File configDir = getConfigDirectory( context ); File repositoryFile = getRepositoryFile( context ); // Load the earlier provisioned configurations... this.repository.load( repositoryFile ); try { provisionAll( configDir ); } finally { // Store the earlier provisioned configurations... this.repository.store( repositoryFile ); } }
private void registerDiscoveryService() { Properties properties = createEndpointListenerServiceProperties(m_manager.getBundleContext(), BonjourEndpointDiscovery.DISCOVERY_TYPE); BonjourEndpointDiscovery discovery = new BonjourEndpointDiscovery(this); Component component = createComponent() .setInterface(new String[] { EndpointEventListener.class.getName(), EndpointListener.class.getName() }, properties) .setImplementation(discovery) .add(createServiceDependency() .setService(HttpService.class) .setRequired(true)) .add(createServiceDependency() .setService(EndpointEventListener.class) .setCallbacks("eventListenerAdded", "eventListenerModified", "eventListenerRemoved") .setRequired(false)) .add(createServiceDependency() .setService(EndpointListener.class) .setCallbacks("listenerAdded", "listenerModified", "listenerRemoved") .setRequired(false)) .add(createServiceDependency() .setService(LogService.class) .setRequired(false)); m_discovery = component; m_manager.add(m_discovery); }
boolean autoConfigureComponents = "true".equals(dm.getBundleContext().getProperty( Activator.CONF_ENABLE_AUTOCONFIG));