Search in sources :

Example 1 with ServiceProvider

use of io.joynr.jeeintegration.api.ServiceProvider in project joynr by bmwcarit.

the class JoynrIntegrationBean method registerProviders.

private void registerProviders(Set<Bean<?>> serviceProviderBeans, JoynrRuntime runtime) {
    Set<ProviderQosFactory> providerQosFactories = getProviderQosFactories();
    for (Bean<?> bean : serviceProviderBeans) {
        Class<?> beanClass = bean.getBeanClass();
        ServiceProvider providerService = beanClass.getAnnotation(ServiceProvider.class);
        Class<?> serviceInterface = serviceProviderDiscovery.getProviderInterfaceFor(providerService.serviceInterface());
        if (LOG.isDebugEnabled()) {
            LOG.debug(format("Registering %s as provider with joynr runtime for service interface %s.", bean, serviceInterface));
        }
        Object provider = Proxy.newProxyInstance(beanClass.getClassLoader(), new Class<?>[] { serviceInterface }, new ProviderWrapper(bean, beanManager, joynrRuntimeFactory.getInjector()));
        ProviderQos providerQos = null;
        for (ProviderQosFactory factory : providerQosFactories) {
            if (factory.providesFor(serviceInterface)) {
                providerQos = factory.create();
                break;
            }
        }
        if (providerQos == null) {
            providerQos = new ProviderQos();
        }
        runtime.registerProvider(getDomainForProvider(beanClass), provider, providerQos);
        registeredProviders.add(provider);
    }
}
Also used : ProviderQosFactory(io.joynr.jeeintegration.api.ProviderQosFactory) ServiceProvider(io.joynr.jeeintegration.api.ServiceProvider) ProviderQos(joynr.types.ProviderQos)

Example 2 with ServiceProvider

use of io.joynr.jeeintegration.api.ServiceProvider in project joynr by bmwcarit.

the class ServiceProviderDiscovery method findServiceProviderBeans.

@SuppressWarnings("serial")
public Set<Bean<?>> findServiceProviderBeans() {
    Set<Bean<?>> result = new HashSet<>();
    for (Bean<?> bean : beanManager.getBeans(Object.class, new AnnotationLiteral<Any>() {
    })) {
        ServiceProvider serviceProvider = bean.getBeanClass().getAnnotation(ServiceProvider.class);
        if (serviceProvider != null) {
            ProvidedBy providedBy = getProvidedByAnnotation(serviceProvider.serviceInterface());
            verifyProvidedBy(providedBy, serviceProvider.serviceInterface(), bean);
            result.add(bean);
            if (LOG.isTraceEnabled()) {
                LOG.trace(format("Bean %s is a service provider. Adding to result.", bean));
            }
        } else if (LOG.isTraceEnabled()) {
            LOG.trace(format("Ignoring bean: %s", bean));
        }
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug(format("Found the following service provider beans:%n%s", result));
    }
    return result;
}
Also used : ProvidedBy(io.joynr.ProvidedBy) ServiceProvider(io.joynr.jeeintegration.api.ServiceProvider) Any(javax.enterprise.inject.Any) Bean(javax.enterprise.inject.spi.Bean) HashSet(java.util.HashSet)

Aggregations

ServiceProvider (io.joynr.jeeintegration.api.ServiceProvider)2 ProvidedBy (io.joynr.ProvidedBy)1 ProviderQosFactory (io.joynr.jeeintegration.api.ProviderQosFactory)1 HashSet (java.util.HashSet)1 Any (javax.enterprise.inject.Any)1 Bean (javax.enterprise.inject.spi.Bean)1 ProviderQos (joynr.types.ProviderQos)1