77
(ARCHITECTING WEB APPLICATIONS WITHOUT GWT-USER) Beyond GWT 3.0 Panic

GWTcon 2015 - Beyond GWT 3.0 Panic

Embed Size (px)

Citation preview

Page 1: GWTcon 2015 - Beyond GWT 3.0 Panic

(ARCHITECTING WEB APPLICATIONS WITHOUT GWT-USER)

Beyond GWT 3.0 Panic

Page 2: GWTcon 2015 - Beyond GWT 3.0 Panic

Cristiano Costantini @cristcost +CristianoCostantini http://lnkdin.me/p/cristianocostantini

Page 3: GWTcon 2015 - Beyond GWT 3.0 Panic

GWT and ServiceMix project: 270K LoC, 5500 classes, more than 200 Maven modules

Page 4: GWTcon 2015 - Beyond GWT 3.0 Panic

GWT MEET-UP 2015“GWT 2.8 and Beyond” , by Ray Cromwel l , Goktug Gokdogan

Page 5: GWTcon 2015 - Beyond GWT 3.0 Panic
Page 6: GWTcon 2015 - Beyond GWT 3.0 Panic
Page 7: GWTcon 2015 - Beyond GWT 3.0 Panic

OK… WHAT DO WE DO NOW?

Page 8: GWTcon 2015 - Beyond GWT 3.0 Panic
Page 9: GWTcon 2015 - Beyond GWT 3.0 Panic

STOP USING GWT?

Page 10: GWTcon 2015 - Beyond GWT 3.0 Panic

No, I want to reuse Java in Web Appl icat ions , mobi le platforms and off-

course in the Java Backend

STOP USING GWT?

Page 11: GWTcon 2015 - Beyond GWT 3.0 Panic

1st. remove GWT-User from dependencies

2nd. don’t use JSNI, use JsInterop

3rd. don’t use Widgets, use Polymer

4th. don’t use IDE plugins*

5th. don’t use GWT RPC

Experiments Checklist:

Page 12: GWTcon 2015 - Beyond GWT 3.0 Panic

1st. remove GWT-User from dependencies

2nd. don’t use JSNI, use JsInterop

3rd. don’t use Widgets, use Polymer

4th. don’t use IDE plugins*

5th. don’t use GWT RPC

LET’S PUT IT INTO PRACTICE

Experiments Checklist:

Page 13: GWTcon 2015 - Beyond GWT 3.0 Panic

INTRODUCING WUnit an example application to test our

survival strategy

Page 14: GWTcon 2015 - Beyond GWT 3.0 Panic

INTRODUCING WUNIT

Page 15: GWTcon 2015 - Beyond GWT 3.0 Panic

WUNIT IS A UNIT TEST FRAMEWORK FOR…

INTRODUCING WUNIT

Page 16: GWTcon 2015 - Beyond GWT 3.0 Panic

WUNIT IS A UNIT TEST FRAMEWORK FOR…

INTRODUCING WUNIT

…WARHAMMER, THE GAME

Page 17: GWTcon 2015 - Beyond GWT 3.0 Panic

Testing which “Unit” is the best is really slow

Page 18: GWTcon 2015 - Beyond GWT 3.0 Panic

Testing needs throwing a lot of dice

Page 19: GWTcon 2015 - Beyond GWT 3.0 Panic

Using the “Assault Dice” app…

…solves only part of the problem

Page 20: GWTcon 2015 - Beyond GWT 3.0 Panic

SO IT CAME

WUnit

Page 21: GWTcon 2015 - Beyond GWT 3.0 Panic

DEMO

Page 22: GWTcon 2015 - Beyond GWT 3.0 Panic

MANUAL

DICE APP

WUNIT

0 12,5 25 37,5 50

BENCHMARK

(Minutes to test two units)

Page 23: GWTcon 2015 - Beyond GWT 3.0 Panic

AT FIRST WUNIT IS BORN WITH THIS ARCHITECTURE

CONSOLE ENGINE MODEL

POJOJavaSystem.out

Page 24: GWTcon 2015 - Beyond GWT 3.0 Panic

THE VALUE OF USING JAVA TO IMPLEMENT THE GAME LOGIC

ENGINE

JavaThis code is so much complex

(Warhammer rules are so) that I wouldn’t attempt to write it without a full OOP language with solid development tools

Page 25: GWTcon 2015 - Beyond GWT 3.0 Panic

THE VALUE OF USING JAVA TO IMPLEMENT THE GAME LOGIC

ENGINE

JavaThis code is so much complex

(Warhammer rules are so) that I wouldn’t attempt to write it without a full OOP language with solid development tools

Page 26: GWTcon 2015 - Beyond GWT 3.0 Panic

THE VALUE OF USING JAVA TO IMPLEMENT THE GAME LOGIC

ENGINE

JavaThis code is so much complex

(Warhammer rules are so) that I wouldn’t attempt to write it without a full OOP language with solid development tools

Page 27: GWTcon 2015 - Beyond GWT 3.0 Panic

THE VALUE OF USING JAVA TO IMPLEMENT THE GAME LOGIC

ENGINE

JavaThis code is so much complex

(Warhammer rules are so) that I wouldn’t attempt to write it without a full OOP language with solid development tools

Page 28: GWTcon 2015 - Beyond GWT 3.0 Panic

WUnit ’s Engine is implemented in Java

Developed with strong TDD (coverage is about 93.6%)

REUSE - REUSE - REUSE

Page 29: GWTcon 2015 - Beyond GWT 3.0 Panic

AIM CROSS-PLATFORMCONSOLE

ENGINE MODEL

POJOJava

System.out

WEB

ANDROID

GWT/j2cl

Android

iOS

j2objc

Page 30: GWTcon 2015 - Beyond GWT 3.0 Panic

…AND THEN I WANTED TO TO BUILD AN USER INTERFACE FOR WUNIT:

HOW DID I DID IT?

(Singular not avai lable)

Page 31: GWTcon 2015 - Beyond GWT 3.0 Panic

HOW TO USE GWT AND NOT GWT-USER

(Experiments made with WUnit prototype)

Page 32: GWTcon 2015 - Beyond GWT 3.0 Panic

ARCHITECTING WEB APPLICATIONS FOR REUSE

VIEW INPUT

PRESENTER ENGINE MODEL

VIEW OUTPUT

written with POJO

written in (pure) Java

written in GWT/JS

written in Polymer

Note: Engine and Model are compiled to Javascript and run on the browser

thanks to javaemul !

Page 33: GWTcon 2015 - Beyond GWT 3.0 Panic

REMOVE GWT-USER FROM DEPENDENCIES1st

Page 34: GWTcon 2015 - Beyond GWT 3.0 Panic

…but i t comes the f irst fai lure!

JsInterop annotat ions and EntryPoint interface are ins ide GWT-user.

REMOVE GWT-USER FROM DEPENDENCIES1st

Page 35: GWTcon 2015 - Beyond GWT 3.0 Panic

…but i t comes the f irst fai lure!

JsInterop annotat ions and EntryPoint interface are ins ide GWT-user.

Then, just avoid using anything else from GWT-user…

REMOVE GWT-USER FROM DEPENDENCIES1st

Page 36: GWTcon 2015 - Beyond GWT 3.0 Panic

…and avoid inher i t ing “User” module in your .gwt.xml

Page 37: GWTcon 2015 - Beyond GWT 3.0 Panic

-- TO GWT STEERING COMMITTEE --

please create an independent library

with EntryPoint and JsInterop interfaces

so we can remove GWT-User from dependencies

Page 38: GWTcon 2015 - Beyond GWT 3.0 Panic

Polymer is cool ! Write the widgets in javascr ipt

DON'T USE WIDGETS, USE POLYMER

2nd

Page 39: GWTcon 2015 - Beyond GWT 3.0 Panic
Page 40: GWTcon 2015 - Beyond GWT 3.0 Panic
Page 41: GWTcon 2015 - Beyond GWT 3.0 Panic
Page 42: GWTcon 2015 - Beyond GWT 3.0 Panic

…displays as a table’s row on the browser

The custom HTML element…

Page 43: GWTcon 2015 - Beyond GWT 3.0 Panic

<wunit-dice> elem

ent

Page 44: GWTcon 2015 - Beyond GWT 3.0 Panic

<wunit-dice> elem

ent

Aspect

Page 45: GWTcon 2015 - Beyond GWT 3.0 Panic

<wunit-game> elem

ent

Page 46: GWTcon 2015 - Beyond GWT 3.0 Panic

<wunit-game> elem

ent

Aspect

Page 47: GWTcon 2015 - Beyond GWT 3.0 Panic

@JsTypeUSE JsInterop

3rd

Page 48: GWTcon 2015 - Beyond GWT 3.0 Panic

@JsTypeUSE JsInterop

3rd

* Note: this WUnit prototype has used the OLD JsInterop annotations

Page 49: GWTcon 2015 - Beyond GWT 3.0 Panic

HTM

L H

OST

PAG

E

Page 50: GWTcon 2015 - Beyond GWT 3.0 Panic

LINK FROM GWT TO HOST PAGE

Page 51: GWTcon 2015 - Beyond GWT 3.0 Panic

LINK FROM GWT TO HOST PAGE

Fail! I had to use JSNI (but it is limited to invoking query selector from Java, and it can be rewritten with the new JsInterop)

Page 52: GWTcon 2015 - Beyond GWT 3.0 Panic

OUTPUT FROM JAVA TO POLYMER ELEMENTS

VIEW OUTPUT

Polymer

Page 53: GWTcon 2015 - Beyond GWT 3.0 Panic

OUTPUT FROM JAVA TO POLYMER ELEMENTS

VIEW OUTPUT

Polymer

Page 54: GWTcon 2015 - Beyond GWT 3.0 Panic

INPUT FROM POLYMER ELEMENTS TO JAVA

Polymer

VIEW INPUT

Page 55: GWTcon 2015 - Beyond GWT 3.0 Panic

INPUT FROM POLYMER ELEMENTS TO JAVA

Polymer

VIEW INPUT

Page 56: GWTcon 2015 - Beyond GWT 3.0 Panic

DON'T USE IDE PLUGINS 4th

Page 57: GWTcon 2015 - Beyond GWT 3.0 Panic

Unfortunately this so lut ion does not works standalone…

I 've hacked extensively the CodeServer

*

Page 58: GWTcon 2015 - Beyond GWT 3.0 Panic

Unfortunately this so lut ion does not works standalone…

I 've hacked extensively the CodeServer

HACKS-HACKS-HACKS*

Page 59: GWTcon 2015 - Beyond GWT 3.0 Panic

<add-linker name="sso" />

FOCUS: SSO LINKER

Page 60: GWTcon 2015 - Beyond GWT 3.0 Panic

<add-linker name="sso" />

FOCUS: SSO LINKER

Page 61: GWTcon 2015 - Beyond GWT 3.0 Panic

-- TO GWT STEERING COMMITTEE --

please make Code Server more modular and reusable so we

can use it this approach without hacks

Page 62: GWTcon 2015 - Beyond GWT 3.0 Panic

This problem is not solved yet (WUnit don't uses c l ient-server communicat ion)

Work in progress It would be poss ible to implement a c lean approach if GWT was support ing GSON or

if the javaemul was support ing (a more r ich subset of) Java Ref lect ion

DON'T USE GWT RPC5th

Page 63: GWTcon 2015 - Beyond GWT 3.0 Panic

-- TO GWT STEERING COMMITTEE --

please create an independent and modular library

with the javaemul, so it can be extended in a clean way

Page 64: GWTcon 2015 - Beyond GWT 3.0 Panic

CONCLUSIONS:

Page 65: GWTcon 2015 - Beyond GWT 3.0 Panic

How much GWT-User have we used in WUnit?

Page 66: GWTcon 2015 - Beyond GWT 3.0 Panic

How much GWT-User have we used in WUnit?

Instrument for

coverage

Page 67: GWTcon 2015 - Beyond GWT 3.0 Panic

How much GWT-User have we used in WUnit?

Compile, including

gwt:compile

Page 68: GWTcon 2015 - Beyond GWT 3.0 Panic

How much GWT-User have we used in WUnit?

Execute JettyEmbeddedServer

(including Code Server)

Page 69: GWTcon 2015 - Beyond GWT 3.0 Panic

How much GWT-User have we used in WUnit?

* Open and run the app (to trigger Code Server compilation)

Page 70: GWTcon 2015 - Beyond GWT 3.0 Panic

How much GWT-User have we used in WUnit?

Generate coverage

report

Page 71: GWTcon 2015 - Beyond GWT 3.0 Panic

COVERAGE REPORT WUNIT (GWT Compilation and Code Server execution)

Page 72: GWTcon 2015 - Beyond GWT 3.0 Panic

+ SUPER SOURCES

Page 73: GWTcon 2015 - Beyond GWT 3.0 Panic

+ SUPER SOURCES

Page 74: GWTcon 2015 - Beyond GWT 3.0 Panic

J2CL ?

FUTURE:

Page 75: GWTcon 2015 - Beyond GWT 3.0 Panic

Maven archetype or Template for this approach

https ://github.com/codejuicer/gwt-s l immize

(release after some c lean up and off ic ia l gwt 2.8 .0)

Page 76: GWTcon 2015 - Beyond GWT 3.0 Panic

Career Website: https ://www.thalesgroup.com/en/homepage/careers

Jobs info: cv.r [email protected]

INTERESTED WORKING IN MY TEAM?

Page 77: GWTcon 2015 - Beyond GWT 3.0 Panic

THANKS