[jboss-jira] [JBoss JIRA] (WFLY-9597) UndertowSubsystemParser_5_0 could be instantiated twice: once as a reader and once as a writer

Brian Stansberry (JIRA) issues at jboss.org
Tue Dec 5 13:08:00 EST 2017


    [ https://issues.jboss.org/browse/WFLY-9597?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13497564#comment-13497564 ] 

Brian Stansberry commented on WFLY-9597:
----------------------------------------

Part of the reason I filed WFCORE-3441 is I wanted consideration of this kind thing before people started just blindly moving to a Supplier in order to make a deprecation warn go away.

There are a number of intersecting factors to balance in all this.

1) If the parsers and marshallers are basically stateless objects, the class space for the Supplier is more than the cost of an object.
2) A PersistentResourceXMLParser implementation may or may not be stateless, depending on how it is coded. Some store the PersistentResourceXMLDescription in a static field (making the class itself somewhat heavy but an instance stateless), some in an instance field, and some calculate it on the fly.
3) For the current version of a parser, it's actually important to boot time that a PersistentResourceXMLDescription be created during Extension.initializeParsers and not deferred to when parsing happens. Extension.initializeParsers is done concurrently while parsing is single threaded, and creating the PersistentResourceXMLDescription ends up being the trigger that loads most of the extensions management model classes, creates AttributeDefinitions etc.

Likely the most efficient way to do this with a PersistentResourceXMLParser is:

{code}
class FooExtension implements Extension {

  private volatile PersistentResourceXmlParser currentParserMarshaller;

  private PersistentResourceXmlParser getCurrentParserMarshaller() {
       PersistentResourceXmlParser result = currentParserMarshaller;
       if (result == null) {
           result = currentParserMarshaller = new FooParser3_0();
        }
        return result;
    }

    public void initializeParsers(ExtensionParsingContext context) {
        .... register legacy parsers using the Supplier API
        context.setSubsystemXmlMapping("foo",  FOO_3_URI, getCurrentParserMarshaller());
    }

    public void initialize(ExtensionContext context) {
        .... do the other stuff
        subsystem.registerXMLElementWriter(getCurrentParserMarshaller());
    }

}
{code}

That's kind of fussy code, but oh well.
        

> UndertowSubsystemParser_5_0 could be instantiated twice: once as a reader and once as a writer
> ----------------------------------------------------------------------------------------------
>
>                 Key: WFLY-9597
>                 URL: https://issues.jboss.org/browse/WFLY-9597
>             Project: WildFly
>          Issue Type: Bug
>          Components: Web (Undertow)
>            Reporter: Radoslav Husar
>            Assignee: Tomaz Cerar
>
> The org.wildfly.extension.undertow.UndertowSubsystemParser_5_0#xmlDescription could be created twice, the first and last line in the diff should return the same instance or use different approach: https://github.com/rhusar/wildfly/blob/7dbc8bd0c8bcdae5db61ecdff1484a422cf4b92c/undertow/src/main/java/org/wildfly/extension/undertow/UndertowExtension.java#L100-L113
> Most likely the same issue is in multiple places.



--
This message was sent by Atlassian JIRA
(v7.5.0#75005)


More information about the jboss-jira mailing list