-
Notifications
You must be signed in to change notification settings - Fork 2.2k
/
MessagingSubsystemRootResourceDefinition.java
151 lines (132 loc) · 8.39 KB
/
MessagingSubsystemRootResourceDefinition.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/*
* JBoss, Home of Professional Open Source.
* Copyright 2011, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.extension.messaging.activemq;
import static org.jboss.as.controller.SimpleAttributeDefinitionBuilder.create;
import static org.jboss.as.controller.transform.description.RejectAttributeChecker.DEFINED;
import static org.jboss.dmr.ModelType.INT;
import java.util.Arrays;
import java.util.Collection;
import org.apache.activemq.artemis.api.core.client.ActiveMQClient;
import org.jboss.as.controller.AttributeDefinition;
import org.jboss.as.controller.PersistentResourceDefinition;
import org.jboss.as.controller.ReloadRequiredRemoveStepHandler;
import org.jboss.as.controller.SimpleAttributeDefinition;
import org.jboss.as.controller.SubsystemRegistration;
import org.jboss.as.controller.transform.description.AttributeConverter.DefaultValueAttributeConverter;
import org.jboss.as.controller.transform.description.DiscardAttributeChecker;
import org.jboss.as.controller.transform.description.ResourceTransformationDescriptionBuilder;
import org.jboss.as.controller.transform.description.TransformationDescription;
import org.jboss.as.controller.transform.description.TransformationDescriptionBuilder;
import org.jboss.dmr.ModelNode;
import org.wildfly.extension.messaging.activemq.jms.ConnectionFactoryAttributes;
/**
* {@link org.jboss.as.controller.ResourceDefinition} for the messaging subsystem root resource.
*
* @author Brian Stansberry (c) 2011 Red Hat Inc.
*/
public class MessagingSubsystemRootResourceDefinition extends PersistentResourceDefinition {
public static final SimpleAttributeDefinition GLOBAL_CLIENT_THREAD_POOL_MAX_SIZE = create("global-client-thread-pool-max-size", INT)
.setAttributeGroup("global-client")
.setXmlName("thread-pool-max-size")
.setAllowNull(true)
.setDefaultValue(new ModelNode(ActiveMQClient.DEFAULT_THREAD_POOL_MAX_SIZE))
.setAllowExpression(true)
.setRestartAllServices()
.build();
public static final SimpleAttributeDefinition GLOBAL_CLIENT_SCHEDULED_THREAD_POOL_MAX_SIZE = create("global-client-scheduled-thread-pool-max-size", INT)
.setAttributeGroup("global-client")
.setXmlName("scheduled-thread-pool-max-size")
.setAllowNull(true)
.setDefaultValue(new ModelNode(ActiveMQClient.DEFAULT_SCHEDULED_THREAD_POOL_MAX_SIZE))
.setAllowExpression(true)
.setRestartAllServices()
.build();
public static final AttributeDefinition[] ATTRIBUTES = {
GLOBAL_CLIENT_THREAD_POOL_MAX_SIZE,
GLOBAL_CLIENT_SCHEDULED_THREAD_POOL_MAX_SIZE
};
public static final MessagingSubsystemRootResourceDefinition INSTANCE = new MessagingSubsystemRootResourceDefinition();
private MessagingSubsystemRootResourceDefinition() {
super(MessagingExtension.SUBSYSTEM_PATH,
MessagingExtension.getResourceDescriptionResolver(MessagingExtension.SUBSYSTEM_NAME),
MessagingSubsystemAdd.INSTANCE,
ReloadRequiredRemoveStepHandler.INSTANCE);
}
@Override
public Collection<AttributeDefinition> getAttributes() {
return Arrays.asList(ATTRIBUTES);
}
public static void registerTransformers(SubsystemRegistration subsystemRegistration) {
registerTransformers_EAP_7_0_0(subsystemRegistration);
}
private static void registerTransformers_EAP_7_0_0(SubsystemRegistration subsystemRegistration) {
final ResourceTransformationDescriptionBuilder subsystem = TransformationDescriptionBuilder.Factory.createSubsystemInstance();
rejectDefinedAttributeWithDefaultValue(subsystem, MessagingSubsystemRootResourceDefinition.GLOBAL_CLIENT_THREAD_POOL_MAX_SIZE,
MessagingSubsystemRootResourceDefinition.GLOBAL_CLIENT_SCHEDULED_THREAD_POOL_MAX_SIZE);
ResourceTransformationDescriptionBuilder server = subsystem.addChildResource(MessagingExtension.SERVER_PATH);
// reject journal-datasource, journal-bindings-table introduced in management version 2.0.0 if it is defined and different from the default value.
rejectDefinedAttributeWithDefaultValue(server, ServerDefinition.JOURNAL_DATASOURCE,
ServerDefinition.JOURNAL_MESSAGES_TABLE,
ServerDefinition.JOURNAL_BINDINGS_TABLE,
ServerDefinition.JOURNAL_LARGE_MESSAGES_TABLE,
ServerDefinition.JOURNAL_SQL_PROVIDER_FACTORY);
ResourceTransformationDescriptionBuilder bridge = server.addChildResource(MessagingExtension.BRIDGE_PATH);
// reject producer-window-size introduced in management version 2.0.0 if it is defined and different from the default value.
rejectDefinedAttributeWithDefaultValue(bridge, BridgeDefinition.PRODUCER_WINDOW_SIZE);
ResourceTransformationDescriptionBuilder clusterConnection = server.addChildResource(MessagingExtension.CLUSTER_CONNECTION_PATH);
// reject producer-window-size introduced in management version 2.0.0 if it is defined and different from the default value.
rejectDefinedAttributeWithDefaultValue(clusterConnection, ClusterConnectionDefinition.PRODUCER_WINDOW_SIZE);
ResourceTransformationDescriptionBuilder pooledConnectionFactory = server.addChildResource(MessagingExtension.POOLED_CONNECTION_FACTORY_PATH);
// reject rebalance-connections introduced in management version 2.0.0 if it is defined and different from the default value.
rejectDefinedAttributeWithDefaultValue(pooledConnectionFactory, ConnectionFactoryAttributes.Pooled.REBALANCE_CONNECTIONS);
// reject statistics-enabled introduced in management version 2.0.0 if it is defined and different from the default value.
rejectDefinedAttributeWithDefaultValue(pooledConnectionFactory, ConnectionFactoryAttributes.Pooled.STATISTICS_ENABLED);
// reject max-pool-size whose default value has been changed in management version 2.0.0
defaultValueAttributeConverter(pooledConnectionFactory, ConnectionFactoryAttributes.Pooled.MAX_POOL_SIZE);
// reject min-pool-size whose default value has been changed in management version 2.0.0
defaultValueAttributeConverter(pooledConnectionFactory, ConnectionFactoryAttributes.Pooled.MIN_POOL_SIZE);
TransformationDescription.Tools.register(subsystem.build(), subsystemRegistration, MessagingExtension.VERSION_1_0_0);
}
/**
* Reject the attributes if they are defined or discard them if they are undefined or set to their default value.
*/
private static void rejectDefinedAttributeWithDefaultValue(ResourceTransformationDescriptionBuilder builder, AttributeDefinition... attrs) {
for (AttributeDefinition attr : attrs) {
builder.getAttributeBuilder()
.setDiscard(new DiscardAttributeChecker.DiscardAttributeValueChecker(attr.getDefaultValue()), attr)
.addRejectCheck(DEFINED, attr);
}
}
/**
* Reject the attributes if they are defined.
*/
private static void rejectDefinedAttribute(ResourceTransformationDescriptionBuilder builder, AttributeDefinition... attrs) {
for (AttributeDefinition attr : attrs) {
builder.getAttributeBuilder()
.addRejectCheck(DEFINED, attr);
}
}
private static void defaultValueAttributeConverter(ResourceTransformationDescriptionBuilder builder, AttributeDefinition attr) {
builder.getAttributeBuilder()
.setValueConverter(new DefaultValueAttributeConverter(attr), attr);
}
}