// Add a RUNTIME step to actually install the HQ Service. This will execute after the runtime step
// added by any child resources whose ADD handler executes after this one in the model stage.
context.addStep(new OperationStepHandler() {
@Override
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
final ServiceTarget serviceTarget = context.getServiceTarget();
final String serverName = PathAddress.pathAddress(operation.require(OP_ADDR)).getLastElement().getValue();
// Transform the configuration based on the recursive model
final ModelNode model = Resource.Tools.readModel(resource);
final Configuration configuration = transformConfig(context, serverName, model);
// Create path services
final ServiceName bindingsPath = createDirectoryService(DEFAULT_BINDINGS_DIR, model.get(PATH, BINDINGS_DIRECTORY), serviceTarget, operation, newControllers, verificationHandler);
final ServiceName journalPath = createDirectoryService(DEFAULT_JOURNAL_DIR, model.get(PATH, JOURNAL_DIRECTORY), serviceTarget, operation, newControllers, verificationHandler);
final ServiceName largeMessagePath = createDirectoryService(DEFAULT_LARGE_MESSAGE_DIR, model.get(PATH, LARGE_MESSAGES_DIRECTORY), serviceTarget, operation, newControllers, verificationHandler);
final ServiceName pagingPath = createDirectoryService(DEFAULT_PAGING_DIR, model.get(PATH, PAGING_DIRECTORY), serviceTarget, operation, newControllers, verificationHandler);
// Create the HornetQ Service
final HornetQService hqService = new HornetQService();
hqService.setConfiguration(configuration);
// Add the HornetQ Service
ServiceName hqServiceName = MessagingServices.getHornetQServiceName(serverName);
final ServiceBuilder<HornetQServer> serviceBuilder = serviceTarget.addService(hqServiceName, hqService)
.addDependency(DependencyType.OPTIONAL, ServiceName.JBOSS.append("mbean", "server"), MBeanServer.class, hqService.getMBeanServer());
serviceBuilder.addDependency(bindingsPath, String.class, hqService.getPathInjector(DEFAULT_BINDINGS_DIR));
serviceBuilder.addDependency(journalPath, String.class, hqService.getPathInjector(DEFAULT_JOURNAL_DIR));
serviceBuilder.addDependency(largeMessagePath, String.class, hqService.getPathInjector(DEFAULT_LARGE_MESSAGE_DIR));