Search in sources :

Example 1 with ManagedReference

use of org.jboss.as.naming.ManagedReference in project wildfly by wildfly.

the class WebInjectionContainer method newInstance.

public Object newInstance(Class<?> clazz) throws IllegalAccessException, InvocationTargetException, NamingException, InstantiationException {
    final ManagedReferenceFactory factory = componentRegistry.createInstanceFactory(clazz);
    ManagedReference reference = factory.getReference();
    if (reference != null) {
        instanceMap.put(reference.getInstance(), reference);
        return reference.getInstance();
    }
    return clazz.newInstance();
}
Also used : ManagedReferenceFactory(org.jboss.as.naming.ManagedReferenceFactory) ManagedReference(org.jboss.as.naming.ManagedReference)

Example 2 with ManagedReference

use of org.jboss.as.naming.ManagedReference in project camunda-bpm-platform by camunda.

the class ProcessApplicationDeploymentService method performDeployment.

protected void performDeployment() throws StartException {
    ManagedReference reference = null;
    try {
        // get process engine
        ProcessEngine processEngine = processEngineInjector.getValue();
        // get the process application component
        ProcessApplicationInterface processApplication = null;
        ComponentView componentView = paComponentViewInjector.getOptionalValue();
        if (componentView != null) {
            reference = componentView.createInstance();
            processApplication = (ProcessApplicationInterface) reference.getInstance();
        } else {
            processApplication = noViewProcessApplication.getValue();
        }
        // get the application name
        String processApplicationName = processApplication.getName();
        // build the deployment
        final RepositoryService repositoryService = processEngine.getRepositoryService();
        final ProcessApplicationDeploymentBuilder deploymentBuilder = repositoryService.createDeployment(processApplication.getReference());
        // enable duplicate filtering
        deploymentBuilder.enableDuplicateFiltering(PropertyHelper.getBooleanProperty(processArchive.getProperties(), ProcessArchiveXml.PROP_IS_DEPLOY_CHANGED_ONLY, false));
        // enable resuming of previous versions:
        if (PropertyHelper.getBooleanProperty(processArchive.getProperties(), ProcessArchiveXml.PROP_IS_RESUME_PREVIOUS_VERSIONS, true)) {
            enableResumingOfPreviousVersions(deploymentBuilder);
        }
        // set the name for the deployment
        String deploymentName = processArchive.getName();
        if (deploymentName == null || deploymentName.isEmpty()) {
            deploymentName = processApplicationName;
        }
        deploymentBuilder.name(deploymentName);
        // set the tenant id for the deployment
        String tenantId = processArchive.getTenantId();
        if (tenantId != null && !tenantId.isEmpty()) {
            deploymentBuilder.tenantId(tenantId);
        }
        // add deployment resources
        for (Entry<String, byte[]> resource : deploymentMap.entrySet()) {
            deploymentBuilder.addInputStream(resource.getKey(), new ByteArrayInputStream(resource.getValue()));
        }
        // let the process application component add resources to the deployment.
        processApplication.createDeployment(processArchive.getName(), deploymentBuilder);
        Collection<String> resourceNames = deploymentBuilder.getResourceNames();
        if (!resourceNames.isEmpty()) {
            logDeploymentSummary(resourceNames, deploymentName, processApplicationName);
            // perform the actual deployment
            deployment = Tccl.runUnderClassloader(new Tccl.Operation<ProcessApplicationDeployment>() {

                public ProcessApplicationDeployment run() {
                    return deploymentBuilder.deploy();
                }
            }, module.getClassLoader());
        } else {
            LOGGER.info("Not creating a deployment for process archive '" + processArchive.getName() + "': no resources provided.");
        }
    } catch (Exception e) {
        throw new StartException("Could not register process application with shared process engine ", e);
    } finally {
        if (reference != null) {
            reference.release();
        }
    }
}
Also used : ManagedReference(org.jboss.as.naming.ManagedReference) ProcessApplicationInterface(org.camunda.bpm.application.ProcessApplicationInterface) StartException(org.jboss.msc.service.StartException) ProcessApplicationDeploymentBuilder(org.camunda.bpm.engine.repository.ProcessApplicationDeploymentBuilder) ComponentView(org.jboss.as.ee.component.ComponentView) ByteArrayInputStream(java.io.ByteArrayInputStream) StartException(org.jboss.msc.service.StartException) ProcessEngine(org.camunda.bpm.engine.ProcessEngine) RepositoryService(org.camunda.bpm.engine.RepositoryService)

Example 3 with ManagedReference

use of org.jboss.as.naming.ManagedReference in project camunda-bpm-platform by camunda.

the class ProcessApplicationStartService method start.

@Override
public void start(StartContext context) throws StartException {
    ManagedReference reference = null;
    try {
        // get the process application component
        ProcessApplicationInterface processApplication = null;
        ComponentView componentView = paComponentViewInjector.getOptionalValue();
        if (componentView != null) {
            reference = componentView.createInstance();
            processApplication = (ProcessApplicationInterface) reference.getInstance();
        } else {
            processApplication = noViewProcessApplication.getValue();
        }
        // create & populate the process application info object
        processApplicationInfo = new ProcessApplicationInfoImpl();
        processApplicationInfo.setName(processApplication.getName());
        processApplicationInfo.setProperties(processApplication.getProperties());
        referencedProcessEngines = new HashSet<ProcessEngine>();
        List<ProcessApplicationDeploymentInfo> deploymentInfos = new ArrayList<ProcessApplicationDeploymentInfo>();
        for (ServiceName deploymentServiceName : deploymentServiceNames) {
            ProcessApplicationDeploymentService value = getDeploymentService(context, deploymentServiceName);
            referencedProcessEngines.add(value.getProcessEngineInjector().getValue());
            ProcessApplicationDeployment deployment = value.getDeployment();
            if (deployment != null) {
                for (String deploymentId : deployment.getProcessApplicationRegistration().getDeploymentIds()) {
                    ProcessApplicationDeploymentInfoImpl deploymentInfo = new ProcessApplicationDeploymentInfoImpl();
                    deploymentInfo.setDeploymentId(deploymentId);
                    deploymentInfo.setProcessEngineName(value.getProcessEngineName());
                    deploymentInfos.add(deploymentInfo);
                }
            }
        }
        processApplicationInfo.setDeploymentInfo(deploymentInfos);
        notifyBpmPlatformPlugins(platformPluginsInjector.getValue(), processApplication);
        if (postDeployDescription != null) {
            invokePostDeploy(processApplication);
        }
        // install the ManagedProcessApplication Service as a child to this service
        // if this service stops (at undeployment) the ManagedProcessApplication service is removed as well.
        ServiceName serviceName = ServiceNames.forManagedProcessApplication(processApplicationInfo.getName());
        MscManagedProcessApplication managedProcessApplication = new MscManagedProcessApplication(processApplicationInfo, processApplication.getReference());
        context.getChildTarget().addService(serviceName, managedProcessApplication).install();
    } catch (StartException e) {
        throw e;
    } catch (Exception e) {
        throw new StartException(e);
    } finally {
        if (reference != null) {
            reference.release();
        }
    }
}
Also used : ProcessApplicationDeploymentInfoImpl(org.camunda.bpm.application.impl.ProcessApplicationDeploymentInfoImpl) ProcessApplicationDeploymentInfo(org.camunda.bpm.application.ProcessApplicationDeploymentInfo) ProcessApplicationInfoImpl(org.camunda.bpm.application.impl.ProcessApplicationInfoImpl) ArrayList(java.util.ArrayList) ManagedReference(org.jboss.as.naming.ManagedReference) ProcessApplicationInterface(org.camunda.bpm.application.ProcessApplicationInterface) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException) StartException(org.jboss.msc.service.StartException) ProcessApplicationDeployment(org.camunda.bpm.engine.repository.ProcessApplicationDeployment) ComponentView(org.jboss.as.ee.component.ComponentView) ServiceName(org.jboss.msc.service.ServiceName) StartException(org.jboss.msc.service.StartException) ProcessEngine(org.camunda.bpm.engine.ProcessEngine)

Example 4 with ManagedReference

use of org.jboss.as.naming.ManagedReference in project camunda-bpm-platform by camunda.

the class ProcessApplicationStartService method stop.

@Override
public void stop(StopContext context) {
    ManagedReference reference = null;
    try {
        // get the process application component
        ProcessApplicationInterface processApplication = null;
        ComponentView componentView = paComponentViewInjector.getOptionalValue();
        if (componentView != null) {
            reference = componentView.createInstance();
            processApplication = (ProcessApplicationInterface) reference.getInstance();
        } else {
            processApplication = noViewProcessApplication.getValue();
        }
        invokePreUndeploy(processApplication);
    } catch (Exception e) {
        LOGGER.log(Level.SEVERE, "Exception while stopping process application", e);
    } finally {
        if (reference != null) {
            reference.release();
        }
    }
}
Also used : ComponentView(org.jboss.as.ee.component.ComponentView) ManagedReference(org.jboss.as.naming.ManagedReference) ProcessApplicationInterface(org.camunda.bpm.application.ProcessApplicationInterface) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException) StartException(org.jboss.msc.service.StartException)

Example 5 with ManagedReference

use of org.jboss.as.naming.ManagedReference in project wildfly by wildfly.

the class LookupInjectionSource method getResourceValue.

/**
 * {@inheritDoc}
 */
public void getResourceValue(final ResolutionContext resolutionContext, final ServiceBuilder<?> serviceBuilder, final DeploymentPhaseContext phaseContext, final Injector<ManagedReferenceFactory> injector) {
    final String applicationName = resolutionContext.getApplicationName();
    final String moduleName = resolutionContext.getModuleName();
    final String componentName = resolutionContext.getComponentName();
    final boolean compUsesModule = resolutionContext.isCompUsesModule();
    final String scheme = org.jboss.as.naming.InitialContext.getURLScheme(lookupName);
    if (scheme == null) {
        String sanitizedLookupName = sanitizeLookupName(lookupName);
        // relative name, build absolute name and setup normal lookup injection
        if (componentName != null && !compUsesModule) {
            ContextNames.bindInfoFor(applicationName, moduleName, componentName, "java:comp/env/" + sanitizedLookupName).setupLookupInjection(serviceBuilder, injector, phaseContext.getDeploymentUnit(), optional);
        } else if (compUsesModule) {
            ContextNames.bindInfoFor(applicationName, moduleName, componentName, "java:module/env/" + sanitizedLookupName).setupLookupInjection(serviceBuilder, injector, phaseContext.getDeploymentUnit(), optional);
        } else {
            ContextNames.bindInfoFor(applicationName, moduleName, componentName, "java:jboss/env/" + sanitizedLookupName).setupLookupInjection(serviceBuilder, injector, phaseContext.getDeploymentUnit(), optional);
        }
    } else {
        if (scheme.equals("java")) {
            // an absolute java name, setup normal lookup injection
            if (compUsesModule && lookupName.startsWith("java:comp/")) {
                // switch "comp" with "module"
                ContextNames.bindInfoFor(applicationName, moduleName, componentName, "java:module/" + lookupName.substring(10)).setupLookupInjection(serviceBuilder, injector, phaseContext.getDeploymentUnit(), optional);
            } else {
                ContextNames.bindInfoFor(applicationName, moduleName, componentName, lookupName).setupLookupInjection(serviceBuilder, injector, phaseContext.getDeploymentUnit(), optional);
            }
        } else {
            // an absolute non java name
            final ManagedReferenceFactory managedReferenceFactory;
            if (URL_SCHEMES.contains(scheme)) {
                // a Jakarta EE Standard Resource Manager Connection Factory for URLs, using lookup to define value of URL, inject factory that creates URL instances
                managedReferenceFactory = new ManagedReferenceFactory() {

                    @Override
                    public ManagedReference getReference() {
                        try {
                            return new ImmediateManagedReference(new URL(lookupName));
                        } catch (MalformedURLException e) {
                            throw new RuntimeException(e);
                        }
                    }
                };
            } else {
                // lookup for a non java jndi resource, inject factory which does a true jndi lookup
                managedReferenceFactory = new ManagedReferenceFactory() {

                    @Override
                    public ManagedReference getReference() {
                        try {
                            return new ImmediateManagedReference(new InitialContext().lookup(lookupName));
                        } catch (NamingException e) {
                            EeLogger.ROOT_LOGGER.tracef(e, "failed to lookup %s", lookupName);
                            return null;
                        }
                    }
                };
            }
            injector.inject(managedReferenceFactory);
        }
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) ManagedReferenceFactory(org.jboss.as.naming.ManagedReferenceFactory) ImmediateManagedReference(org.jboss.as.naming.ImmediateManagedReference) ManagedReference(org.jboss.as.naming.ManagedReference) NamingException(javax.naming.NamingException) ImmediateManagedReference(org.jboss.as.naming.ImmediateManagedReference) URL(java.net.URL) InitialContext(javax.naming.InitialContext)

Aggregations

ManagedReference (org.jboss.as.naming.ManagedReference)33 ComponentView (org.jboss.as.ee.component.ComponentView)11 ManagedReferenceFactory (org.jboss.as.naming.ManagedReferenceFactory)9 NamingException (javax.naming.NamingException)4 ProcessApplicationInterface (org.camunda.bpm.application.ProcessApplicationInterface)4 ImmediateManagedReference (org.jboss.as.naming.ImmediateManagedReference)4 InterceptorContext (org.jboss.invocation.InterceptorContext)4 Method (java.lang.reflect.Method)3 MalformedURLException (java.net.MalformedURLException)3 ComponentInstance (org.jboss.as.ee.component.ComponentInstance)3 StartException (org.jboss.msc.service.StartException)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 URL (java.net.URL)2 ArrayList (java.util.ArrayList)2 InitialContext (javax.naming.InitialContext)2 ProcessEngine (org.camunda.bpm.engine.ProcessEngine)2 ProcessEngineException (org.camunda.bpm.engine.ProcessEngineException)2 BindingConfiguration (org.jboss.as.ee.component.BindingConfiguration)2 Component (org.jboss.as.ee.component.Component)2 ComponentConfiguration (org.jboss.as.ee.component.ComponentConfiguration)2