+ All Categories
Home > Technology > JavaCro'14 - Using WildFly core to build high performance web server – Tomaž Cerar

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

Date post: 13-Jan-2015
Category:
Upload: hujak-hrvatska-udruga-java-korisnika-croatian-java-user-association
View: 1,390 times
Download: 2 times
Share this document with a friend
Description:
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)
Popular Tags:
40
Transcript
Page 1: JavaCro'14 - Using WildFly core to build high performance web server – Tomaž Cerar
Page 2: JavaCro'14 - Using WildFly core to build high performance web server – Tomaž Cerar

Using WildFly core to build high

performance web server

Tomaž Cerar, Red Hat

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

Agenda

• Undertow

• WildFly core

• What are extensions

• Write simple extension• Write simple extension

• Undertow extension

• Demo

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

WILDFLY CORE

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

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

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

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

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

Domain management

• Manages configuration

• Backbone for all extensions

• Accessible via

– Extensions– Extensions

– CLI

– Admin console

– DMR clients

– …

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

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

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

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

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

UNDERTOW

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

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

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

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

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

What are extensions?

• Entry point for extending WildFly

• Can provide

– new deployment types

– new model– new model

– services

– resources

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

Domain model definition

• Attributes

• Resources

• Resource tree

– PathElement– PathElement

– Single target (key=value)

– Multi target (key=*)

• Resolvers & multi language support

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

Operation handlers

• Defines operations on resources

• Execution stage

– MODEL

– RUNTIME– RUNTIME

– VERIFY

– DOMAIN

– DONE

• Can be chained

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

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

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

Deployment manager

• Deployment repository

• Defines deployment phases

• Provides deployment processor infrastructure

• Can be used via• Can be used via

– Domain management

– Deployment scanner

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

Deployment processor

• Hooks into deployment lifecycle

• Can modify deployment behavior

• Can define new deployment type

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

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

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

Extension loading

standalone.xml<extension module="org.wildfly.extension.sdd"/>

ServiceLoaderorg.jboss.as.controller.Extension

org.wildfly.extension.sdd.SDDExtension

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

WRITING EXTENSIONS

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

Building blocks

• Define Extension point

• Define Root Model

• Define Add handler

• Define XML parser • Define XML parser

• Define XML marshaller

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

Extension class

public class UndertowExtension implements Extension {@Overridepublic void initializeParsers(ExtensionParsingContext context) {

}

@Override@Overridepublic void initialize(ExtensionContext context) {

}}

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

Service Loader entry

• Point it to implementation class

– org.wildfly.extension.undertow.UndertowExtension

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

Define root modelpublic 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);

}

}

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

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);

}}

}

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

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;

}

}

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

Define XML model

<subsystem xmlns="urn:wildfly:domain:undertow:1.0“ statistics-enabled=“true”/>

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

Define parserclass 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);

}

}

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

Define marshaller

public void writeContent(XMLExtendedStreamWriter writer, SubsystemMarshallingContext context) throws

XMLStreamException {

xmlDescription.persist(writer, context.getModel(), Namespace.CURRENT.getUriString());

}

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

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);

}

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

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>

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

What does it do?

(almost) nothing!

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

How to test it?

• Test harness enables you to test

– xml parser

– model consistency

– MSC services

– Compatibility (transformers)

– Localization resources

– …

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

public class UndertowSubsystemTestCase extends AbstractSubsystemBaseTest {

public UndertowSubsystemTestCase() {super(“undertow”, new UndertowExtension());super(“undertow”, new UndertowExtension());

}

@Overrideprotected String getSubsystemXml() throws IOException {

return readResource(“undertow-1.0.xml");}

}

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

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

• ….

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

Demo

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

• http://undertow.io/

• https://github.com/wildfly/wildfly

• http://www.wildfly.org/

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

Questions?


Recommended