/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
23package org.jboss.as.messaging;
24
25import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.ADD;
26import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP;
27import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP_ADDR;
28import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.PATH;
29import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.RELATIVE_TO;
30import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.REMOVE;
31
32import java.util.EnumSet;
33
34import org.jboss.as.controller.AttributeDefinition;
35import org.jboss.as.controller.OperationContext;
36import org.jboss.as.controller.OperationFailedException;
37import org.jboss.as.controller.OperationStepHandler;
38import org.jboss.as.controller.PathAddress;
39import org.jboss.as.controller.ReloadRequiredWriteAttributeHandler;
40import org.jboss.as.controller.descriptions.ModelDescriptionConstants;
41import org.jboss.as.controller.registry.AttributeAccess;
42import org.jboss.as.controller.registry.ManagementResourceRegistration;
43import org.jboss.as.controller.registry.Resource;
44import org.jboss.dmr.ModelNode;
45import org.jboss.msc.service.ServiceController;
46import org.jboss.msc.service.ServiceName;
47
48
49/**
50 * @author Emanuel Muckenhuber
51 */
52class MessagingPathHandlers {
53
54 static final AttributeDefinition[] ATTRIBUTES = new AttributeDefinition[] { CommonAttributes.PATH, CommonAttributes.RELATIVE_TO };
55 static final OperationStepHandler PATH_ADD = new OperationStepHandler() {
56
57 @Override
58 public void execute(final OperationContext context, final ModelNode operation) throws OperationFailedException {
59 final Resource resource = context.createResource(PathAddress.EMPTY_ADDRESS);
60 final ModelNode model = resource.getModel();
61 for(final AttributeDefinition def : ATTRIBUTES) {
62 def.validateAndSet(operation, model);
63 }
64 reloadRequiredStep(context);
65 context.completeStep();
66 }
67 };
68
69 static final OperationStepHandler PATH_ATTR = new ReloadRequiredWriteAttributeHandler(CommonAttributes.RELATIVE_TO, CommonAttributes.PATH);
70
71 static final OperationStepHandler PATH_REMOVE = new OperationStepHandler() {
72
73 @Override
74 public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
75 final Resource resource = context.removeResource(PathAddress.EMPTY_ADDRESS);
76 reloadRequiredStep(context);
77 context.completeStep();
78 }
79 };
80
81 static void register(final ManagementResourceRegistration registration) {
82 registration.registerOperationHandler(ADD, PATH_ADD, MessagingSubsystemProviders.PATH_ADD);
83 registration.registerOperationHandler(REMOVE, PATH_REMOVE, MessagingSubsystemProviders.PATH_REMOVE);
84 for(final AttributeDefinition def : ATTRIBUTES) {
85 registration.registerReadWriteAttribute(def.getName(), null, PATH_ATTR, EnumSet.of(AttributeAccess.Flag.RESTART_ALL_SERVICES));
86 }
87 }
88
89 static ModelNode createAddOperation(final ModelNode address, final ModelNode subModel) {
90 final ModelNode operation = new ModelNode();
91 operation.get(OP).set(ADD);
92 operation.get(OP_ADDR).set(address);
93 operation.get(RELATIVE_TO).set(subModel.get(RELATIVE_TO));
94 operation.get(PATH).set(subModel.require(PATH));
95 return operation;
96 }
97
98 static void reloadRequiredStep(final OperationContext context) {
99 if(context.isNormalServer()) {
100 context.addStep(new OperationStepHandler() {
101 @Override
102 public void execute(final OperationContext context, final ModelNode operation) throws OperationFailedException {
103 final ServiceName hqServiceName = MessagingServices.getHornetQServiceName(PathAddress.pathAddress(operation.get(ModelDescriptionConstants.OP_ADDR)));
104 final ServiceController<?> controller = context.getServiceRegistry(false).getService(hqServiceName);
105 if(controller != null) {
106 context.reloadRequired();
107 }
108 context.completeStep();
109 }
110 }, OperationContext.Stage.RUNTIME);
111 }
112 }
113
114}