public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
DeploymentUnit unit = phaseContext.getDeploymentUnit();
if (DeploymentUtils.isUnitRootless( unit )) {
return;
}
final RubyAppMetaData rubyAppMetaData = unit.getAttachment( RubyAppMetaData.ATTACHMENT_KEY );
if ( rubyAppMetaData == null ) {
return;
}
String mbeanName = ObjectNameFactory.create( "torquebox.apps", new Hashtable<String, String>() {
{
put( "name", rubyAppMetaData.getApplicationName() );
}
} ).toString();
ServiceName serviceName = unit.getServiceName();
RubyApplication application = new RubyApplication();
application.setEnvironmentName( rubyAppMetaData.getEnvironmentName() );
application.setRootPath( rubyAppMetaData.getRoot().getAbsolutePath() );
application.setName( rubyAppMetaData.getApplicationName() );
ServiceName mbeanServiceName = serviceName.append( "mbean" );
MBeanRegistrationService<RubyApplicationMBean> mbeanService = new MBeanRegistrationService<RubyApplicationMBean>( mbeanName, mbeanServiceName, new ImmediateValue<RubyApplicationMBean>( application ) );
phaseContext.getServiceTarget().addService( mbeanServiceName, mbeanService )
.addDependency( DependencyType.OPTIONAL, MBeanServerService.SERVICE_NAME, MBeanServer.class, mbeanService.getMBeanServerInjector() )