PageRenderTime 44ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/jboss-as-7.1.1.Final/messaging/src/main/java/org/jboss/as/messaging/MessagingPathHandlers.java

#
Java | 114 lines | 75 code | 15 blank | 24 comment | 5 complexity | e77bf96050b4e2efb50d5fe4b364910c MD5 | raw file
Possible License(s): LGPL-2.1, Apache-2.0
  1. /*
  2. * JBoss, Home of Professional Open Source.
  3. * Copyright 2011, Red Hat, Inc., and individual contributors
  4. * as indicated by the @author tags. See the copyright.txt file in the
  5. * distribution for a full listing of individual contributors.
  6. *
  7. * This is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU Lesser General Public License as
  9. * published by the Free Software Foundation; either version 2.1 of
  10. * the License, or (at your option) any later version.
  11. *
  12. * This software is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with this software; if not, write to the Free
  19. * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  20. * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  21. */
  22. package org.jboss.as.messaging;
  23. import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.ADD;
  24. import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP;
  25. import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP_ADDR;
  26. import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.PATH;
  27. import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.RELATIVE_TO;
  28. import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.REMOVE;
  29. import java.util.EnumSet;
  30. import org.jboss.as.controller.AttributeDefinition;
  31. import org.jboss.as.controller.OperationContext;
  32. import org.jboss.as.controller.OperationFailedException;
  33. import org.jboss.as.controller.OperationStepHandler;
  34. import org.jboss.as.controller.PathAddress;
  35. import org.jboss.as.controller.ReloadRequiredWriteAttributeHandler;
  36. import org.jboss.as.controller.descriptions.ModelDescriptionConstants;
  37. import org.jboss.as.controller.registry.AttributeAccess;
  38. import org.jboss.as.controller.registry.ManagementResourceRegistration;
  39. import org.jboss.as.controller.registry.Resource;
  40. import org.jboss.dmr.ModelNode;
  41. import org.jboss.msc.service.ServiceController;
  42. import org.jboss.msc.service.ServiceName;
  43. /**
  44. * @author Emanuel Muckenhuber
  45. */
  46. class MessagingPathHandlers {
  47. static final AttributeDefinition[] ATTRIBUTES = new AttributeDefinition[] { CommonAttributes.PATH, CommonAttributes.RELATIVE_TO };
  48. static final OperationStepHandler PATH_ADD = new OperationStepHandler() {
  49. @Override
  50. public void execute(final OperationContext context, final ModelNode operation) throws OperationFailedException {
  51. final Resource resource = context.createResource(PathAddress.EMPTY_ADDRESS);
  52. final ModelNode model = resource.getModel();
  53. for(final AttributeDefinition def : ATTRIBUTES) {
  54. def.validateAndSet(operation, model);
  55. }
  56. reloadRequiredStep(context);
  57. context.completeStep();
  58. }
  59. };
  60. static final OperationStepHandler PATH_ATTR = new ReloadRequiredWriteAttributeHandler(CommonAttributes.RELATIVE_TO, CommonAttributes.PATH);
  61. static final OperationStepHandler PATH_REMOVE = new OperationStepHandler() {
  62. @Override
  63. public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
  64. final Resource resource = context.removeResource(PathAddress.EMPTY_ADDRESS);
  65. reloadRequiredStep(context);
  66. context.completeStep();
  67. }
  68. };
  69. static void register(final ManagementResourceRegistration registration) {
  70. registration.registerOperationHandler(ADD, PATH_ADD, MessagingSubsystemProviders.PATH_ADD);
  71. registration.registerOperationHandler(REMOVE, PATH_REMOVE, MessagingSubsystemProviders.PATH_REMOVE);
  72. for(final AttributeDefinition def : ATTRIBUTES) {
  73. registration.registerReadWriteAttribute(def.getName(), null, PATH_ATTR, EnumSet.of(AttributeAccess.Flag.RESTART_ALL_SERVICES));
  74. }
  75. }
  76. static ModelNode createAddOperation(final ModelNode address, final ModelNode subModel) {
  77. final ModelNode operation = new ModelNode();
  78. operation.get(OP).set(ADD);
  79. operation.get(OP_ADDR).set(address);
  80. operation.get(RELATIVE_TO).set(subModel.get(RELATIVE_TO));
  81. operation.get(PATH).set(subModel.require(PATH));
  82. return operation;
  83. }
  84. static void reloadRequiredStep(final OperationContext context) {
  85. if(context.isNormalServer()) {
  86. context.addStep(new OperationStepHandler() {
  87. @Override
  88. public void execute(final OperationContext context, final ModelNode operation) throws OperationFailedException {
  89. final ServiceName hqServiceName = MessagingServices.getHornetQServiceName(PathAddress.pathAddress(operation.get(ModelDescriptionConstants.OP_ADDR)));
  90. final ServiceController<?> controller = context.getServiceRegistry(false).getService(hqServiceName);
  91. if(controller != null) {
  92. context.reloadRequired();
  93. }
  94. context.completeStep();
  95. }
  96. }, OperationContext.Stage.RUNTIME);
  97. }
  98. }
  99. }