/** * Construct a new instance. * * @param componentName the component name * @param componentClassName the component instance class name * @param moduleDescription the EE module description * @param deploymentUnitServiceName the service name of the DU containing this component */ public ComponentDescription(final String componentName, final String componentClassName, final EEModuleDescription moduleDescription, final ServiceName deploymentUnitServiceName) { this.moduleDescription = moduleDescription; if (componentName == null) { throw EeLogger.ROOT_LOGGER.nullName("component"); } if (componentClassName == null) { throw EeLogger.ROOT_LOGGER.nullVar("componentClassName", "component", componentName); } if (moduleDescription == null) { throw EeLogger.ROOT_LOGGER.nullVar("moduleDescription", "component", componentName); } if (deploymentUnitServiceName == null) { throw EeLogger.ROOT_LOGGER.nullVar("deploymentUnitServiceName", "component", componentName); } serviceName = BasicComponent.serviceNameOf(deploymentUnitServiceName, componentName); this.componentName = componentName; this.componentClassName = componentClassName; configurators.addLast(DEFAULT_COMPONENT_CONFIGURATOR); configurators.addLast(DEFAULT_INTERCEPTOR_CONFIGURATOR); configurators.addLast(DEFAULT_COMPONENT_VIEW_CONFIGURATOR); }
@Override public void done() { super.stop(); }
public ManagedReference initializeInstance(final Object instance) { setupComponent(); return new ManagedReference() { private final ComponentInstance componentInstance = component.createInstance(instance); private boolean destroyed; @Override public synchronized void release() { if (!destroyed) { componentInstance.destroy(); destroyed = true; } } @Override public Object getInstance() { return componentInstance.getInstance(); } }; }
protected void createInterceptors(InterceptorFactoryContext context) { // Create the post-construct interceptors for the ComponentInstance postConstructInterceptor = this.postConstruct.create(context); // create the pre-destroy interceptors preDestroyInterceptor = this.getPreDestroy().create(context); final Map<Method, InterceptorFactory> interceptorFactoryMap = this.getInterceptorFactoryMap(); // This is an identity map. This means that only <b>certain</b> {@code Method} objects will // match - specifically, they must equal the objects provided to the proxy. final IdentityHashMap<Method, Interceptor> interceptorMap = new IdentityHashMap<Method, Interceptor>(); for (Method method : interceptorFactoryMap.keySet()) { interceptorMap.put(method, interceptorFactoryMap.get(method).create(context)); } this.interceptorInstanceMap = interceptorMap; }
waitForComponentStart(); final BasicComponentInstance basicComponentInstance = this.instantiateComponentInstance(preDestroyInterceptor, interceptorInstanceMap, context); if(instance != null) { basicComponentInstance.setInstanceData(BasicComponentInstance.INSTANCE_KEY, instance); componentInstanceCreated(basicComponentInstance);
waitForComponentStart(); final Interceptor componentInstancePostConstructInterceptor = this.getPostConstruct().create(context); final Interceptor componentInstancePreDestroyInterceptor = this.getPreDestroy().create(context); final Map<Method, InterceptorFactory> interceptorFactoryMap = this.getInterceptorFactoryMap(); final BasicComponentInstance basicComponentInstance = this.instantiateComponentInstance(instanceReference, componentInstancePreDestroyInterceptor, interceptorMap, context); componentInstanceCreated(basicComponentInstance, context);
/** * {@inheritDoc} */ public ComponentInstance createInstance() { BasicComponentInstance instance = constructComponentInstance(null, true); return instance; }
@Override public void run() { try { getValue().start(); context.complete(); } catch (Throwable e) { context.failed(new StartException(e)); } } };
/** * Create the component. * * @return the component instance */ protected BasicComponent createComponent() { return new BasicComponent(this); }
/** * {@inheritDoc} */ public final void destroy() { if (doneUpdater.compareAndSet(this, 0, 1)) try { preDestroy(); final Object instance = getInstance(); if (instance != null) { final InterceptorContext interceptorContext = prepareInterceptorContext(); interceptorContext.setTarget(instance); interceptorContext.putPrivateData(InvocationType.class, InvocationType.PRE_DESTROY); preDestroy.processInvocation(interceptorContext); } } catch (Exception e) { ROOT_LOGGER.componentDestroyFailure(e, this); } finally { component.finishDestroy(); } }
waitForComponentStart(); final BasicComponentInstance basicComponentInstance = this.instantiateComponentInstance(preDestroyInterceptor, interceptorInstanceMap, context); if(instance != null) { basicComponentInstance.setInstanceData(BasicComponentInstance.INSTANCE_KEY, instance); componentInstanceCreated(basicComponentInstance);
protected void createInterceptors(InterceptorFactoryContext context) { // Create the post-construct interceptors for the ComponentInstance postConstructInterceptor = this.postConstruct.create(context); // create the pre-destroy interceptors preDestroyInterceptor = this.getPreDestroy().create(context); final Map<Method, InterceptorFactory> interceptorFactoryMap = this.getInterceptorFactoryMap(); // This is an identity map. This means that only <b>certain</b> {@code Method} objects will // match - specifically, they must equal the objects provided to the proxy. final IdentityHashMap<Method, Interceptor> interceptorMap = new IdentityHashMap<Method, Interceptor>(); for (Method method : interceptorFactoryMap.keySet()) { interceptorMap.put(method, interceptorFactoryMap.get(method).create(context)); } this.interceptorInstanceMap = interceptorMap; }
/** * Construct the component instance. Upon return, the object instance should have injections and lifecycle * invocations completed already. * * * @param instance An instance to be wrapped, or null if a new instance should be created * @return the component instance */ protected BasicComponentInstance constructComponentInstance(ManagedReference instance, boolean invokePostConstruct) { return constructComponentInstance(instance, invokePostConstruct, Collections.emptyMap()); }
@Override public void start() { getShutDownInterceptorFactory().start(); super.start(); }
/** * Create the component. * * @return the component instance */ protected BasicComponent createComponent() { return new BasicComponent(this); }
/** * {@inheritDoc} */ public final void destroy() { if (doneUpdater.compareAndSet(this, 0, 1)) try { preDestroy(); final ManagedReference reference = instanceReference.get(); if (reference != null) { final InterceptorContext interceptorContext = prepareInterceptorContext(); interceptorContext.setTarget(reference.getInstance()); interceptorContext.putPrivateData(InvocationType.class, InvocationType.PRE_DESTROY); preDestroy.processInvocation(interceptorContext); } } catch (Exception e) { ROOT_LOGGER.componentDestroyFailure(e, this); } finally { component.finishDestroy(); } }
waitForComponentStart(); final BasicComponentInstance basicComponentInstance = this.instantiateComponentInstance(preDestroyInterceptor, interceptorInstanceMap, context); if(instance != null) { basicComponentInstance.setInstanceData(BasicComponentInstance.INSTANCE_KEY, instance); componentInstanceCreated(basicComponentInstance);
@Override public void run() { try { getValue().stop(); } finally { context.complete(); } } };
private static ServiceName componentServiceName(final OperationContext context, final ModelNode operation) { final PathAddress address = PathAddress.pathAddress(operation.require(ModelDescriptionConstants.OP_ADDR)); final String parent; final String module; int i = 2; if (address.getElement(1).getKey().equals(ModelDescriptionConstants.SUBDEPLOYMENT)) { parent = resolveRuntimeName(context,address.getElement(0)); module = address.getElement(1).getValue(); i++; } else { parent = null; module = resolveRuntimeName(context,address.getElement(0)); } final String component = address.getElement(i).getValue(); final ServiceName deploymentUnitServiceName; if (parent == null) { deploymentUnitServiceName = Services.deploymentUnitName(module); } else { deploymentUnitServiceName = Services.deploymentUnitName(parent, module); } // Hmm, don't like the START bit return BasicComponent.serviceNameOf(deploymentUnitServiceName, component).append("START"); }
protected void createInterceptors(InterceptorFactoryContext context) { // Create the post-construct interceptors for the ComponentInstance postConstructInterceptor = this.postConstruct.create(context); // create the pre-destroy interceptors preDestroyInterceptor = this.getPreDestroy().create(context); final Map<Method, InterceptorFactory> interceptorFactoryMap = this.getInterceptorFactoryMap(); // This is an identity map. This means that only <b>certain</b> {@code Method} objects will // match - specifically, they must equal the objects provided to the proxy. final IdentityHashMap<Method, Interceptor> interceptorMap = new IdentityHashMap<Method, Interceptor>(); for (Method method : interceptorFactoryMap.keySet()) { interceptorMap.put(method, interceptorFactoryMap.get(method).create(context)); } this.interceptorInstanceMap = interceptorMap; }