Search in sources :

Example 11 with Service

use of org.mule.runtime.api.service.Service in project mule by mulesoft.

the class SpringMuleContextServiceConfigurator method getCustomServiceBeanDefinition.

private BeanDefinition getCustomServiceBeanDefinition(CustomService customService) {
    BeanDefinition beanDefinition;
    Optional<Class> customServiceClass = customService.getServiceClass();
    Optional<Object> customServiceImpl = customService.getServiceImpl();
    if (customServiceClass.isPresent()) {
        beanDefinition = getBeanDefinitionBuilder(customServiceClass.get()).getBeanDefinition();
    } else if (customServiceImpl.isPresent()) {
        if (customServiceImpl.get() instanceof Service) {
            beanDefinition = getConstantObjectBeanDefinition(createInjectProviderParamsServiceProxy((Service) customServiceImpl.get(), registry));
        } else {
            beanDefinition = getConstantObjectBeanDefinition(customServiceImpl.get());
        }
    } else {
        throw new IllegalStateException("A custom service must define a service class or instance");
    }
    return beanDefinition;
}
Also used : CustomService(org.mule.runtime.core.internal.config.CustomService) DefaultClusterService(org.mule.runtime.core.internal.cluster.DefaultClusterService) Service(org.mule.runtime.api.service.Service) MuleValueProviderService(org.mule.runtime.core.internal.value.MuleValueProviderService) EventContextService(org.mule.runtime.core.api.event.EventContextService) DefaultConnectivityTestingService(org.mule.runtime.core.internal.connectivity.DefaultConnectivityTestingService) DefaultStreamCloserService(org.mule.runtime.core.internal.util.DefaultStreamCloserService) ExtendedTransformationService(org.mule.runtime.core.privileged.transformer.ExtendedTransformationService) DefaultEventContextService(org.mule.runtime.core.internal.event.DefaultEventContextService) MuleMetadataService(org.mule.runtime.core.internal.metadata.MuleMetadataService) BeanDefinitionBuilder.genericBeanDefinition(org.springframework.beans.factory.support.BeanDefinitionBuilder.genericBeanDefinition) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition)

Example 12 with Service

use of org.mule.runtime.api.service.Service in project mule by mulesoft.

the class InjectParamsFromContextServiceProxy method createInjectProviderParamsServiceProxy.

/**
 * Creates a proxy for the provided service instance.
 *
 * @param service service to wrap. Non null.
 * @param registry the {@link Registry} to use for resolving injectable parameters. Non null.
 * @return a new proxy instance.
 */
public static Service createInjectProviderParamsServiceProxy(Service service, Registry registry) {
    checkArgument(service != null, "service cannot be null");
    checkArgument(registry != null, "registry cannot be null");
    InvocationHandler handler = new InjectParamsFromContextServiceProxy(service, registry);
    return (Service) newProxyInstance(service.getClass().getClassLoader(), findImplementedInterfaces(service.getClass()), handler);
}
Also used : Service(org.mule.runtime.api.service.Service) MetadataInvocationHandler(org.mule.runtime.container.internal.MetadataInvocationHandler) InvocationHandler(java.lang.reflect.InvocationHandler)

Aggregations

Service (org.mule.runtime.api.service.Service)12 ArtifactClassLoader (org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoader)8 ArrayList (java.util.ArrayList)7 Pair (org.mule.runtime.api.util.Pair)6 Test (org.junit.Test)5 ServiceDiscoverer (org.mule.runtime.module.service.api.discoverer.ServiceDiscoverer)5 InOrder (org.mockito.InOrder)3 InvocationHandler (java.lang.reflect.InvocationHandler)2 MetadataInvocationHandler (org.mule.runtime.container.internal.MetadataInvocationHandler)2 Collection (java.util.Collection)1 Comparator.comparing (java.util.Comparator.comparing)1 HashSet (java.util.HashSet)1 LinkedHashMap (java.util.LinkedHashMap)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 Collectors.toList (java.util.stream.Collectors.toList)1 DefaultExpressionLanguageFactoryService (org.mule.runtime.api.el.DefaultExpressionLanguageFactoryService)1 MuleException (org.mule.runtime.api.exception.MuleException)1