/
TransactionSubsystemRootResourceDefinition.java
650 lines (553 loc) · 37 KB
/
TransactionSubsystemRootResourceDefinition.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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
/*
* JBoss, Home of Professional Open Source.
* Copyright 2020, 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.jboss.as.txn.subsystem;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashSet;
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;
import javax.transaction.TransactionSynchronizationRegistry;
import org.jboss.as.controller.AbstractWriteAttributeHandler;
import org.jboss.as.controller.AttributeDefinition;
import org.jboss.as.controller.ModelVersion;
import org.jboss.as.controller.OperationContext;
import org.jboss.as.controller.OperationFailedException;
import org.jboss.as.controller.OperationStepHandler;
import org.jboss.as.controller.PathAddress;
import org.jboss.as.controller.ReloadRequiredWriteAttributeHandler;
import org.jboss.as.controller.SimpleAttributeDefinition;
import org.jboss.as.controller.SimpleAttributeDefinitionBuilder;
import org.jboss.as.controller.SimpleOperationDefinitionBuilder;
import org.jboss.as.controller.SimpleResourceDefinition;
import org.jboss.as.controller.access.management.SensitiveTargetAccessConstraintDefinition;
import org.jboss.as.controller.capability.RuntimeCapability;
import org.jboss.as.controller.client.helpers.MeasurementUnit;
import org.jboss.as.controller.descriptions.ModelDescriptionConstants;
import org.jboss.as.controller.operations.validation.IntRangeValidator;
import org.jboss.as.controller.operations.validation.StringBytesLengthValidator;
import org.jboss.as.controller.operations.validation.StringLengthValidator;
import org.jboss.as.controller.registry.AttributeAccess;
import org.jboss.as.controller.registry.ImmutableManagementResourceRegistration;
import org.jboss.as.controller.registry.ManagementResourceRegistration;
import org.jboss.as.controller.registry.OperationEntry;
import org.jboss.as.controller.registry.Resource;
import org.jboss.as.txn.logging.TransactionLogger;
import org.jboss.dmr.ModelNode;
import org.jboss.dmr.ModelType;
import org.jboss.tm.XAResourceRecoveryRegistry;
import org.wildfly.transaction.client.ContextTransactionManager;
import com.arjuna.ats.arjuna.common.CoordinatorEnvironmentBean;
import com.arjuna.ats.arjuna.common.arjPropertyManager;
import com.arjuna.ats.arjuna.coordinator.TxControl;
import org.wildfly.transaction.client.provider.remoting.RemotingTransactionService;
/**
* {@link org.jboss.as.controller.ResourceDefinition} for the root resource of the transaction subsystem.
*
* @author Brian Stansberry (c) 2011 Red Hat Inc.
*/
public class TransactionSubsystemRootResourceDefinition extends SimpleResourceDefinition {
static final RuntimeCapability<Void> TRANSACTION_CAPABILITY = RuntimeCapability.Builder.of("org.wildfly.transactions")
.build();
/** Capability that indicates a local TransactionManager provider is present. */
public static final RuntimeCapability<Void> LOCAL_PROVIDER_CAPABILITY = RuntimeCapability.Builder.of("org.wildfly.transactions.global-default-local-provider", Void.class)
.build();
/**
* Provides access to the special TransactionSynchronizationRegistry impl that ensures proper ordering between
* Jakarta Connectors and other synchronizations.
*/
public static final RuntimeCapability<Void> TRANSACTION_SYNCHRONIZATION_REGISTRY_CAPABILITY =
RuntimeCapability.Builder.of("org.wildfly.transactions.transaction-synchronization-registry", TransactionSynchronizationRegistry.class)
.build();
public static final RuntimeCapability<Void> REMOTE_TRANSACTION_SERVICE_CAPABILITY =
RuntimeCapability.Builder.of("org.wildfly.transactions.remote-transaction-service", RemotingTransactionService.class)
.build();
static final RuntimeCapability<Void> XA_RESOURCE_RECOVERY_REGISTRY_CAPABILITY =
RuntimeCapability.Builder.of("org.wildfly.transactions.xa-resource-recovery-registry", XAResourceRecoveryRegistry.class)
.build();
//recovery environment
public static final SimpleAttributeDefinition BINDING = new SimpleAttributeDefinitionBuilder(CommonAttributes.BINDING, ModelType.STRING, false)
.setValidator(new StringLengthValidator(1))
.setFlags(AttributeAccess.Flag.RESTART_ALL_SERVICES)
.setXmlName(Attribute.BINDING.getLocalName())
.setAllowExpression(true)
.addAccessConstraint(SensitiveTargetAccessConstraintDefinition.SOCKET_BINDING_REF)
.build();
public static final SimpleAttributeDefinition STATUS_BINDING = new SimpleAttributeDefinitionBuilder(CommonAttributes.STATUS_BINDING, ModelType.STRING, false)
.setValidator(new StringLengthValidator(1))
.setFlags(AttributeAccess.Flag.RESTART_ALL_SERVICES)
.setXmlName(Attribute.STATUS_BINDING.getLocalName())
.setAllowExpression(true)
.addAccessConstraint(SensitiveTargetAccessConstraintDefinition.SOCKET_BINDING_REF)
.build();
public static final SimpleAttributeDefinition RECOVERY_LISTENER = new SimpleAttributeDefinitionBuilder(CommonAttributes.RECOVERY_LISTENER, ModelType.BOOLEAN, true)
.setDefaultValue(ModelNode.FALSE)
.setFlags(AttributeAccess.Flag.RESTART_ALL_SERVICES)
.setXmlName(Attribute.RECOVERY_LISTENER.getLocalName())
.setAllowExpression(true).build();
//core environment
public static final SimpleAttributeDefinition NODE_IDENTIFIER = new SimpleAttributeDefinitionBuilder(CommonAttributes.NODE_IDENTIFIER, ModelType.STRING, true)
.setDefaultValue(new ModelNode().set("1"))
.setFlags(AttributeAccess.Flag.RESTART_JVM)
.setAllowExpression(true)
.setValidator(new StringBytesLengthValidator(0,23,true,true))
.build();
public static final SimpleAttributeDefinition PROCESS_ID_UUID = new SimpleAttributeDefinitionBuilder("process-id-uuid", ModelType.BOOLEAN, true)
.setDefaultValue(ModelNode.FALSE)
.setAlternatives("process-id-socket-binding")
.setFlags(AttributeAccess.Flag.RESTART_ALL_SERVICES)
.build();
public static final SimpleAttributeDefinition PROCESS_ID_SOCKET_BINDING = new SimpleAttributeDefinitionBuilder("process-id-socket-binding", ModelType.STRING)
.setRequired(true)
.setValidator(new StringLengthValidator(1, true))
.setAlternatives("process-id-uuid")
.setFlags(AttributeAccess.Flag.RESTART_ALL_SERVICES)
.setXmlName(Attribute.BINDING.getLocalName())
.setAllowExpression(true)
.addAccessConstraint(SensitiveTargetAccessConstraintDefinition.SOCKET_BINDING_REF)
.build();
public static final SimpleAttributeDefinition PROCESS_ID_SOCKET_MAX_PORTS = new SimpleAttributeDefinitionBuilder("process-id-socket-max-ports", ModelType.INT, true)
.setValidator(new IntRangeValidator(1, true))
.setDefaultValue(new ModelNode().set(10))
.setRequires("process-id-socket-binding")
.setFlags(AttributeAccess.Flag.RESTART_ALL_SERVICES)
.setXmlName(Attribute.SOCKET_PROCESS_ID_MAX_PORTS.getLocalName())
.setAllowExpression(true)
.addAccessConstraint(SensitiveTargetAccessConstraintDefinition.SOCKET_CONFIG)
.build();
//coordinator environment
public static final SimpleAttributeDefinition STATISTICS_ENABLED = new SimpleAttributeDefinitionBuilder(CommonAttributes.STATISTICS_ENABLED, ModelType.BOOLEAN, true)
.setDefaultValue(ModelNode.FALSE)
.setFlags(AttributeAccess.Flag.RESTART_NONE)
.setAllowExpression(true).build();
public static final SimpleAttributeDefinition ENABLE_STATISTICS = new SimpleAttributeDefinitionBuilder(CommonAttributes.ENABLE_STATISTICS, ModelType.BOOLEAN, true)
.setDefaultValue(ModelNode.FALSE)
.setFlags(AttributeAccess.Flag.RESTART_NONE)
.setXmlName(Attribute.ENABLE_STATISTICS.getLocalName())
.setDeprecated(ModelVersion.create(2))
.setAllowExpression(true).build();
public static final SimpleAttributeDefinition ENABLE_TSM_STATUS = new SimpleAttributeDefinitionBuilder(CommonAttributes.ENABLE_TSM_STATUS, ModelType.BOOLEAN, true)
.setDefaultValue(ModelNode.FALSE)
.setFlags(AttributeAccess.Flag.RESTART_JVM)
.setXmlName(Attribute.ENABLE_TSM_STATUS.getLocalName())
.setAllowExpression(true).build();
public static final SimpleAttributeDefinition DEFAULT_TIMEOUT = new SimpleAttributeDefinitionBuilder(CommonAttributes.DEFAULT_TIMEOUT, ModelType.INT, true)
.setValidator(new IntRangeValidator(0))
.setMeasurementUnit(MeasurementUnit.SECONDS)
.setDefaultValue(new ModelNode().set(300))
.setFlags(AttributeAccess.Flag.RESTART_NONE)
.setXmlName(Attribute.DEFAULT_TIMEOUT.getLocalName())
.setAllowExpression(true).build();
public static final SimpleAttributeDefinition MAXIMUM_TIMEOUT = new SimpleAttributeDefinitionBuilder(CommonAttributes.MAXIMUM_TIMEOUT, ModelType.INT, true)
.setValidator(new IntRangeValidator(300))
.setMeasurementUnit(MeasurementUnit.SECONDS)
.setDefaultValue(new ModelNode().set(31536000))
.setFlags(AttributeAccess.Flag.RESTART_NONE)
.setAllowExpression(true).build();
//object store
public static final SimpleAttributeDefinition OBJECT_STORE_RELATIVE_TO = new SimpleAttributeDefinitionBuilder(CommonAttributes.OBJECT_STORE_RELATIVE_TO, ModelType.STRING, true)
.setFlags(AttributeAccess.Flag.RESTART_ALL_SERVICES)
.setXmlName(Attribute.RELATIVE_TO.getLocalName())
.setAllowExpression(true).build();
public static final SimpleAttributeDefinition OBJECT_STORE_PATH = new SimpleAttributeDefinitionBuilder(CommonAttributes.OBJECT_STORE_PATH, ModelType.STRING, true)
.setDefaultValue(new ModelNode().set("tx-object-store"))
.setFlags(AttributeAccess.Flag.RESTART_ALL_SERVICES)
.setXmlName(Attribute.PATH.getLocalName())
.setAllowExpression(true).build();
public static final SimpleAttributeDefinition JTS = new SimpleAttributeDefinitionBuilder(CommonAttributes.JTS, ModelType.BOOLEAN, true)
.setDefaultValue(ModelNode.FALSE)
.setFlags(AttributeAccess.Flag.RESTART_JVM) //I think the use of statics in arjunta will require a JVM restart
.setAllowExpression(false).build();
public static final SimpleAttributeDefinition USE_HORNETQ_STORE = new SimpleAttributeDefinitionBuilder(CommonAttributes.USE_HORNETQ_STORE, ModelType.BOOLEAN, true)
.setDefaultValue(ModelNode.FALSE)
.addAlternatives(CommonAttributes.USE_JDBC_STORE)
.setFlags(AttributeAccess.Flag.RESTART_JVM)
.setAllowExpression(false)
.setDeprecated(ModelVersion.create(3)).build();
// Use a separate AD for the :add op to advertise that use-hornetq-store and use-journal-store together is not optimal
static final SimpleAttributeDefinition USE_HORNETQ_STORE_PARAM = new SimpleAttributeDefinitionBuilder(USE_HORNETQ_STORE)
.addAlternatives(CommonAttributes.USE_JOURNAL_STORE).build();
public static final SimpleAttributeDefinition HORNETQ_STORE_ENABLE_ASYNC_IO = new SimpleAttributeDefinitionBuilder(CommonAttributes.HORNETQ_STORE_ENABLE_ASYNC_IO, ModelType.BOOLEAN, true)
.setDefaultValue(ModelNode.FALSE)
.setFlags(AttributeAccess.Flag.RESTART_JVM)
.setXmlName(Attribute.ENABLE_ASYNC_IO.getLocalName())
.setAllowExpression(true)
.setRequires(CommonAttributes.USE_HORNETQ_STORE)
.setDeprecated(ModelVersion.create(3)).build();
public static final SimpleAttributeDefinition USE_JOURNAL_STORE = new SimpleAttributeDefinitionBuilder(CommonAttributes.USE_JOURNAL_STORE, ModelType.BOOLEAN, true)
.setDefaultValue(ModelNode.FALSE)
.addAlternatives(CommonAttributes.USE_JDBC_STORE)
.setFlags(AttributeAccess.Flag.RESTART_JVM)
.setAllowExpression(false).build();
// Use a separate AD for the :add op to advertise that use-hornetq-store and use-journal-store together is not optimal
static final SimpleAttributeDefinition USE_JOURNAL_STORE_PARAM = new SimpleAttributeDefinitionBuilder(USE_JOURNAL_STORE)
.addAlternatives(CommonAttributes.USE_HORNETQ_STORE).build();
public static final SimpleAttributeDefinition JOURNAL_STORE_ENABLE_ASYNC_IO = new SimpleAttributeDefinitionBuilder(CommonAttributes.JOURNAL_STORE_ENABLE_ASYNC_IO, ModelType.BOOLEAN, true)
.setDefaultValue(ModelNode.FALSE)
.setFlags(AttributeAccess.Flag.RESTART_JVM)
.setXmlName(Attribute.ENABLE_ASYNC_IO.getLocalName())
.setAllowExpression(true)
.setRequires(CommonAttributes.USE_JOURNAL_STORE).build();
public static final SimpleAttributeDefinition USE_JDBC_STORE = new SimpleAttributeDefinitionBuilder(CommonAttributes.USE_JDBC_STORE, ModelType.BOOLEAN, true)
.setDefaultValue(ModelNode.FALSE)
.addAlternatives(CommonAttributes.USE_JOURNAL_STORE)
.addAlternatives(CommonAttributes.USE_HORNETQ_STORE)
.setRequires(CommonAttributes.JDBC_STORE_DATASOURCE)
.setFlags(AttributeAccess.Flag.RESTART_JVM)
.setAllowExpression(false).build();
public static final SimpleAttributeDefinition JDBC_STORE_DATASOURCE = new SimpleAttributeDefinitionBuilder(CommonAttributes.JDBC_STORE_DATASOURCE, ModelType.STRING, true)
.setFlags(AttributeAccess.Flag.RESTART_JVM)
.setXmlName(Attribute.DATASOURCE_JNDI_NAME.getLocalName())
.setAllowExpression(true).build();
public static final SimpleAttributeDefinition JDBC_ACTION_STORE_TABLE_PREFIX =
new SimpleAttributeDefinitionBuilder(CommonAttributes.JDBC_ACTION_STORE_TABLE_PREFIX, ModelType.STRING, true)
.setFlags(AttributeAccess.Flag.RESTART_JVM)
.setXmlName(Attribute.TABLE_PREFIX.getLocalName())
.setAllowExpression(true)
.setRequires(CommonAttributes.USE_JDBC_STORE).build();
public static final SimpleAttributeDefinition JDBC_ACTION_STORE_DROP_TABLE = new SimpleAttributeDefinitionBuilder(CommonAttributes.JDBC_ACTION_STORE_DROP_TABLE, ModelType.BOOLEAN, true)
.setDefaultValue(ModelNode.FALSE)
.setFlags(AttributeAccess.Flag.RESTART_JVM)
.setXmlName(Attribute.DROP_TABLE.getLocalName())
.setAllowExpression(true)
.setRequires(CommonAttributes.USE_JDBC_STORE).build();
public static final SimpleAttributeDefinition JDBC_COMMUNICATION_STORE_TABLE_PREFIX = new SimpleAttributeDefinitionBuilder(CommonAttributes.JDBC_COMMUNICATION_STORE_TABLE_PREFIX, ModelType.STRING, true)
.setFlags(AttributeAccess.Flag.RESTART_JVM)
.setXmlName(Attribute.TABLE_PREFIX.getLocalName())
.setAllowExpression(true)
.setRequires(CommonAttributes.USE_JDBC_STORE).build();
public static final SimpleAttributeDefinition JDBC_COMMUNICATION_STORE_DROP_TABLE = new SimpleAttributeDefinitionBuilder(CommonAttributes.JDBC_COMMUNICATION_STORE_DROP_TABLE, ModelType.BOOLEAN, true)
.setDefaultValue(ModelNode.FALSE)
.setFlags(AttributeAccess.Flag.RESTART_JVM)
.setXmlName(Attribute.DROP_TABLE.getLocalName())
.setAllowExpression(true)
.setRequires(CommonAttributes.USE_JDBC_STORE).build();
public static final SimpleAttributeDefinition JDBC_STATE_STORE_TABLE_PREFIX = new SimpleAttributeDefinitionBuilder(CommonAttributes.JDBC_STATE_STORE_TABLE_PREFIX, ModelType.STRING, true)
.setFlags(AttributeAccess.Flag.RESTART_JVM)
.setXmlName(Attribute.TABLE_PREFIX.getLocalName())
.setAllowExpression(true)
.setRequires(CommonAttributes.USE_JDBC_STORE).build();
public static final SimpleAttributeDefinition JDBC_STATE_STORE_DROP_TABLE = new SimpleAttributeDefinitionBuilder(CommonAttributes.JDBC_STATE_STORE_DROP_TABLE, ModelType.BOOLEAN, true)
.setDefaultValue(ModelNode.FALSE)
.setFlags(AttributeAccess.Flag.RESTART_JVM)
.setXmlName(Attribute.DROP_TABLE.getLocalName())
.setAllowExpression(true)
.setRequires(CommonAttributes.USE_JDBC_STORE).build();
public static final SimpleAttributeDefinition STALE_TRANSACTION_TIME = new SimpleAttributeDefinitionBuilder(CommonAttributes.STALE_TRANSACTION_TIME, ModelType.INT, true)
.setValidator(new IntRangeValidator(0))
.setMeasurementUnit(MeasurementUnit.SECONDS)
.setDefaultValue(new ModelNode().set(600))
.setFlags(AttributeAccess.Flag.RESTART_ALL_SERVICES)
.setAllowExpression(true).build();
private final boolean registerRuntimeOnly;
TransactionSubsystemRootResourceDefinition(boolean registerRuntimeOnly) {
super(new Parameters(TransactionExtension.SUBSYSTEM_PATH,
TransactionExtension.getResourceDescriptionResolver())
.setAddHandler(TransactionSubsystemAdd.INSTANCE)
.setRemoveHandler(TransactionSubsystemRemove.INSTANCE)
.setCapabilities(TRANSACTION_CAPABILITY, LOCAL_PROVIDER_CAPABILITY,
TRANSACTION_SYNCHRONIZATION_REGISTRY_CAPABILITY,
XA_RESOURCE_RECOVERY_REGISTRY_CAPABILITY)
// Configuring these is not required as these are defaulted based on our add/remove handler types
//OperationEntry.Flag.RESTART_ALL_SERVICES, OperationEntry.Flag.RESTART_ALL_SERVICES
);
this.registerRuntimeOnly = registerRuntimeOnly;
}
// all attributes
static final AttributeDefinition[] add_attributes = new AttributeDefinition[] {
BINDING, STATUS_BINDING, RECOVERY_LISTENER, NODE_IDENTIFIER, PROCESS_ID_UUID, PROCESS_ID_SOCKET_BINDING,
PROCESS_ID_SOCKET_MAX_PORTS, STATISTICS_ENABLED, ENABLE_TSM_STATUS, DEFAULT_TIMEOUT, MAXIMUM_TIMEOUT,
OBJECT_STORE_RELATIVE_TO, OBJECT_STORE_PATH, JTS, USE_HORNETQ_STORE_PARAM, USE_JOURNAL_STORE_PARAM, USE_JDBC_STORE, JDBC_STORE_DATASOURCE,
JDBC_ACTION_STORE_DROP_TABLE, JDBC_ACTION_STORE_TABLE_PREFIX, JDBC_COMMUNICATION_STORE_DROP_TABLE,
JDBC_COMMUNICATION_STORE_TABLE_PREFIX, JDBC_STATE_STORE_DROP_TABLE, JDBC_STATE_STORE_TABLE_PREFIX,
JOURNAL_STORE_ENABLE_ASYNC_IO, ENABLE_STATISTICS, HORNETQ_STORE_ENABLE_ASYNC_IO, STALE_TRANSACTION_TIME
};
static final AttributeDefinition[] attributes_1_2 = new AttributeDefinition[] {USE_JDBC_STORE, JDBC_STORE_DATASOURCE,
JDBC_ACTION_STORE_DROP_TABLE, JDBC_ACTION_STORE_TABLE_PREFIX,
JDBC_COMMUNICATION_STORE_DROP_TABLE, JDBC_COMMUNICATION_STORE_TABLE_PREFIX,
JDBC_STATE_STORE_DROP_TABLE, JDBC_STATE_STORE_TABLE_PREFIX
};
@Override
public void registerAttributes(ManagementResourceRegistration resourceRegistration) {
// Register all attributes except of the mutual ones
Set<AttributeDefinition> attributesWithoutMutuals = new HashSet<>(Arrays.asList(add_attributes));
attributesWithoutMutuals.remove(USE_HORNETQ_STORE_PARAM);
attributesWithoutMutuals.remove(USE_JOURNAL_STORE_PARAM);
attributesWithoutMutuals.remove(USE_JDBC_STORE);
attributesWithoutMutuals.remove(STATISTICS_ENABLED);
attributesWithoutMutuals.remove(DEFAULT_TIMEOUT);
attributesWithoutMutuals.remove(MAXIMUM_TIMEOUT);
attributesWithoutMutuals.remove(JDBC_STORE_DATASOURCE); // Remove these as it also needs special write handler
attributesWithoutMutuals.remove(PROCESS_ID_UUID);
attributesWithoutMutuals.remove(PROCESS_ID_SOCKET_BINDING);
attributesWithoutMutuals.remove(PROCESS_ID_SOCKET_MAX_PORTS);
attributesWithoutMutuals.remove(ENABLE_STATISTICS);
attributesWithoutMutuals.remove(HORNETQ_STORE_ENABLE_ASYNC_IO);
OperationStepHandler writeHandler = new ReloadRequiredWriteAttributeHandler(attributesWithoutMutuals);
for(final AttributeDefinition def : attributesWithoutMutuals) {
resourceRegistration.registerReadWriteAttribute(def, null, writeHandler);
}
// Register mutual object store attributes
OperationStepHandler mutualWriteHandler = new ObjectStoreMutualWriteHandler(USE_JOURNAL_STORE, USE_JDBC_STORE);
resourceRegistration.registerReadWriteAttribute(USE_JOURNAL_STORE, null, mutualWriteHandler);
resourceRegistration.registerReadWriteAttribute(USE_JDBC_STORE, null, mutualWriteHandler);
//Register default-timeout attribute
resourceRegistration.registerReadWriteAttribute(DEFAULT_TIMEOUT, null, new DefaultTimeoutHandler(DEFAULT_TIMEOUT));
resourceRegistration.registerReadWriteAttribute(MAXIMUM_TIMEOUT, null, new MaximumTimeoutHandler(MAXIMUM_TIMEOUT));
// Register jdbc-store-datasource attribute
resourceRegistration.registerReadWriteAttribute(JDBC_STORE_DATASOURCE, null, new JdbcStoreDatasourceWriteHandler(JDBC_STORE_DATASOURCE));
// Register mutual object store attributes
OperationStepHandler mutualProcessIdWriteHandler = new ProcessIdWriteHandler(PROCESS_ID_UUID, PROCESS_ID_SOCKET_BINDING, PROCESS_ID_SOCKET_MAX_PORTS);
resourceRegistration.registerReadWriteAttribute(PROCESS_ID_UUID, null, mutualProcessIdWriteHandler);
resourceRegistration.registerReadWriteAttribute(PROCESS_ID_SOCKET_BINDING, null, mutualProcessIdWriteHandler);
resourceRegistration.registerReadWriteAttribute(PROCESS_ID_SOCKET_MAX_PORTS, null, mutualProcessIdWriteHandler);
//Register statistics-enabled attribute
resourceRegistration.registerReadWriteAttribute(STATISTICS_ENABLED, null, new StatisticsEnabledHandler(STATISTICS_ENABLED));
AliasedHandler esh = new AliasedHandler(STATISTICS_ENABLED.getName());
resourceRegistration.registerReadWriteAttribute(ENABLE_STATISTICS, esh, esh);
AliasedHandler hsh = new AliasedHandler(USE_JOURNAL_STORE.getName());
resourceRegistration.registerReadWriteAttribute(USE_HORNETQ_STORE, hsh, hsh);
AliasedHandler hseh = new AliasedHandler(JOURNAL_STORE_ENABLE_ASYNC_IO.getName());
resourceRegistration.registerReadWriteAttribute(HORNETQ_STORE_ENABLE_ASYNC_IO, hseh, hseh);
if (registerRuntimeOnly) {
TxStatsHandler.INSTANCE.registerMetrics(resourceRegistration);
}
}
@SuppressWarnings("deprecation")
@Override
protected void registerAddOperation(ManagementResourceRegistration registration, OperationStepHandler handler, OperationEntry.Flag... flags) {
// Sort the add params alphabetically to match what DefaultResourceAddDescriptionProvider does
SortedSet<AttributeDefinition> sorted = new TreeSet<>(Comparator.comparing(AttributeDefinition::getName));
for (AttributeDefinition ad : add_attributes) {
if (!ad.getImmutableFlags().contains(AttributeAccess.Flag.STORAGE_RUNTIME)) {
sorted.add(ad);
}
}
registration.registerOperationHandler(new SimpleOperationDefinitionBuilder(ModelDescriptionConstants.ADD, getResourceDescriptionResolver())
.withFlags(flags)
.setParameters(sorted.toArray(new AttributeDefinition[add_attributes.length]))
.setEntryType(OperationEntry.EntryType.PUBLIC)
.build()
, handler);
}
private static class AliasedHandler implements OperationStepHandler {
private final String aliasedName;
public AliasedHandler(String aliasedName) {
this.aliasedName = aliasedName;
}
@Override
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
ModelNode aliased = getAliasedOperation(operation);
context.addStep(aliased, getHandlerForOperation(context, operation), OperationContext.Stage.MODEL, true);
}
private ModelNode getAliasedOperation(ModelNode operation) {
ModelNode aliased = operation.clone();
aliased.get(ModelDescriptionConstants.NAME).set(aliasedName);
return aliased;
}
private static OperationStepHandler getHandlerForOperation(OperationContext context, ModelNode operation) {
ImmutableManagementResourceRegistration imrr = context.getResourceRegistration();
return imrr.getOperationHandler(PathAddress.EMPTY_ADDRESS, operation.get(OP).asString());
}
}
private static class ObjectStoreMutualWriteHandler extends ReloadRequiredWriteAttributeHandler {
public ObjectStoreMutualWriteHandler(final AttributeDefinition... definitions) {
super(definitions);
}
@Override
protected void finishModelStage(final OperationContext context, final ModelNode operation, String attributeName,
ModelNode newValue, ModelNode oldValue, final Resource model) throws OperationFailedException {
super.finishModelStage(context, operation, attributeName, newValue, oldValue, model);
assert !USE_JOURNAL_STORE.isAllowExpression() && !USE_JDBC_STORE.isAllowExpression() : "rework this before enabling expression";
if (attributeName.equals(USE_JOURNAL_STORE.getName()) || attributeName.equals(USE_JDBC_STORE.getName())) {
if (newValue.isDefined() && newValue.asBoolean()) {
// check the value of the mutual attribute and disable it if it is set to true
final String mutualAttributeName = attributeName.equals(USE_JDBC_STORE.getName())
? USE_JOURNAL_STORE.getName()
: USE_JDBC_STORE.getName();
ModelNode resourceModel = model.getModel();
if (resourceModel.hasDefined(mutualAttributeName) && resourceModel.get(mutualAttributeName).asBoolean()) {
resourceModel.get(mutualAttributeName).set(ModelNode.FALSE);
}
}
}
context.addStep(JdbcStoreValidationStep.INSTANCE, OperationContext.Stage.MODEL);
}
}
private static class JdbcStoreDatasourceWriteHandler extends ReloadRequiredWriteAttributeHandler {
public JdbcStoreDatasourceWriteHandler(AttributeDefinition... definitions) {
super(definitions);
}
@Override
protected void validateUpdatedModel(OperationContext context, Resource model) throws OperationFailedException {
super.validateUpdatedModel(context, model);
context.addStep(JdbcStoreValidationStep.INSTANCE, OperationContext.Stage.MODEL);
}
}
/**
* Validates that if use-jdbc-store is set, jdbc-store-datasource must be also set.
*
* Must be added to both use-jdbc-store and jdbc-store-datasource fields.
*/
private static class JdbcStoreValidationStep implements OperationStepHandler {
private static final JdbcStoreValidationStep INSTANCE = new JdbcStoreValidationStep();
@Override
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
ModelNode modelNode = context.readResource(PathAddress.EMPTY_ADDRESS).getModel();
if (modelNode.hasDefined(USE_JDBC_STORE.getName()) && modelNode.get(USE_JDBC_STORE.getName()).asBoolean()
&& !modelNode.hasDefined(JDBC_STORE_DATASOURCE.getName())) {
throw TransactionLogger.ROOT_LOGGER.mustBeDefinedIfTrue(JDBC_STORE_DATASOURCE.getName(), USE_JDBC_STORE.getName());
}
}
}
private static class ProcessIdWriteHandler extends ReloadRequiredWriteAttributeHandler {
public ProcessIdWriteHandler(final AttributeDefinition... definitions) {
super(definitions);
}
@Override
protected void validateUpdatedModel(final OperationContext context, final Resource model) {
context.addStep(new OperationStepHandler() {
@Override
public void execute(OperationContext operationContext, ModelNode operation) throws OperationFailedException {
ModelNode node = context.readResource(PathAddress.EMPTY_ADDRESS).getModel();
if (node.hasDefined(TransactionSubsystemRootResourceDefinition.PROCESS_ID_UUID.getName())
&& node.get(TransactionSubsystemRootResourceDefinition.PROCESS_ID_UUID.getName()).asBoolean()) {
if (node.hasDefined(TransactionSubsystemRootResourceDefinition.PROCESS_ID_SOCKET_BINDING.getName())) {
throw TransactionLogger.ROOT_LOGGER.mustBeUndefinedIfTrue(TransactionSubsystemRootResourceDefinition.PROCESS_ID_SOCKET_BINDING.getName(), TransactionSubsystemRootResourceDefinition.PROCESS_ID_UUID.getName());
} else if (node.hasDefined(TransactionSubsystemRootResourceDefinition.PROCESS_ID_SOCKET_MAX_PORTS.getName())) {
throw TransactionLogger.ROOT_LOGGER.mustBeUndefinedIfTrue(TransactionSubsystemRootResourceDefinition.PROCESS_ID_SOCKET_MAX_PORTS.getName(), TransactionSubsystemRootResourceDefinition.PROCESS_ID_UUID.getName());
}
} else if (node.hasDefined(TransactionSubsystemRootResourceDefinition.PROCESS_ID_SOCKET_BINDING.getName())) {
//it's fine do nothing
} else if (node.hasDefined(TransactionSubsystemRootResourceDefinition.PROCESS_ID_SOCKET_MAX_PORTS.getName())) {
throw TransactionLogger.ROOT_LOGGER.mustBedefinedIfDefined(TransactionSubsystemRootResourceDefinition.PROCESS_ID_SOCKET_BINDING.getName(), TransactionSubsystemRootResourceDefinition.PROCESS_ID_SOCKET_MAX_PORTS.getName());
} else {
// not uuid and also not sockets!
throw TransactionLogger.ROOT_LOGGER.eitherTrueOrDefined(TransactionSubsystemRootResourceDefinition.PROCESS_ID_UUID.getName(), TransactionSubsystemRootResourceDefinition.PROCESS_ID_SOCKET_BINDING.getName());
}
}
}, OperationContext.Stage.MODEL);
}
@Override
protected void finishModelStage(final OperationContext context, final ModelNode operation, String attributeName,
ModelNode newValue, ModelNode oldValue, final Resource model) {
if (attributeName.equals(PROCESS_ID_SOCKET_BINDING.getName())
&& newValue.isDefined()) {
ModelNode resourceModel = model.getModel();
if (resourceModel.hasDefined(PROCESS_ID_UUID.getName())
&& resourceModel.get(PROCESS_ID_UUID.getName()).asBoolean()) {
resourceModel.get(PROCESS_ID_UUID.getName()).set(ModelNode.FALSE);
}
}
if (attributeName.equals(PROCESS_ID_UUID.getName())
&& newValue.asBoolean(false)) {
ModelNode resourceModel = model.getModel();
resourceModel.get(PROCESS_ID_SOCKET_BINDING.getName()).clear();
resourceModel.get(PROCESS_ID_SOCKET_MAX_PORTS.getName()).clear();
}
validateUpdatedModel(context, model);
}
}
@Override
public void registerChildren(ManagementResourceRegistration resourceRegistration) {
resourceRegistration.registerSubModel(new CMResourceResourceDefinition());
}
private static class DefaultTimeoutHandler extends AbstractWriteAttributeHandler<Void> {
public DefaultTimeoutHandler(final AttributeDefinition... definitions) {
super(definitions);
}
@Override
protected boolean applyUpdateToRuntime(final OperationContext context, final ModelNode operation,
final String attributeName, final ModelNode resolvedValue,
final ModelNode currentValue, final HandbackHolder<Void> handbackHolder)
throws OperationFailedException {
int timeout = resolvedValue.asInt();
// TxControl allow timeout to be set to 0 with meaning of no timeout at all
arjPropertyManager.getCoordinatorEnvironmentBean().setDefaultTimeout(timeout);
TxControl.setDefaultTimeout(timeout);
if (timeout == 0) {
ModelNode model = context.readResource(PathAddress.EMPTY_ADDRESS).getModel();
timeout = MAXIMUM_TIMEOUT.resolveModelAttribute(context, model).asInt();
TransactionLogger.ROOT_LOGGER.timeoutValueIsSetToMaximum(timeout);
}
ContextTransactionManager.setGlobalDefaultTransactionTimeout(timeout);
return false;
}
@Override
protected void revertUpdateToRuntime(final OperationContext context, final ModelNode operation,
final String attributeName, final ModelNode valueToRestore,
final ModelNode valueToRevert, final Void handback)
throws OperationFailedException {
arjPropertyManager.getCoordinatorEnvironmentBean().setDefaultTimeout(valueToRestore.asInt());
TxControl.setDefaultTimeout(valueToRestore.asInt());
ContextTransactionManager.setGlobalDefaultTransactionTimeout(valueToRestore.asInt());
}
}
private static class MaximumTimeoutHandler extends AbstractWriteAttributeHandler<Void> {
public MaximumTimeoutHandler(final AttributeDefinition... definitions) {
super(definitions);
}
@Override
protected boolean applyUpdateToRuntime(final OperationContext context, final ModelNode operation,
final String attributeName, final ModelNode resolvedValue,
final ModelNode currentValue, final HandbackHolder<Void> handbackHolder)
throws OperationFailedException {
int maximum_timeout = resolvedValue.asInt();
if (TxControl.getDefaultTimeout() == 0) {
TransactionLogger.ROOT_LOGGER.timeoutValueIsSetToMaximum(maximum_timeout);
ContextTransactionManager.setGlobalDefaultTransactionTimeout(maximum_timeout);
}
return false;
}
@Override
protected void revertUpdateToRuntime(OperationContext operationContext, ModelNode modelNode, String s, ModelNode modelNode1, ModelNode modelNode2, Void aVoid) throws OperationFailedException {
}
}
private static class StatisticsEnabledHandler extends AbstractWriteAttributeHandler<Void> {
private volatile CoordinatorEnvironmentBean coordinatorEnvironmentBean;
public StatisticsEnabledHandler(final AttributeDefinition... definitions) {
super(definitions);
}
@Override
protected boolean applyUpdateToRuntime(final OperationContext context, final ModelNode operation,
final String attributeName, final ModelNode resolvedValue,
final ModelNode currentValue, final HandbackHolder<Void> handbackHolder)
throws OperationFailedException {
if (this.coordinatorEnvironmentBean == null) {
this.coordinatorEnvironmentBean = arjPropertyManager.getCoordinatorEnvironmentBean();
}
coordinatorEnvironmentBean.setEnableStatistics(resolvedValue.asBoolean());
return false;
}
@Override
protected void revertUpdateToRuntime(final OperationContext context, final ModelNode operation,
final String attributeName, final ModelNode valueToRestore,
final ModelNode valueToRevert, final Void handback)
throws OperationFailedException {
if (this.coordinatorEnvironmentBean == null) {
this.coordinatorEnvironmentBean = arjPropertyManager.getCoordinatorEnvironmentBean();
}
coordinatorEnvironmentBean.setEnableStatistics(valueToRestore.asBoolean());
}
}
}