Search in sources :

Example 1 with RemoteEJBDiscoveryConfigurator

use of org.jboss.ejb.protocol.remote.RemoteEJBDiscoveryConfigurator in project wildfly by wildfly.

the class DiscoveryRegistrationProcessor method deploy.

public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    // we only process top level deployment units
    if (deploymentUnit.getParent() != null) {
        return;
    }
    final ServiceName clientContextName = deploymentUnit.getAttachment(EjbDeploymentAttachmentKeys.EJB_CLIENT_CONTEXT_SERVICE_NAME);
    final ServiceName profileServiceName = deploymentUnit.getAttachment(EjbDeploymentAttachmentKeys.EJB_REMOTING_PROFILE_SERVICE_NAME);
    final DiscoveryService discoveryService = new DiscoveryService();
    final ServiceName discoveryServiceName = DiscoveryService.BASE_NAME.append(deploymentUnit.getName());
    final ServiceBuilder<Discovery> builder = phaseContext.getServiceTarget().addService(discoveryServiceName, discoveryService);
    Injector<DiscoveryProvider> providerInjector = discoveryService.getDiscoveryProviderInjector();
    new RemoteEJBDiscoveryConfigurator().configure(providerInjector::inject, registryProvider -> {
    });
    if (profileServiceName != null)
        builder.addDependency(profileServiceName, RemotingProfileService.class, new Injector<RemotingProfileService>() {

            Injector<DiscoveryProvider> providerInjector = discoveryService.getDiscoveryProviderInjector();

            public void inject(final RemotingProfileService value) throws InjectionException {
                providerInjector.inject(new StaticDiscoveryProvider(value.getServiceUrls()));
            }

            public void uninject() {
                providerInjector.uninject();
            }
        });
    // only add association service dependency if the context is configured to use the local EJB receiver & we are not app client
    final EJBClientDescriptorMetaData ejbClientDescriptorMetaData = deploymentUnit.getAttachment(Attachments.EJB_CLIENT_METADATA);
    final boolean useLocalReceiver = ejbClientDescriptorMetaData == null || ejbClientDescriptorMetaData.isLocalReceiverExcluded() != Boolean.TRUE;
    if (useLocalReceiver && !appClient) {
        builder.addDependency(AssociationService.SERVICE_NAME, AssociationService.class, new Injector<AssociationService>() {

            Injector<DiscoveryProvider> providerInjector = discoveryService.getDiscoveryProviderInjector();

            public void inject(final AssociationService value) throws InjectionException {
                providerInjector.inject(value.getLocalDiscoveryProvider());
            }

            public void uninject() {
                providerInjector.uninject();
            }
        });
    }
    builder.install();
}
Also used : RemoteEJBDiscoveryConfigurator(org.jboss.ejb.protocol.remote.RemoteEJBDiscoveryConfigurator) DiscoveryProvider(org.wildfly.discovery.spi.DiscoveryProvider) StaticDiscoveryProvider(org.wildfly.discovery.impl.StaticDiscoveryProvider) Discovery(org.wildfly.discovery.Discovery) AssociationService(org.jboss.as.ejb3.remote.AssociationService) InjectionException(org.jboss.msc.inject.InjectionException) ServiceName(org.jboss.msc.service.ServiceName) Injector(org.jboss.msc.inject.Injector) EJBClientDescriptorMetaData(org.jboss.as.ee.metadata.EJBClientDescriptorMetaData) StaticDiscoveryProvider(org.wildfly.discovery.impl.StaticDiscoveryProvider) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit) RemotingProfileService(org.jboss.as.ejb3.remote.RemotingProfileService)

Aggregations

EJBClientDescriptorMetaData (org.jboss.as.ee.metadata.EJBClientDescriptorMetaData)1 AssociationService (org.jboss.as.ejb3.remote.AssociationService)1 RemotingProfileService (org.jboss.as.ejb3.remote.RemotingProfileService)1 DeploymentUnit (org.jboss.as.server.deployment.DeploymentUnit)1 RemoteEJBDiscoveryConfigurator (org.jboss.ejb.protocol.remote.RemoteEJBDiscoveryConfigurator)1 InjectionException (org.jboss.msc.inject.InjectionException)1 Injector (org.jboss.msc.inject.Injector)1 ServiceName (org.jboss.msc.service.ServiceName)1 Discovery (org.wildfly.discovery.Discovery)1 StaticDiscoveryProvider (org.wildfly.discovery.impl.StaticDiscoveryProvider)1 DiscoveryProvider (org.wildfly.discovery.spi.DiscoveryProvider)1