PageRenderTime 48ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

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

#
Java | 100 lines | 63 code | 12 blank | 25 comment | 9 complexity | f972e41ac32770f60d177d2f3ed6af39 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 org.jboss.as.controller.AbstractWriteAttributeHandler;
  24. import java.util.EnumSet;
  25. import org.hornetq.core.server.HornetQServer;
  26. import org.hornetq.core.settings.HierarchicalRepository;
  27. import org.hornetq.core.settings.impl.AddressSettings;
  28. import org.jboss.as.controller.AttributeDefinition;
  29. import org.jboss.as.controller.OperationContext;
  30. import org.jboss.as.controller.OperationFailedException;
  31. import org.jboss.as.controller.PathAddress;
  32. import org.jboss.as.controller.descriptions.ModelDescriptionConstants;
  33. import org.jboss.as.controller.registry.AttributeAccess;
  34. import org.jboss.as.controller.registry.ManagementResourceRegistration;
  35. import org.jboss.as.controller.registry.Resource;
  36. import org.jboss.dmr.ModelNode;
  37. /**
  38. * @author Emanuel Muckenhuber
  39. */
  40. class AddressSettingsWriteHandler extends AbstractWriteAttributeHandler<AddressSettingsWriteHandler.RevertHandback> {
  41. static final AddressSettingsWriteHandler INSTANCE = new AddressSettingsWriteHandler();
  42. public void registerAttributes(final ManagementResourceRegistration registry, boolean registerRuntimeOnly) {
  43. final EnumSet<AttributeAccess.Flag> flags = EnumSet.of(AttributeAccess.Flag.RESTART_NONE);
  44. for (AttributeDefinition attr : AddressSettingAdd.ATTRIBUTES) {
  45. if (registerRuntimeOnly || !attr.getFlags().contains(AttributeAccess.Flag.STORAGE_RUNTIME)) {
  46. registry.registerReadWriteAttribute(attr.getName(), null, this, flags);
  47. }
  48. }
  49. }
  50. protected AddressSettingsWriteHandler() {
  51. super(AddressSettingAdd.ATTRIBUTES);
  52. }
  53. @Override
  54. protected boolean applyUpdateToRuntime(final OperationContext context, final ModelNode operation, final String attributeName, final ModelNode resolvedValue,
  55. final ModelNode currentValue, final HandbackHolder<RevertHandback> handbackHolder) throws OperationFailedException {
  56. final Resource resource = context.readResourceForUpdate(PathAddress.EMPTY_ADDRESS);
  57. final HornetQServer server = AddressSettingAdd.getServer(context, operation);
  58. if(server != null) {
  59. final ModelNode model = resource.getModel();
  60. final PathAddress address = PathAddress.pathAddress(operation.require(ModelDescriptionConstants.OP_ADDR));
  61. final AddressSettings settings = AddressSettingAdd.createSettings(context, model);
  62. final HierarchicalRepository<AddressSettings> repository = server.getAddressSettingsRepository();
  63. final String match = address.getLastElement().getValue();
  64. final AddressSettings existingSettings = repository.getMatch(match);
  65. repository.addMatch(match, settings);
  66. if(existingSettings != null) {
  67. handbackHolder.setHandback(new RevertHandback() {
  68. @Override
  69. public void doRevertUpdateToRuntime() {
  70. // Restore the old settings
  71. repository.addMatch(address.getLastElement().getValue(), existingSettings);
  72. }
  73. });
  74. }
  75. }
  76. return false;
  77. }
  78. @Override
  79. protected void revertUpdateToRuntime(final OperationContext context, final ModelNode operation, final String attributeName, final ModelNode valueToRestore,
  80. final ModelNode valueToRevert, final RevertHandback handback) throws OperationFailedException {
  81. if(handback != null) {
  82. handback.doRevertUpdateToRuntime();
  83. }
  84. }
  85. static interface RevertHandback {
  86. void doRevertUpdateToRuntime();
  87. }
  88. }