public Object addingService()

in cdi-extender/src/main/java/org/apache/aries/cdi/container/internal/container/ReferenceSync.java [53:107]


	public Object addingService(final ServiceReference<Object> reference) {
		if (!Perms.hasGetServicePermission(_templateDTO.serviceType, _containerState.bundleContext())) {
			return null;
		}

		boolean active = _componentInstanceDTO.active;
		boolean resolved = (_referenceDTO.matches.size() >= _templateDTO.minimumCardinality);
		boolean dynamic = (_templateDTO.policy == ReferencePolicy.DYNAMIC);
		boolean reluctant = (_templateDTO.policyOption == ReferencePolicyOption.RELUCTANT);
		CollectionType collectionType = _templateDTO.collectionType;
		boolean requiresUpdate = true;

		if (resolved && reluctant && active && !dynamic) {
			requiresUpdate = false;
		}

		try (Syncro open = _syncro.open()) {
			_referenceDTO.matches = SRs.from(_referenceDTO.serviceTracker.getServiceReferences(), reference);

			if (collectionType == CollectionType.BINDER_SERVICE ||
				collectionType == CollectionType.BINDER_REFERENCE ||
				collectionType == CollectionType.BINDER_BEAN_SERVICE_OBJECTS) {

				requiresUpdate = false;

				return _referenceDTO.binder.addingService(reference);
			}
			else if (collectionType == CollectionType.PROPERTIES) {
				return Maps.of(reference.getProperties());
			}
			else if (collectionType == CollectionType.REFERENCE) {
				return reference;
			}
			else if (collectionType == CollectionType.SERVICEOBJECTS) {
				return new BeanServiceObjectsImpl<>(
					_containerState.bundleContext().getServiceObjects(reference));
			}
			else if (collectionType == CollectionType.TUPLE) {
				return new SimpleImmutableEntry<>(
					Maps.of(reference.getProperties()),
					_containerState.bundleContext().getService(reference));
			}

			return _containerState.bundleContext().getService(reference);
		}
		finally {
			if (requiresUpdate) {
				InstanceActivator activator = _builder.setInstance(
					_componentInstanceDTO
				).build();

				updateStatically(activator);
			}
		}
	}