boost development with java ee7 on jboss enterprise ... hat_boost development with...boost...

41
#RedHatForumCH Boost development with Java EE7 on JBoss Enterprise Application Platform 7 Dimitris Andreadis EAP Engineering Manager September 13, 2016

Upload: phungduong

Post on 29-Mar-2018

237 views

Category:

Documents


5 download

TRANSCRIPT

#RedHatForumCH

Boost development with Java EE7 onJBoss Enterprise Application Platform 7

Dimitris AndreadisEAP Engineering Manager

September 13, 2016

#RedHatForumCH

About Me

JBoss AS/EAP, WildFly Fan(atic)•2001, JBoss User•2003, JBoss Committer•2004, JBoss Full-time Core Developer•2006, JBoss AS Lead (v3.2.8+, v4.0.4+, v4.2.x, 5.0.x)•2009, JBoss AS Engineering Manager•2013, JBoss EAP/WildFly Sr. Engineering Manager

And before JBoss?●7y experience in distributed systems (telcos, NMS/OSS)●BSc/MSc Computer Science (Athens/Dublin)

about.me/dandreadis

#RedHatForumCH

JBoss EAP 7

#RedHatForumCH

EAP Themes

Lightweight Modular Fast

#RedHatForumCH

Unified Configuration

Web Console JMX

CLI HTTP / JSON

ThirdpartyApps

XML

#RedHatForumCH

Domain Mode

Host 1

HostController

HostController

HostController

HostController

Host 2Server 1Server 1

Server 2Server 2

HostController

HostController

Server 5Server 5

Server 4Server 4

Server Group A

Server Group B

Host 3

Host 4

Server 3Server 3Domain Controller

(master Host Controller)Domain Controller

(master Host Controller)

#RedHatForumCH

WildFly vs JBoss EAP

Open Source Red Hat & Community Resources Rapid Innovation Focus on delivering features

Volunteer community support

Open Source Enterprise Subscription Stability & Compatibility ~ 6 week CPs delivered regularly,

features backported by customerdemand

Industry leading support withguaranteed SLAs

Security certifications and hardening

Open Source Enterprise Subscription Stability & Compatibility ~ 6 week CPs delivered regularly,

features backported by customerdemand

Industry leading support withguaranteed SLAs

Security certifications and hardening

WildFly EAP

#RedHatForumCH

WildFly / EAP Relationship

AS 7.1AS 7.1

EAP 6.1EAP 6.1 EAP 6.2EAP 6.2 EAP 6.3EAP 6.3 EAP 6.4EAP 6.4EAP 6.0EAP 6.0

AS 7.0AS 7.0 AS 7.2AS 7.2

WildFly 8WildFly 8 WildFly 9WildFly 9 WildFly 10WildFly 10

EAP 7.0EAP 7.0 EAP 7.1EAP 7.1

WildFly 11WildFly 11Some Backported Features

#RedHatForumCH

Project vs EE spec vs Product

JBoss AS 2 J2EE 1.2 JBoss AS 3 J2EE 1.3 JBoss AS 4 J2EE 1.4 JBoss EAP 4 JBoss AS 5 Java EE 5 JBoss EAP 5 JBoss AS 6 , AS7 Java EE 6 JBoss EAP 6 WildFly 8, 9, 10 Java EE 7 JBoss EAP 7

#RedHatForumCH

EAP 7 Highlights

100% Java EE7 certified (Web & Full profiles) plus CDI 1.2, WebSockets 1.1 Java SE 8 (OpenJDK, Oracle, IBM and HP JDKs) High Performance Web Server (Undertow) Port reduction (8080, 9990) Reverse Proxy / HTTP/2 HornetQ ActiveMQ Artemis IIOP Implementation switched to OpenJDK ORB CLI Migration Operations (from JBoss Web, JacORB, and HornetQ)

#RedHatForumCH

EAP 7 Highlights (cont.)

HA MDBs & Singleton Deployments Server Suspend Mode/Graceful Shutdown Offline CLI Mode (including Domain mode) Improved UI for large domains Hierarchical Profiles Batch Enhancements Hibernate 5

…and more

#RedHatForumCH

Java EE 7

#RedHatForumCH

Java EE7: Central Themes

Improving Productivity New Web Technologies Better Integration Embracing CDI

#RedHatForumCH

Java EE7 Improvements From Above

#RedHatForumCH

EE7 Highlights – New Techs

JSR-352 Batch Applications for the Java Platform Runtime & Artifact API, XML-based Job specification lang.

JSR-236 Concurrency Utilities for JavaEE Executor, Scheduled Executor, Thread Factory, Context

JSR-353 Java API for JSON Processing (JSON-P) Parse, transform and query JSON data

JSR-356 Web Sockets support Annotation driven endpoints and lifecycle callbacks

#RedHatForumCH

EE7 Highlights – Spec. Updates

JSR-345 EJB 3.2, plus Interceptors 1.2, Annotations 1.2 Misc. improvements

JSR-340 Servlet 3.1 Non-blocking I/O, HTTP upgrade, etc.

JSR-342 JMS 2.0 Shared topic subs, delayed delivery, async send, etc.

JSR-344 JSF 2.2 HTML 5, FaceFlows, Stateless Views, Resource lib contracts

JSR-322 JCA 1.7 Activation name for msg endpoints

#RedHatForumCH

EE7 Highlights – Optional Techs

EJB 2.1 Entity Beans (CMP/BMP) JAX-RPC (API for XML-based RPC) JAXR (API for XML Registries) JSR-88 it has re-surfaced in JSR 373 (JSR-77 successor) JavaTM EE Management API 2.0

#RedHatForumCH

Batch Processing - JSR-352

Based on decades of industry experience Balances transactional integrity and performance Separates responsibilities into reusable components Customizable execution using job specification language

Item Reader

Item Processor

Item Writer

Step

Job Repository

Job Operator Job

#RedHatForumCH

Batch Processing

Item Reader

Item Processor

Item Writer

<job id="job"> <step id="step1"> <chunk item-count=“3”> <reader ref="AccReader"/> <processor ref="AccProcessor"/> <writer ref="AccWriter"/> </chunk> </step></job>

Chunk 1A

Item 1

Item 2

Item 3

Item 1

#RedHatForumCH

Parallelism Using Chunks & Partitions

<chunk item-count=“3”> <reader ref=“AccReader”> <properties> <property name="start" value="#{partitionPlan['start']}"/> <property name="end" value="#{partitionPlan['end']}"/> </properties> </reader> <processor ref="AccProcessor"/> <writer ref=“AccWriter"/> </chunk> <partition> <plan partitions=“2”> <properties partition="0"> <property name="start" value="1"/> <property name="end" value="10"/> </properties> ... </partition>

Job XML

Chunk 1A

Item 1

Item 2

Item 3

Chunk 2A

Item 4

Item 5

Item 6

Chunk 1B

Item 11

Item 12

Item 13

Chunk 2B

Item 14

Item 15

Item 16

Thread 1 Thread 2

#RedHatForumCH

Starting a Job

Easily called from a Servlet or an EJB or common shared code Can also abort and resume jobs

JobOperator jobOperator = BatchRuntime.getJobOperator();Properties props = new Properties();props.setProperty(...)long id = jobOperator.start(JOB_NAME, props);

#RedHatForumCH

EE Concurrency

Adds Java EE variants of SE Executors ManagedExecutorService ManagedScheduledExecutorService ManagedThreadFactory

Provides Contextual Proxies ContextService

Supports Task listeners in addition to futures Supports UserTransaction

#RedHatForumCH

Simple Executor Example

@ResourceManagedExecutorService executor;Future res;

void startSearch() { res = executor.submit(new Callable<Long>() { public long call() { return findNeedleInHaystack(); } });} long waitForNeedle() { return res.get();}

#RedHatForumCH

Context Servicepublic interface MessageProcessor { public void process(Message msg);}

public class UserUpdate implements MessageProcessor { public void process(Message msg) { // requires user’s principal to update updateUserLastMessageTime(msg); } }// On Servletpublic void doPost() { ... MessageProcessor callback = service.createContextualProxy(new UserUpdate(), execProps, MessageProcessor.class); producer.send(dest, session.createObjectMessage(callback));} public class ProcessingMDB { public void onMessage(Message msg) { ObjectMessage omsg = (ObjectMessage)msg; ((MessageProcessor)omsg.getObject()).process(); }}

#RedHatForumCH

JMS 2.0 - API Simplification

@Inject JMSContext context;@Resource(lookup=”java:module/myqueue”) Queue queue;

void sendSomething(String data) { context.createProducer().send(queue, data);}

#RedHatForumCH

JMS 2: Shared Subscriptions

ProducerProducer TopicTopic

Consumer Job AConsumer Job A

Shared Sub BShared Sub B

Consumer Job B 1Consumer Job B 1

Consumer Job B 2Consumer Job B 2

Consumer Job B 3Consumer Job B 3

Message 1 - Job AMessage 1 - Job A

Message 2 - Job BMessage 2 - Job B

Message 3 - Job BMessage 3 - Job B

Consumer Job AConsumer Job AMessage 1 - Job AMessage 1 - Job A

#RedHatForumCH

JAX-RS 2 Client API

Client client = ClientBuilder.newClient(); WebTarget target = client.target(“.../people"); Person p = target .path("{id}") .resolveTemplate("id", "1") .request(MediaType.APPLICATION_XML) .get(Person.class);

GET /people/1 HTTP/1.1Accept: application/xml

#RedHatForumCH

JSON API (JSR 353): DOM-Like API

JsonObject jsonObject = Json.createObjectBuilder() .add("apple", "red") .add("banana", "yellow") .build(); StringWriter w = new StringWriter();JsonWriter writer = Json.createWriter(w); writer.write(jsonObject);

JsonReader reader = Json.createReader(…);JSonObject jsonObject = (JsonObject)reader.read();

#RedHatForumCH

JSON API (JSR 353): StAX-Like API

JsonParser parser = Json.createParser(new StringReader(jsonData));while (parser.hasNext()) { JsonParser.Event event = parser.next(); switch(event) { case START_OBJECT: System.out.println("Name = " + parser.getString()); break; case KEY_NAME: System.out.println("Key = " + parser.getString()); break;

case VALUE_STRING: System.out.println("Value = " + parser.getString()); break;

}}

#RedHatForumCH

CDI Everywhere

Automatic enablement for beans with scope annotation and EJBs “beans.xml” is optional Bean discovery mode all: All types annotated: Types with bean defining annotation none: Disable CDI

@Vetoed for programmatic disablement of classes Global ordering/priority of interceptors and decorators

#RedHatForumCH

Web Sockets Overview

Full-duplex Communication Framed Messages Binary and Text Messages Supports Fragmentation

#RedHatForumCH

JS Web Socket Client Example

var socket = new WebSocket(“ws://www.example.com/websocket/johndoe“);

// Every message we get, dump it to the logsocket.onmessage = function (event) { console.log(event.data);}

// Send a text messageexampleSocket.send(“Hi There!”);

#RedHatForumCH

Web Sockets - Server Endpoint (Text Messages)

@ServerEndpoint("/websocket/{name}") //note the URL template.public class HelloEndpoint {

@OnOpen //invoked when the client first connects public void onOpen(final Session session) { session.getAsyncRemote().sendText("hi"); }

@OnMessage //handles text messages public String message(String message, @PathParam("name") String name) { return "Hello " + name + " you sent" + message; }}

#RedHatForumCH

Web Sockets - Server Endpoint (Binary Messages)

@ServerEndpoint("/websocket/{name}") //note the URL template.public class HelloEndpoint {

@OnMessage //handles binary messages public byte[] binaryMessage(byte[] binaryMessage) { return binaryMessage; //echo binary data }

@OnClose //invoked when the connection is closed public void onClose(final Session session) { System.out.println("Connection closed"); }}

#RedHatForumCH

Web Socket - Client Connections

ServerContainer sc = (ServerContainer)servletContext.getAttribute("javax.websocket.server.ServerContainer");

Session session = sc.connectToServer(AnnotatedClientEndpoint.class, new URI("ws://example.com/chat"));

Future<Void> future = session.getAsyncRemote() .sendText("Hello Websocket");

#RedHatForumCH

Web Socket - Client Endpoint

@ClientEndpointpublic class AnnotatedClientEndpoint {

@OnOpen public void onOpen(final Session session) { session.getAsyncRemote().sendText("hi"); }

@OnMessage public void onMessage(final String message, final Session session) { System.out.println(message); }}

#RedHatForumCH

Servlet 3.1

Non-Blocking Listeners Improved Async Processing

Custom Http Upgrade Support Security enhancements

#RedHatForumCH

Non-Blocking Async Example

protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException { final AsyncContext context = req.startAsync(); final ServletOutputStream outputStream = resp.getOutputStream(); final String[] messages = {"Hello ", "async ", "world"}; outputStream.setWriteListener(new WriteListener() { int pos = 0; @Override public synchronized void onWritePossible() throws IOException { while (outputStream.isReady() && pos < messages.length()) { outputStream.write(messages[pos++].getBytes()); } if (pos == messages.length()) context.complete(); } });}

#RedHatForumCH

Beyond Servlet - HTTP Handlers

public class HelloWorldHandler implements HttpHandler { @Override public void handleRequest(final HttpServerExchange exchange) throws Exception { exchange.getResponseHeaders() .put(Headers.CONTENT_TYPE, "text/plain"); exchange.getResponseSender() .send("Hello World"); }}

#RedHatForumCH

Beyond Servlet - HTTP Handlers

public class MyBlockingHandler implements HttpHandler { @Override public void handleRequest(final HttpServerExchange exchange) throws Exception { if (exchange.isInIoThread()) { exchange.dispatch(this); return; } // Do blocking stuff }}

#RedHatForumCH

More Resources

Download EAP 7 For Free http://www.jboss.org/products/eap/download/

Check out the documentation https://access.redhat.com/documentation/en/red-hat-jboss-enterprise-application-pla

tform/