Top Banner
QCon SP @dblevins @tomitribe #JavaEE Java EE: Extendable and Functional David Blevins Tomitribe
28

@dblevins @tomitribe #JavaEE

Jan 06, 2017

Download

Documents

hatram
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: @dblevins @tomitribe #JavaEE

QC

on S

P

@dblevins @tomitribe #JavaEE

Java EE:Extendable and Functional

David BlevinsTomitribe

Page 2: @dblevins @tomitribe #JavaEE

QC

on S

P

@dblevins @tomitribe #JavaEE

Talk Overview

• Part 1: Extensibility• CDI Scopes• Connectors• Java EE 6-7

• Part 2: Functions• New API Opportunities with Java 8• Killing annotations• Shift from Declarative to Programmatic• Java EE 8?

Page 3: @dblevins @tomitribe #JavaEE

QC

on S

P

@dblevins @tomitribe #JavaEE

Part 1: ExtendableCDI Scopes

Page 4: @dblevins @tomitribe #JavaEE

QC

on S

P

@dblevins @tomitribe #JavaEE

Background

• EJB and CDI Alignment• EJB slowly being deprecated• Functionality moving to CDI• CDI significantly more extendable

Page 5: @dblevins @tomitribe #JavaEE

QC

on S

P

@dblevins @tomitribe #JavaEE

CDI and EJB Under the Covers

Page 6: @dblevins @tomitribe #JavaEE

@dblevins @tomitribe #JavaEE

QC

on S

PProxy (Fake)

Proxy (Fake)

Interceptors

Decorators

Instance (Real)

Security

Transaction

Interceptors

Decorators

Instance (Real)

1. Resolution

2. Services

3. Invocation

(Pool)1. Resolution

2. Services

3. Invocation

(Context/Scope)

CDI 1.0 EJB 3.1

Page 7: @dblevins @tomitribe #JavaEE

@dblevins @tomitribe #JavaEE

QC

on S

PProxy (Fake)

Proxy (Fake)

Security

Transaction

Interceptors

Decorators

Instance (Real)

1. Resolution

2. Services

3. Invocation

(Pool)1. Resolution

2. Services

3. Invocation

(Context/Scope)

CDI 1.1 EJB 3.2

Transaction

Interceptors

Decorators

Instance (Real)

Page 8: @dblevins @tomitribe #JavaEE

QC

on S

P

@dblevins @tomitribe #JavaEE

EJB/CDI Lifecycle Lineup

• @Singleton

• same as CDI @ApplicationScoped

• @Stateful

• applies to any CDI Scope, not just @SessionScoped

• @Stateless

• no CDI equivalent

• @RequestScoped sort of close(ish)

Page 9: @dblevins @tomitribe #JavaEE

QC

on S

P

@dblevins @tomitribe #JavaEE

Implementing a Scope

• Create a new Scope Annotation

• Create an implementation of Context

• Register the Scope and Context via an Extension

• Mark the boundaries

• Logical concept

• Always different

Page 10: @dblevins @tomitribe #JavaEE

QC

on S

P

@dblevins @tomitribe #JavaEE

Custom Scope Examples

Page 11: @dblevins @tomitribe #JavaEE

QC

on S

P

@dblevins @tomitribe #JavaEE

http://tomitribe.io/projects/microscoped

Page 12: @dblevins @tomitribe #JavaEE

QC

on S

P

@dblevins @tomitribe #JavaEE

Common Mistakes you will make

• Not putting a beans.xml in your app (Java EE 6)• No CDI for you!

• Not understanding @Typed• Psst, think @Local from EJB• Bites you when using @Produces

• Not understanding what Dependent and NormalScope• Dependent == plain object• NormalScoped == proxied object• Bites you when creating custom scopes

Page 13: @dblevins @tomitribe #JavaEE

QC

on S

P

@dblevins @tomitribe #JavaEE

Part 1: ExtendableConnectors

Page 14: @dblevins @tomitribe #JavaEE

QC

on S

P

@dblevins @tomitribe #JavaEE

Inbound Connectors(aka MDBs)

Page 15: @dblevins @tomitribe #JavaEE

QC

on S

P

@dblevins @tomitribe #JavaEE

The following are all false

• MDBs are for JMS

• MDBs must be asynchronous

• A MessageListener interface has one method which returns ‘void’

• MDBs are always pooled

• MDBs are stateless

Page 16: @dblevins @tomitribe #JavaEE

QC

on S

P

@dblevins @tomitribe #JavaEE

JMS MDB in Java EE 7

Page 17: @dblevins @tomitribe #JavaEE

QC

on S

P

@dblevins @tomitribe #JavaEE

Title Text

• Body Level One• Body Level Two• Body Level Three• Body Level Four• Body Level Five

Page 18: @dblevins @tomitribe #JavaEE

QC

on S

P

@dblevins @tomitribe #JavaEE

Title Text

• Body Level One• Body Level Two• Body Level Three• Body Level Four• Body Level Five

Bad Configuration

Page 19: @dblevins @tomitribe #JavaEE

QC

on S

P

@dblevins @tomitribe #JavaEE

Title Text

• Body Level One• Body Level Two• Body Level Three• Body Level Four• Body Level Five

Boiler Plate

Page 20: @dblevins @tomitribe #JavaEE

QC

on S

P

@dblevins @tomitribe #JavaEE

Title Text

• Body Level One• Body Level Two• Body Level Three• Body Level Four• Body Level Five

Only Useful Line of Code

Page 21: @dblevins @tomitribe #JavaEE

QC

on S

P

@dblevins @tomitribe #JavaEE

JMS MDB in Java EE 8

Page 22: @dblevins @tomitribe #JavaEE

QC

on S

P

@dblevins @tomitribe #JavaEE

Oh yeah.

Page 23: @dblevins @tomitribe #JavaEE

QC

on S

P

@dblevins @tomitribe #JavaEE

Custom Connector Examples

Page 24: @dblevins @tomitribe #JavaEE

QC

on S

P

@dblevins @tomitribe #JavaEE

https://tomitribe.io/projects/chatterbox

https://tomitribe.io/projects/sheldon

Page 25: @dblevins @tomitribe #JavaEE

QC

on S

P

@dblevins @tomitribe #JavaEE

Part 2: Functional(Ideas for the Future)

Page 26: @dblevins @tomitribe #JavaEE

QC

on S

P

@dblevins @tomitribe #JavaEE

Eras of Java EE

• 1998 (start)• 2001 (strong) • 2006 (start)

• 2009 (strong)• 2014* (start)

• ???? (strong)

XML Annotation Lambda

Page 27: @dblevins @tomitribe #JavaEE

QC

on S

P

@dblevins @tomitribe #JavaEE

Opportunity for Impact

• From Declarative to Programmatic• From Component-side to Caller-side• Large decrease in annotation and class overhead• Logic is mobileImpact of Opportunity• Potential Growth in mixed container and “API” code• Lifecycle compromises might need to be made• Will take time and effort (join in!)

Page 28: @dblevins @tomitribe #JavaEE

QC

on S

P

@dblevins @tomitribe #JavaEE

Thank You!