6
6
package org .wildfly .extension .io ;
7
7
8
8
import java .util .List ;
9
- import java .util .function .Predicate ;
10
- import java .util .stream .Stream ;
9
+ import java .util .function .UnaryOperator ;
11
10
12
- import org .jboss .as .controller .PathAddress ;
13
- import org .jboss .as .controller .PersistentResourceXMLDescription ;
14
- import org .jboss .as .controller .PersistentSubsystemSchema ;
11
+ import org .jboss .as .controller .ResourceDescription ;
15
12
import org .jboss .as .controller .SubsystemSchema ;
13
+ import org .jboss .as .controller .persistence .xml .ResourceXMLElement ;
14
+ import org .jboss .as .controller .persistence .xml .SubsystemResourceXMLSchema ;
16
15
import org .jboss .as .controller .xml .VersionedNamespace ;
17
16
import org .jboss .dmr .ModelNode ;
18
17
import org .jboss .staxmapper .IntVersion ;
19
- import org .wildfly .io .OptionAttributeDefinition ;
20
18
21
19
/**
22
20
* Enumerates the supported schemas of the IO subsystem.
23
21
*/
24
- public enum IOSubsystemSchema implements PersistentSubsystemSchema <IOSubsystemSchema > {
22
+ public enum IOSubsystemSchema implements SubsystemResourceXMLSchema <IOSubsystemSchema > {
25
23
VERSION_1_1 (1 , 1 ), // WildFly 8.1 - 10.1
26
24
VERSION_2_0 (2 , 0 ), // WildFly 11 - 12
27
25
VERSION_3_0 (3 , 0 ), // WildFly 13 - 31
@@ -32,7 +30,7 @@ public enum IOSubsystemSchema implements PersistentSubsystemSchema<IOSubsystemSc
32
30
private final VersionedNamespace <IntVersion , IOSubsystemSchema > namespace ;
33
31
34
32
IOSubsystemSchema (int major , int minor ) {
35
- this .namespace = SubsystemSchema .createLegacySubsystemURN (IOSubsystemRegistrar . NAME , new IntVersion (major , minor ));
33
+ this .namespace = SubsystemSchema .createLegacySubsystemURN (IOSubsystemResourceDescription . INSTANCE . getName () , new IntVersion (major , minor ));
36
34
}
37
35
38
36
@ Override
@@ -41,32 +39,29 @@ public VersionedNamespace<IntVersion, IOSubsystemSchema> getNamespace() {
41
39
}
42
40
43
41
@ Override
44
- public PersistentResourceXMLDescription getXMLDescription () {
45
- PersistentResourceXMLDescription .Factory factory = PersistentResourceXMLDescription .factory (this );
46
- PersistentResourceXMLDescription .Builder builder = factory .builder (IOSubsystemRegistrar .PATH );
47
- if (this .since (VERSION_4_0 )) {
48
- builder .addAttribute (IOSubsystemRegistrar .DEFAULT_WORKER );
49
- } else {
50
- builder .setAdditionalOperationsGenerator (new PersistentResourceXMLDescription .AdditionalOperationsGenerator () {
42
+ public ResourceXMLElement getSubsystemResourceXMLElement () {
43
+ ResourceXMLElement .Builder .Factory factory = ResourceXMLElement .Builder .Factory .newInstance (this );
44
+ ResourceXMLElement .Builder builder = factory .createBuilder (IOSubsystemResourceDescription .INSTANCE );
45
+ if (!this .since (VERSION_4_0 )) {
46
+ builder .excludeAttribute (IOSubsystemResourceDescription .DEFAULT_WORKER );
47
+ builder .withOperationTransformation (new UnaryOperator <>() {
51
48
@ Override
52
- public void additionalOperations ( PathAddress address , ModelNode addOperation , List < ModelNode > operations ) {
49
+ public ModelNode apply ( ModelNode operation ) {
53
50
// Apply "magic" default worker referenced by other subsystems
54
- addOperation .get (IOSubsystemRegistrar .DEFAULT_WORKER .getName ()).set (IOSubsystemRegistrar .LEGACY_DEFAULT_WORKER );
51
+ operation .get (IOSubsystemResourceDescription .DEFAULT_WORKER .getName ()).set (IOSubsystemResourceRegistrar .LEGACY_DEFAULT_WORKER );
52
+ return operation ;
55
53
}
56
54
});
57
55
}
58
-
59
- Stream <OptionAttributeDefinition > workerAttributes = Stream .of (WorkerResourceDefinition .ATTRIBUTES );
56
+ ResourceXMLElement .Builder workerBuilder = factory .createBuilder (ResourceDescription .of (WorkerResourceDefinition .PATH , List .of (WorkerResourceDefinition .ATTRIBUTES )));
60
57
if (!this .since (VERSION_3_0 )) {
61
- workerAttributes = workerAttributes . filter ( Predicate . not ( WorkerResourceDefinition .WORKER_TASK_CORE_THREADS :: equals ) );
58
+ workerBuilder . excludeAttribute ( WorkerResourceDefinition .WORKER_TASK_CORE_THREADS );
62
59
}
63
- PersistentResourceXMLDescription .Builder workerBuilder = factory .builder (WorkerResourceDefinition .PATH ).addAttributes (workerAttributes );
64
60
if (this .since (VERSION_2_0 )) {
65
- workerBuilder .addChild (factory .builder ( OutboundBindAddressResourceDefinition .PATH ). addAttributes ( OutboundBindAddressResourceDefinition .ATTRIBUTES . stream ( )).build ());
61
+ workerBuilder .appendChild (factory .createBuilder ( ResourceDescription . of ( OutboundBindAddressResourceDefinition .PATH , OutboundBindAddressResourceDefinition .ATTRIBUTES )).build ());
66
62
}
67
-
68
- return builder .addChild (workerBuilder .build ())
69
- .addChild (factory .builder (BufferPoolResourceDefinition .PATH ).addAttributes (BufferPoolResourceDefinition .ATTRIBUTES .stream ()).build ())
63
+ return builder .appendChild (workerBuilder .build ())
64
+ .appendChild (factory .createBuilder (ResourceDescription .of (BufferPoolResourceDefinition .PATH , BufferPoolResourceDefinition .ATTRIBUTES )).build ())
70
65
.build ();
71
66
}
72
67
}
0 commit comments