JavaCro'14 - Using WildFly core to build high performance web server – Tomaž Cerar

3,046 views

Published on

WildFly core is fully modular application server, which is used as base to build WildFly EE container and much more. Functionalities such as EE are implemented as sets of extensions also known as subsystems.
Extensions give you low level access to application server’s functionalities such as

JBoss Modules for class loading
Domain management model
Deployment processors
Modular Service Container (aka service kernel)

Published in: Technology, Education
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
3,046
On SlideShare
0
From Embeds
0
Number of Embeds
1,324
Actions
Shares
0
Downloads
20
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

JavaCro'14 - Using WildFly core to build high performance web server – Tomaž Cerar

  1. 1. Using WildFly core to build high performance web server Tomaž Cerar, Red Hat
  2. 2. Agenda • Undertow • WildFly core • What are extensions • Write simple extension• Write simple extension • Undertow extension • Demo
  3. 3. WILDFLY CORE
  4. 4. WildFly core • Really small (< 15 mb) • Consists of – JBoss Modules – Modular Service Controller (MSC)– Modular Service Controller (MSC) – Domain management (CLI, rest) – Deployment manager – Logging • Base for WildFly 8, EE7 certified app server
  5. 5. JBoss Modules • Modular class loader • Concurrent class loader implementation • Isolated class loader • Each module consists of set of resources• Each module consists of set of resources
  6. 6. Domain management • Manages configuration • Backbone for all extensions • Accessible via – Extensions– Extensions – CLI – Admin console – DMR clients – …
  7. 7. Modular Service Controller • Truly concurrent service container • Handles service dependencies • Handles lifecycle • All “real” functionality should be in services• All “real” functionality should be in services
  8. 8. DMR • Detyped Model Representation • JSON like • Internal format for all operations • Internal model (ModelNode)• Internal model (ModelNode) • Resides in org.jboss.dmr package • Really small
  9. 9. UNDERTOW
  10. 10. Undertow • Highly concurrent web server • Servlet 3.1 container • HTTP / AJP / SSL Proxy server • Supports Websocket implementation• Supports Websocket implementation • Supports HTTP Upgrade • Supports use of high performance non-blocking handlers in servlet deployments • Initial HTTP2 / Spdy support
  11. 11. Why Another Webserver? • A true non-blocking API (servlet is by itself insufficient) • Improved support for modern security standards • Upgrade from HTTP to our native protocols• Upgrade from HTTP to our native protocols • Allows WildFly to run in single port mode • Support the latest network protocols naturally and with minimal overhead • Best possible performance and memory efficiency • Handle complex routing use cases a la mod_rewrite • Embeddable in standalone process / test environment
  12. 12. What are extensions? • Entry point for extending WildFly • Can provide – new deployment types – new model– new model – services – resources
  13. 13. Domain model definition • Attributes • Resources • Resource tree – PathElement– PathElement – Single target (key=value) – Multi target (key=*) • Resolvers & multi language support
  14. 14. Operation handlers • Defines operations on resources • Execution stage – MODEL – RUNTIME– RUNTIME – VERIFY – DOMAIN – DONE • Can be chained
  15. 15. Resource handlers • Every resource needs add & remove • In MODEL phase – validate and set model • In RUNTIME phase• In RUNTIME phase – Add services – Add deployment processors
  16. 16. Deployment manager • Deployment repository • Defines deployment phases • Provides deployment processor infrastructure • Can be used via• Can be used via – Domain management – Deployment scanner
  17. 17. Deployment processor • Hooks into deployment lifecycle • Can modify deployment behavior • Can define new deployment type
  18. 18. Extension point • Loaded via Service Loader • Can define many subsystems • Packaged as JBoss Module • Referenced in configuration• Referenced in configuration • Can provide any new functionality
  19. 19. Extension loading standalone.xml <extension module="org.wildfly.extension.sdd"/> ServiceLoader org.jboss.as.controller.Extension org.wildfly.extension.sdd.SDDExtension
  20. 20. WRITING EXTENSIONS
  21. 21. Building blocks • Define Extension point • Define Root Model • Define Add handler • Define XML parser• Define XML parser • Define XML marshaller
  22. 22. Extension class public class UndertowExtension implements Extension { @Override public void initializeParsers(ExtensionParsingContext context) { } @Override@Override public void initialize(ExtensionContext context) { } }
  23. 23. Service Loader entry • Point it to implementation class – org.wildfly.extension.undertow.UndertowExtension
  24. 24. Define root model public class UndertowRootDefinition extends PersistentResourceDefinition { protected static final SimpleAttributeDefinition STATISTICS_ENABLED = new SimpleAttributeDefinitionBuilder("statistics-enabled", ModelType.BOOLEAN, true) .setAllowExpression(true) .setDefaultValue(new ModelNode(false)) .build(); static final UndertowRootDefinition INSTANCE = new UndertowRootDefinition ();static final UndertowRootDefinition INSTANCE = new UndertowRootDefinition (); private SDDRootResource() { super(UndertowExtension.SUBSYSTEM_PATH, UndertowExtension.getResolver(), UndertowSubsystemAdd.INSTANCE, ReloadRequiredRemoveStepHandler.INSTANCE); } @Override public Collection<AttributeDefinition> getAttributes() { return Arrays.asList(ATTRIBUTES); } }
  25. 25. Define root add handler public class UndertowSubsystemAdd extends AbstractBoottimeAddStepHandler { @Override protected void populateModel(ModelNode operation, ModelNode model) throws OperationFailedException { for (AttributeDefinition def : UndertowRootDefinition. .INSTANCE.getAttributes()) { def.validateAndSet(operation, model); }} }
  26. 26. Define namespace enum Namespace { // must be first UNKNOWN(null), UNDERTOW_1_0("urn:jboss:domain:undertow:1.0"); /** * The current namespace version.* The current namespace version. */ public static final Namespace CURRENT = UNDERTOW_1_1; private final String name; Namespace(final String name) { this.name = name; } }
  27. 27. Define XML model <subsystem xmlns="urn:wildfly:domain:undertow:1.0“ statistics-enabled=“true”/>
  28. 28. Define parser class UndertowSubsystemParser_1_0 implements XMLStreamConstants, XMLElementReader<List<ModelNode>> { static final PersistentResourceXMLDescription xmlDescription = builder(UndertowRootDefinition.INSTANCE).build(); @Override@Override public void readElement(XMLExtendedStreamReader reader, List<ModelNode> list) throws XMLStreamException { xmlDescription.parse(reader, PathAddress.EMPTY_ADDRESS, list); } }
  29. 29. Define marshaller public void writeContent(XMLExtendedStreamWriter writer, SubsystemMarshallingContext context) throws XMLStreamException { xmlDescription.persist(writer, context.getModel(), Namespace.CURRENT.getUriString()); }
  30. 30. Making it all work @Override public void initializeParsers(ExtensionParsingContext context) { context.setSubsystemXmlMapping(SUBSYSTEM_NAME, Namespace.UNDERTOW_1_0.getUriString(), UndertowSubsystemParser_1_0.INSTANCE); } @Override public void initialize(ExtensionContext context) {public void initialize(ExtensionContext context) { final SubsystemRegistration subsystem = context.registerSubsystem(SUBSYSTEM_NAME, 1, 0, 0); final ManagementResourceRegistration registration = subsystem.registerSubsystemModel(UnertowRootResource.INSTANCE); subsystem.registerXMLElementWriter(UndertowSubsystemParser.INSTANCE); }
  31. 31. Module definition <module xmlns="urn:jboss:module:1.3" name="org.wildfly.extension.undertoworg.wildfly.extension.undertoworg.wildfly.extension.undertoworg.wildfly.extension.undertow"> <resources> <artifact name="${org.wildfly:wildfly-undertow}"/> </resources> <dependencies> <module name="io.undertow.core" services="import"/> <module name="io.undertow.servlet" services="import"/> <module name="io.undertow.jsp"/> <module name="io.undertow.websocket"/> <module name="javax.api"/><module name="javax.api"/> <module name="javax.servlet.api"/> <module name="javax.servlet.jsp.api"/> <module name="javax.websocket.api"/> <module name="org.jboss.jandex"/> <module name="org.jboss.staxmapper"/> <module name="org.jboss.as.controller"/> <module name="org.jboss.as.server"/> <module name="org.jboss.modules"/> <module name="org.jboss.msc"/> <module name="org.jboss.vfs"/> <module name="org.jboss.logging"/> </dependencies> </module>
  32. 32. What does it do? (almost) nothing!
  33. 33. How to test it? • Test harness enables you to test – xml parser – model consistency – MSC services – Compatibility (transformers) – Localization resources – …
  34. 34. public class UndertowSubsystemTestCase extends AbstractSubsystemBaseTest { public UndertowSubsystemTestCase() { super(“undertow”, new UndertowExtension());super(“undertow”, new UndertowExtension()); } @Override protected String getSubsystemXml() throws IOException { return readResource(“undertow-1.0.xml"); } }
  35. 35. Undertow extension • Multiple servers & hosts per server support • Each server can have multiple listeners • Support AJP, HTTP, HTTPS listeners • Servlet & WebSockets deployments support• Servlet & WebSockets deployments support • SSO • Session Management • Proxy & LB mangament • Filters & content handlers • Predicates • ….
  36. 36. Demo
  37. 37. • http://undertow.io/ • https://github.com/wildfly/wildfly • http://www.wildfly.org/
  38. 38. Questions?

×