/** * Returns the Update callback instances. */ private Object[] getUpdateCallbackInstances(Component comp) { if (m_callbackInstance == null) { return comp.getInstances(); } else { return new Object[] { m_callbackInstance }; } }
/** * Finds a composite * @param component * @param type * @return */ @SuppressWarnings("unchecked") public static <U> U findCompositeInstance(Component component, Class<U> type) { U instance = (U) Stream.of(component.getInstances()) .filter(inst -> Objects.equals(Helpers.getClass(inst), type)) .findFirst() .orElseThrow(() -> new RuntimeException("Did not find a component instance matching type " + type)); return instance; }
@SuppressWarnings("unchecked") private <U> BundleAdapterBuilder setComponentCallbackRef(Cb cbType, Class<U> type, MethodRef<U> ref) { checkHasNoReflectionCallbacks(); List<MethodRef<Object>> list = m_refs.computeIfAbsent(cbType, l -> new ArrayList<>()); list.add((instance, component, bundle) -> { Object componentImpl = Stream.of(component.getInstances()) .filter(impl -> type.isAssignableFrom(Helpers.getClass(impl))) .findFirst() .orElseThrow(() -> new IllegalStateException("The method reference " + ref + " does not match any available component impl classes.")); ref.accept((U) componentImpl, component, bundle); }); return this; }
protected <I> B setComponentCallbackRef(Cb cbType, Class<I> type, MethodRef<I, S> ref) { requiresNoCallbacks(); if (! m_autoConfigInvoked) m_autoConfig = false; List<MethodRef<Object, S>> list = m_refs.computeIfAbsent(cbType, l -> new ArrayList<>()); list.add((instance, component, sref, service) -> { Object componentImpl = Stream.of(component.getInstances()) .filter(impl -> type.isAssignableFrom(Helpers.getClass(impl))) .findFirst() .orElseThrow(() -> new IllegalStateException("The method reference " + ref + " does not match any available component impl classes.")); ref.accept((I) componentImpl, component, sref, service); }); return (B) this; }
public <I> B setComponentSwapCallbackRef(Class<I> type, SwapMethodRef<I, S> ref) { requiresNoCallbacks(); if (! m_autoConfigInvoked) m_autoConfig = false; m_swapRefs.add((instance, component, oref, oservice, nref, nservice) -> { Object componentImpl = Stream.of(component.getInstances()) .filter(impl -> type.isAssignableFrom(Helpers.getClass(impl))) .findFirst() .orElseThrow(() -> new IllegalStateException("The method reference " + ref + " does not match any available component impl classes.")); ref.accept((I) componentImpl, component, oref, oservice, nref, nservice); }); return (B) this; }
private <T> BundleDependencyBuilder setComponentCallbackRef(Cb cbType, Class<T> type, MethodRef<T> ref) { requiresNoStringCallbacks(); if (! m_autoConfigInvoked) m_autoConfig = false; List<MethodRef<Object>> list = m_refs.computeIfAbsent(cbType, l -> new ArrayList<>()); list.add((instance, component, bundle) -> { Object componentImpl = Stream.of(component.getInstances()) .filter(impl -> type.isAssignableFrom(Helpers.getClass(impl))) .findFirst() .orElseThrow(() -> new IllegalStateException("The method reference " + ref + " does not match any available component impl classes.")); ref.accept((T) componentImpl, component, bundle); }); return this; }
@SuppressWarnings("unchecked") private <T> FactoryPidAdapterBuilder setComponentCallbackRef(Class<T> type, MethodRef<T> ref) { checkHasNoReflectionCallbacks(); m_hasMethodRefs = true; m_refs.add((instance, component, props) -> { Object componentImpl = Stream.of(component.getInstances()) .filter(impl -> type.isAssignableFrom(Helpers.getClass(impl))) .findFirst() .orElseThrow(() -> new IllegalStateException("The method reference " + ref + " does not match any available component impl classes.")); ref.accept((T) componentImpl, component, props); }); return this; }
@SuppressWarnings("unchecked") private <T> ConfigurationDependencyBuilder setComponentCallbackRef(Class<T> type, MethodRef<T> ref) { checkHasNoReflectionCallbacks(); m_updateMethodName = null; m_hasMethodRefs = true; m_hasComponentCallbackRefs = true; m_refs.add((instance, component, props) -> { Object componentImpl = Stream.of(component.getInstances()) .filter(impl -> type.isAssignableFrom(Helpers.getClass(impl))) .findFirst() .orElseThrow(() -> new IllegalStateException("The method reference " + ref + " does not match any available component impl classes.")); ref.accept((T) componentImpl, component, props); }); return this; }
/** * Invoke a callback on all Service compositions. */ private void callbackComposites(Component service, String callback) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException { Object[] composites = service.getInstances(); for (Object composite: composites) { invokeMethod(composite, callback, service.getDependencyManager(), service); } }
Object[] composites = service.getInstances(); for (Object composite: composites)
Object[] componentInstances = c.getInstances(); for (Object instance : componentInstances) if (wasRegistered && m_unregistered != null) Object[] componentInstances = c.getInstances(); for (Object instance : componentInstances)
throws Exception Object serviceInstance = c.getInstances()[0]; DependencyManager dm = c.getDependencyManager(); Object[] composites = c.getInstances(); for (Object composite: composites)