@Override public S getInstance() { final ComponentInstance<S> componentInstance = cm.getComponentInstance(); return componentInstance == null? null: componentInstance.getInstance(); }
@Override public void disposeComponent(String componentObject) { ComponentInstance componentInstance = componentInstances.get(componentObject); if (componentInstance != null) componentInstance.dispose(); } }
@Override public S getInstance() { final ComponentInstance<S> componentInstance = cm.getComponentInstance(); return componentInstance == null? null: componentInstance.getInstance(); }
/** * Callend when any of the SCR Components required dependencies become unsatisfied. */ @Deactivate public void deactivate() { LOG.info("Deactivating the {}", COMPONENT_LABEL); try { lock.readLock().lock(); greeterService.stopGreeter(); instance.dispose(); } finally { lock.readLock().unlock(); } }
/** * Called when all of the SCR Components required dependencies have been satisfied. */ @Activate public void activate() { LOG.info("Activating the {}", COMPONENT_LABEL); try { lock.readLock().lock(); if (factory != null) { final Properties props = new Properties(); props.setProperty("salutation", "Hello"); props.setProperty("name", "User"); instance = factory.newInstance((Dictionary) props); greeterService = (GreeterServiceComponentFactory) instance.getInstance(); greeterService.startGreeter(); } } finally { lock.readLock().unlock(); } }
log.info("deactivate Referenced Site {}", siteConfiguration.getName()); if (this.dereferencerComponentInstance != null) { this.dereferencerComponentInstance.dispose(); this.dereferencerComponentInstance = null; this.entitySearcherComponentInstance.dispose(); this.entitySearcherComponentInstance = null;
/** * Called by dispatcher ( Resolver) when service properties have been modified for some reference * * @param serviceReferenceTable Map of <Reference>:<Map of <ServiceComponentProp>:<ServiceReference>> */ final void referencePropertiesUpdated(Hashtable serviceReferenceTable) { // for each element in the table Enumeration e = serviceReferenceTable.keys(); while (e.hasMoreElements()) { Reference ref = (Reference) e.nextElement(); Hashtable serviceSubTable = (Hashtable) serviceReferenceTable.get(ref); Enumeration sub = serviceSubTable.keys(); while (sub.hasMoreElements()) { ServiceComponentProp scp = (ServiceComponentProp) sub.nextElement(); ServiceReference serviceReference = (ServiceReference) serviceSubTable.get(scp); // get the list of instances created Vector instances = scp.instances; for (int i = 0; i < instances.size(); i++) { ComponentInstance compInstance = (ComponentInstance) instances.elementAt(i); if (compInstance != null) { try { scp.updatedReference(ref, compInstance, serviceReference); } catch (Throwable t) { Activator.log(null, LogService.LOG_ERROR, NLS.bind(Messages.ERROR_UPDATING_REFERENCE, ref.reference, compInstance.getInstance()), t); } } } } } }
log.info("deactivate Referenced Site {}", siteConfiguration.getName()); if (this.dereferencerComponentInstance != null) { this.dereferencerComponentInstance.dispose(); this.dereferencerComponentInstance = null; this.entitySearcherComponentInstance.dispose(); this.entitySearcherComponentInstance = null;
/** * Called by dispatcher ( Resolver) when service properties have been modified for some reference * * @param serviceReferenceTable Map of <Reference>:<Map of <ServiceComponentProp>:<ServiceReference>> */ final void referencePropertiesUpdated(Hashtable serviceReferenceTable) { // for each element in the table Enumeration e = serviceReferenceTable.keys(); while (e.hasMoreElements()) { Reference ref = (Reference) e.nextElement(); Hashtable serviceSubTable = (Hashtable) serviceReferenceTable.get(ref); Enumeration sub = serviceSubTable.keys(); while (sub.hasMoreElements()) { ServiceComponentProp scp = (ServiceComponentProp) sub.nextElement(); ServiceReference serviceReference = (ServiceReference) serviceSubTable.get(scp); // get the list of instances created Vector instances = scp.instances; for (int i = 0; i < instances.size(); i++) { ComponentInstance compInstance = (ComponentInstance) instances.elementAt(i); if (compInstance != null) { try { scp.updatedReference(ref, compInstance, serviceReference); } catch (Throwable t) { Activator.log(null, LogService.LOG_ERROR, NLS.bind(Messages.ERROR_UPDATING_REFERENCE, ref.reference, compInstance.getInstance()), t); } } } } } }
@Component(immediate=true) @Instantiate public class Controller { @Requires(filter="(factory.name=A)") Factory factoryOfA; @Requires(filter="(factory.name=B)") Factory factoryOfB; ComponentInstance instance; @Validate public void createA() throws Exception { instance = factoryOfA.createInstance(null); } public void switchToB() throws Exception { instance.dispose(); instance = factoryOfB.createInstance(null); } }
scp.unbindDynamicReference(ref, compInstance, serviceReference); } catch (Throwable t) { Activator.log(null, LogService.LOG_ERROR, NLS.bind(Messages.ERROR_UNBINDING_REFERENCE, ref.reference, compInstance.getInstance()), t);
scp.unbindDynamicReference(ref, compInstance, serviceReference); } catch (Throwable t) { Activator.log(null, LogService.LOG_ERROR, NLS.bind(Messages.ERROR_UNBINDING_REFERENCE, ref.reference, compInstance.getInstance()), t);
public Object getService(Bundle bundle, ServiceRegistration registration) { try { if (Activator.DEBUG) { Activator.log.debug("FactoryReg.getService(): created new service for component " + component.name, null); //$NON-NLS-1$ } ComponentInstance ci = InstanceProcess.staticRef.buildComponent(bundle, component, null, false); // ci can be null if the component is already disposed while being built if (ci != null) { return ci.getInstance(); } } catch (Throwable t) { if (!(t instanceof ComponentException)) { Activator.log(component.bc, LogService.LOG_ERROR, NLS.bind(Messages.CANT_GET_SERVICE, component.name), t); } else { throw (ComponentException) t; } } return null; }
public Object getService(Bundle bundle, ServiceRegistration registration) { try { if (Activator.DEBUG) { Activator.log.debug("FactoryReg.getService(): created new service for component " + component.name, null); //$NON-NLS-1$ } ComponentInstance ci = InstanceProcess.staticRef.buildComponent(bundle, component, null, false); // ci can be null if the component is already disposed while being built if (ci != null) { return ci.getInstance(); } } catch (Throwable t) { if (!(t instanceof ComponentException)) { Activator.log(component.bc, LogService.LOG_ERROR, NLS.bind(Messages.CANT_GET_SERVICE, component.name), t); } else { throw (ComponentException) t; } } return null; }
updatedMethod.invoke(instance.getInstance(), params); } catch (Throwable t) { logError(NLS.bind(Messages.ERROR_UPDATING_REFERENCE, this, instance.getInstance()), t, reference); } finally { if (params.length == 1) {
unbindMethod.invoke(instance.getInstance(), params); } catch (Throwable t) { logError(NLS.bind(Messages.EXCEPTION_UNBINDING_REFERENCE, this), t, reference);
updatedMethod.invoke(instance.getInstance(), params); } catch (Throwable t) { logError(NLS.bind(Messages.ERROR_UPDATING_REFERENCE, this, instance.getInstance()), t, reference); } finally { if (params.length == 1) {
unbindMethod.invoke(instance.getInstance(), params); } catch (Throwable t) { logError(NLS.bind(Messages.EXCEPTION_UNBINDING_REFERENCE, this), t, reference);
referencedSite = new ReferencedSiteImpl(config, offlineMode == null && dereferencerComponentInstance != null ? (EntityDereferencer)dereferencerComponentInstance.getInstance() : null, offlineMode == null && searcherComponentInstance != null ? (EntitySearcher)searcherComponentInstance.getInstance() : null, cache, nsPrefixService);
referencedSite = new ReferencedSiteImpl(config, offlineMode == null && dereferencerComponentInstance != null ? (EntityDereferencer)dereferencerComponentInstance.getInstance() : null, offlineMode == null && searcherComponentInstance != null ? (EntitySearcher)searcherComponentInstance.getInstance() : null, cache, nsPrefixService);