void addDependency(final String dependencyMBeanName, final Injector<Object> injector) { assertState(); final ServiceName injectedMBeanCreateDestroyServiceName = ServiceNameFactory.newCreateDestroy(dependencyMBeanName); createDestroyServiceBuilder.addDependency(injectedMBeanCreateDestroyServiceName, injector); final ServiceName injectedMBeanStartStopServiceName = ServiceNameFactory.newStartStop(dependencyMBeanName); startStopServiceBuilder.addDependency(injectedMBeanStartStopServiceName); }
/** * @param mBeanName * @param mBeanInstance * @param mBeanClassHierarchy * @param target * @param componentInstantiator * @param duServiceName the deployment unit's service name */ MBeanServices( final String mBeanName, final Object mBeanInstance, final List<ClassReflectionIndex<?>> mBeanClassHierarchy, final ServiceTarget target, ServiceComponentInstantiator componentInstantiator, final ServiceName duServiceName) { if (mBeanClassHierarchy == null) { throw SarMessages.MESSAGES.nullVar("mBeanName"); } if (mBeanInstance == null) { throw SarMessages.MESSAGES.nullVar("mBeanInstance"); } if (target == null) { throw SarMessages.MESSAGES.nullVar("target"); } final Method createMethod = ReflectionUtils.getMethod(mBeanClassHierarchy, CREATE_METHOD_NAME, NO_ARGS, false); final Method destroyMethod = ReflectionUtils.getMethod(mBeanClassHierarchy, DESTROY_METHOD_NAME, NO_ARGS, false); createDestroyService = new CreateDestroyService( mBeanInstance, createMethod, destroyMethod, componentInstantiator, duServiceName); createDestroyServiceName = ServiceNameFactory.newCreateDestroy(mBeanName); createDestroyServiceBuilder = target.addService(createDestroyServiceName, createDestroyService); if (componentInstantiator != null) { // the service that starts the EE component needs to start first createDestroyServiceBuilder.addDependency( componentInstantiator.getComponentStartServiceName()); } final Method startMethod = ReflectionUtils.getMethod(mBeanClassHierarchy, START_METHOD_NAME, NO_ARGS, false); final Method stopMethod = ReflectionUtils.getMethod(mBeanClassHierarchy, STOP_METHOD_NAME, NO_ARGS, false); startStopService = new StartStopService(mBeanInstance, startMethod, stopMethod, duServiceName); startStopServiceName = ServiceNameFactory.newStartStop(mBeanName); startStopServiceBuilder = target.addService(startStopServiceName, startStopService); startStopServiceBuilder.addDependency(createDestroyServiceName); this.mBeanName = mBeanName; this.target = target; this.duServiceName = duServiceName; }