public CompletableFutureDependencyImpl(Component c, CompletableFuture<F> future) { super.setRequired(true); m_future = future; m_comp = c; }
/** * Sets a callback method invoked on the instantiated component. */ public ConfigurationDependencyImpl setCallback(String callback) { super.setCallbacks(callback, null); return this; }
@SuppressWarnings("unchecked") public T setPropagate(boolean propagate, boolean overrideServiceProperties) { ensureNotActive(); m_propagate = propagate; m_propagateOverrides = overrideServiceProperties; return (T) this; }
@Override public void start() { Dictionary<String, Object> props = null; if (m_trackedResource != null) { props = new Hashtable<>(); props.put(ResourceHandler.URL, m_trackedResource); } else { if (m_resourceFilter != null) { props = new Hashtable<>(); props.put(ResourceHandler.FILTER, m_resourceFilter); } } m_registration = m_component.getBundleContext().registerService(ResourceHandler.class.getName(), this, props); super.start(); }
@Override public void start() { try { if (m_async) { if (m_exec != null) { m_future.whenCompleteAsync((result, error) -> completed(result, error), m_exec); } else { m_future.whenCompleteAsync((result, error) -> completed(result, error)); } } else { m_future.whenComplete((result, error) -> completed(result, error)); } } catch (Throwable error) { super.getComponentContext().getLogger().log(LogService.LOG_ERROR, "completable future failed", error); } super.start(); }
/** * Copy all dependency service instances to the given collection. */ @Override public void copyToCollection(Collection<Object> services) { Set<Event> events = m_component.getDependencyEvents(this); if (events.size() > 0) { for (Event e : events) { services.add(e.getEvent()); } } else { Object defaultService = getDefaultService(false); if (defaultService != null) { services.add(defaultService); } } }
/** * @see {@link ServiceDependency#setAutoConfig(boolean)} */ @SuppressWarnings("unchecked") public T setAutoConfig(boolean autoConfig) { if (autoConfig && getAutoConfigType() == null) { throw new IllegalStateException("Dependency does not support auto config mode"); } m_autoConfig = autoConfig; m_autoConfigInvoked = true; return (T) this; }
/** * Triggers component activation when the future has completed. * @param result * @param error */ private void completed(F result, Throwable error) { if (error != null) { super.getComponentContext().getLogger().log(LogService.LOG_ERROR, "completable future failed", error); } else { // Will trigger component activation (if other dependencies are satisfied), and our invokeCallback method will then be called. m_component.handleEvent(this, EventType.ADDED, new Event(result)); } }
Object[] instances = super.getInstances(); // never null, either the callback instance or the component instances
@Override public void start() { BundleContext context = m_component.getBundleContext(); if (context != null) { // If null, we are in a test environment Properties props = new Properties(); props.put(Constants.SERVICE_PID, m_pid); ManagedService ms = this; if (m_metaType != null) { ms = m_metaType; props.put(MetaTypeProvider.METATYPE_PID, m_pid); String[] ifaces = new String[] { ManagedService.class.getName(), MetaTypeProvider.class.getName() }; m_registration = context.registerService(ifaces, ms, toR6Dictionary(props)); } else { m_registration = context.registerService(ManagedService.class.getName(), ms, toR6Dictionary(props)); } } super.start(); }
/** * Copy all dependency service instances to the given map (key = dependency service, value = dependency service properties. */ @Override public void copyToMap(Map<Object, Dictionary<?, ?>> map) { Set<Event> events = m_component.getDependencyEvents(this); if (events.size() > 0) { for (Event e : events) { map.put(e.getEvent(), e.getProperties()); } } else { Object defaultService = getDefaultService(false); if (defaultService != null) { map.put(defaultService, EMPTY_PROPERTIES); } } }
/** * @see {@link ServiceDependency#setAutoConfig(String instanceName)} */ @SuppressWarnings("unchecked") public T setAutoConfig(String instanceName) { if (instanceName != null && getAutoConfigType() == null) { throw new IllegalStateException("Dependency does not support auto config mode"); } m_autoConfig = (instanceName != null); m_autoConfigInstance = instanceName; m_autoConfigInvoked = true; return (T) this; }
super.getComponentContext().getLogger().log(LogService.LOG_ERROR, "completable future failed", exc);
@Override public ConfigurationDependencyImpl setRequired(boolean required) { m_optional = ! required; super.setRequired(true); // always required return this; }
/** * Sets the add/change/remove callbacks. * @param add the callback to invoke when a dependency is added * @param change the callback to invoke when a dependency has changed * @param remove the callback to invoke when a dependency is removed * @return this dependency instance */ public T setCallbacks(String add, String change, String remove) { return setCallbacks(null, add, change, remove); }
@Override public void start() { m_tracker = new BundleTracker(m_component.getBundleContext(), m_stateMask, this); m_tracker.open(); super.start(); }
/** * Get the highest ranked available dependency service, or null. */ @Override public Event getService() { Event event = m_component.getDependencyEvent(this); if (event == null) { Object defaultService = getDefaultService(true); if (defaultService != null) { event = new Event(defaultService); } } return event; }
/** * Activates Dependency service properties propagation (to the service properties of the component to which this * dependency is added). * * @param propagate true if the dependency service properties must be propagated to the service properties of * the component to which this dependency is added. * @return this dependency instance */ @SuppressWarnings("unchecked") public T setPropagate(boolean propagate) { ensureNotActive(); m_propagate = propagate; return (T) this; }
public ToggleServiceDependency() { super.setRequired(true); }