/** * Sets propagation of the configuration properties to the service * properties. Any additional service properties specified directly * are merged with these. */ public ConfigurationDependency setPropagate(boolean propagate) { m_delegate.setPropagate(propagate); return this; }
@Override public ConfigurationDependency build() { String pid = m_pid == null ? (m_configType != null ? m_configType.getName() : null) : m_pid; if (pid == null) { throw new IllegalStateException("Pid not specified"); } ConfigurationDependency dep = m_component.getDependencyManager().createConfigurationDependency(); Objects.nonNull(m_pid); dep.setPid(pid); dep.setPropagate(m_propagate); dep.setRequired(m_required); if (m_updateMethodName != null) { dep.setCallback(m_updateCallbackInstance, m_updateMethodName, m_configType); } else if (m_refs.size() > 0) { // setup an internal callback object. When config is updated, we have to call each registered // method references. // Notice that we need the component to be instantiated in case there is a mref on one of the component instances (unbound method ref), or is used // called "needsInstance(true)". dep.setCallback(new Object() { @SuppressWarnings("unused") void updated(Component comp, Dictionary<String, Object> props) { m_refs.forEach(mref -> mref.accept(null, comp, props)); } }, "updated", m_hasComponentCallbackRefs); } return dep; }
private Dependency createConfigurationDependency(DependencyManager dm, Bundle b, String pid, String callback, String[] configTypes, boolean propagate, boolean required) throws ClassNotFoundException { if (pid == null) { throw new IllegalArgumentException( "pid attribute not provided in ConfigurationDependency declaration"); } ConfigurationDependency cd = dm.createConfigurationDependency(); cd.setPid(pid); cd.setCallback(callback); cd.setPropagate(propagate, true /* configuration will override default service properties */); cd.setRequired(required); if (configTypes != null) { Class<?>[] configTypeClasses = new Class<?>[configTypes.length]; for (int i = 0; i < configTypes.length; i ++) { configTypeClasses[i] = b.loadClass(configTypes[i]); } cd.setConfigType(configTypeClasses); } return cd; }
@Override public void init(BundleContext context, DependencyManager manager) throws Exception { Properties props = new Properties(); props.put(CommandProcessor.COMMAND_SCOPE, "ace"); props.put(CommandProcessor.COMMAND_FUNCTION, new String[] { "cw", "gw", "rw" }); manager.add(createComponent().setInterface(WorkspaceManager.class.getName(), props) .setImplementation(WorkspaceManagerImpl.class) .add(createServiceDependency().setService(SessionFactory.class).setRequired(true)) .add(createConfigurationDependency().setPropagate(true).setPid(WORKSPACE_PID)) .add(createServiceDependency().setService(LogService.class).setRequired(false))); }
@Override public void init(BundleContext context, DependencyManager manager) throws Exception { manager.add(createComponent() .setInterface(HttpServlet.class.getName(), null) .setImplementation(DeploymentServlet.class) .add(createServiceDependency().setService(StreamGenerator.class).setRequired(true)) .add(createServiceDependency().setService(DeploymentProvider.class).setRequired(true)) .add(createServiceDependency().setService(LogService.class).setRequired(false)) .add(createConfigurationDependency().setPropagate(true).setPid(PID))); }