Spring ME JavaOne

49
Spring ME Unleashing Spring to the Rest of the Platform Wilfred Springer Xebia, The Netherlands

description

Slides of the BOF on Spring ME.

Transcript of Spring ME JavaOne

Page 1: Spring ME JavaOne

Spring MEUnleashing Spring to the Rest of the Platform

Wilfred SpringerXebia, The Netherlands

Page 2: Spring ME JavaOne

Audience

Page 3: Spring ME JavaOne

3

Agenda

> Why this talk?> Why Spring?> Why not Spring?> How Spring?> Under the hood> Alternatives> Current status & what's next?> Discussion

Page 4: Spring ME JavaOne

4

Java is doing AWESOME!

Source: Tiobe Programming Community Index March

Page 5: Spring ME JavaOne

5

Spring is doing GREAT!

Source: Evans Data, 2008

+ =

Page 6: Spring ME JavaOne

6

But that's like... a freaking big number

Page 7: Spring ME JavaOne

7

… or is it?

SAN MATEO, Calif.—November 19, 2008 – SpringSource, a leading provider of infrastructure software and the company behind Spring, the de facto standard in enterprise Java, today announced that results from an extensive Evans Data research study reveal large scale adoption and penetration of Spring as a means of increasing developer productivity and

combating complexity in today’s enterprise application infrastructure market.

Page 8: Spring ME JavaOne

8

Java Nodes in the Cloud

> 3 Billion Java-Enabled Cards in 2007> 1.8 Billion Java-Enabled Phones in 2007> 7 Million Java Set-top Boxes> 1 Million GWT downloads in 2007> Sun SPOT> Livescribe Smartpen

Page 9: Spring ME JavaOne

9

Not all men are equal

versus

Page 10: Spring ME JavaOne

10

Spring ME Manifesto

“We hold these truths to be self-evident, that all men … Java Developers are entitled to get

their portion of Spring goodness.”

Not just Java EE developersNot just Java SE developers

But also Java ME, GWT developers and Java Card developers

Page 11: Spring ME JavaOne

11

Why Spring?

Page 12: Spring ME JavaOne

12

IoC/Dependency Injection

“Trust us, we know what we're doing.”“Don't call us, we call you.”

Instead of this Take hard-wired dependencies out

And have a frameworkconnect them together

Page 13: Spring ME JavaOne

AOP (Cross-cutting behavior)

Page 14: Spring ME JavaOne

Sanitized API

“Any problem in computer science can be solved with another layer of indirection.”

– David Wheeler

Page 15: Spring ME JavaOne

15

Why not Spring?

Page 16: Spring ME JavaOne

So why not have Spring?

Platform Limitations> Limited Java Runtime capabilities> Limitations imposed by deployment> Limited computational resources

● Limitations on heap● Limitations on application size● Limitations on performance

Page 17: Spring ME JavaOne

Java Runtime Limitations

GWT n n n y y yJava ME y y n y y nJava Card n n n n n n

Class.fo

rName(..

.)

Class.newInsta

nce()

Other java

.lang.re

flect

java.la

ng.Strin

g

char

java.util.

List

BeanFactory#getBean(String name)?BeanFactory#getBean(char[] name)?

Page 18: Spring ME JavaOne

Deployment Limitations

<bean id=”movie1” class=”sample.Movie”> <property name=”title” value=”Into the Wild”/></bean>

package com.mgm;

public class Movie { void setTitle(String title);}

package a.b;

public class a { void a(String ...);}

<bean id=”movie1” class=”a.b.a”> <property name=”a” value=”Into the Wild”/></bean>

OBFUSCATION

1

2 3

4

Page 19: Spring ME JavaOne

Heap

> Java SE● Max heap approx. 1.5 GB

> Java ME● Lower bound max. heap: 140 KB● Upper bound max. heap: 128 MB● Between factor 11 and 11,714 difference

> Java Card● 16 K RAM

Page 20: Spring ME JavaOne

Application Size

> Java ME: Upperbounds between 64 KB and 28 MB

Spring Core 267KBSpring Beans 467KBSpring Context 455KBTotal 1189KB

Page 21: Spring ME JavaOne

Throughput

> Nokia E71:● 369 MHz ARM 11 CPU

> Gameboy Advance● 16 MHz ARM 7 CPU● C-Ray Raytracing Benchmark 296108 s

> Dell PowerEdge M710● 2.4 GHz Xeon Quad Core CPU● C-Ray Raytracing Benchmark 201 s

Page 22: Spring ME JavaOne

22

How Spring?

Page 23: Spring ME JavaOne

23

Introducing Spring ME's IoC

Page 24: Spring ME JavaOne

24

Introducing Spring ME's IoC

Do most of the hard work at build time

Page 25: Spring ME JavaOne

25

Suppose this is the object model

Page 26: Spring ME JavaOne

26

And you want to create these instances

Page 27: Spring ME JavaOne

27

Then this is the Spring ME Configuration<beans xmlns=”…”> <bean id=”movieFinder” class=”….InMemoryMovieFinder”> <property name=”movies”> <list> <bean class=”….Movie”> <property name=”title” value=”Bye Bye Blue Bird”/> <property name=”director” value=”Søren Kragh-Jacobsen”/> <property name=”year” value=”1999”/> </bean> … </list> </property> </bean></beans>

Page 28: Spring ME JavaOne

28

With this Maven plugin configuration<project> <build> <plugins> <plugin> <groupId>me.springframework</groupId> <artifactId>spring-me-maven-plugin</artifactId> <version>1.0</version> <executions> <execution> <goals> <goal>generate</goal> </goals> <configuration> <contextFile>....context.xml</contextFile> <className>com.mgm.BeanFactory</className> </configuration> </execution> </executions>

Page 29: Spring ME JavaOne

29

Generates this BeanFactory

public class BeanFactory { public Object getBean(String name) { if (“movieFinder”.equals(name)) { return getMovieFinder(); } } private final Object getMovieFinder() { … } …}

Page 30: Spring ME JavaOne

30

DEMO

Page 31: Spring ME JavaOne

31

DEMO (Java ME)

> Spring ME on Java ME

Page 32: Spring ME JavaOne

32

DEMO (Java ME)

> A little more Spring alike

Page 33: Spring ME JavaOne

33

DEMO (Java SE)

public interface MinimalBeanFactory{ Object getBean(String name) throws BeansException;}

Page 34: Spring ME JavaOne

34

DEMO (Java SE)

Page 35: Spring ME JavaOne

Additional benefits

> Compile time validation● “Is 10e2 a valid int representation?”● “Is an instance of Boeing747 assignable to a

property of type Airplane?”> Minimal or no runtime dependencies> Superfast (but no benchmarks to verify this)> Small (1K?)

Page 36: Spring ME JavaOne

36

Under the hood

Page 37: Spring ME JavaOne

37

Spring ME Meta Model

Spring XMLConfiguration

Spring MEMeta Model

Spring ME BeanFactory

> Meta Model independent of Spring> Typically Spring XML configuration is used

Page 38: Spring ME JavaOne

38

Other sources?

Spring MEMeta Model

Spring ME BeanFactory

Annotations

@Autowired@PostConstruct@PostDestroy

@ProvidedBy@Inject@ImplementedBy

Spring XMLConfiguration

Page 39: Spring ME JavaOne

39

Spring ME's Meta Model

Page 40: Spring ME JavaOne

40

Spring ME Meta Model Snapshot

Page 41: Spring ME JavaOne

41

Alternatives

Page 42: Spring ME JavaOne

42

Inversion of Control Galore

Rocket GWT y n y y y y y y y y n y n n all y y y n nSpring ME y y y y y y y y y y n n y n l/m y y y y* y*

n y y n n n n n n n n n n n ... y n n y yFall ME n y y n n n n n n n n n n n ... y n n n n

y n y y y y ? y y n y y n n all n y n y ySignal n n y y n n ? n n n n n y n all n y y ? ?

Israfil IoC

GWToolbox

GWTJa

va M

E

Singletons

Prototyp

es

LazyEager

Factory

methods

Init method

Destroy m

ethod

XML config

uration

Annotation con

figuratio

n

Property

placeholders

Spring C

ompatible S

yntax

AliasColle

ctions*

Constructo

r injectio

n

Property

injecti

on

Wire

by name

Autowire by t

ype

Autowire by n

ame

Page 43: Spring ME JavaOne

43

Sanitized API

> Java ME needs a lot more sanity● J2ME Polish is your friend

> Java Card is probably too limited to use wrapper APIs

> GWT is already addressed by a lot of frameworks

Page 44: Spring ME JavaOne

44

AOP

> What about it?> Compile team weaving?> Using the metadata, AOP proxies could be

constructed at build time> The factory could construct instances of these

proxies instead of the actual objects

Page 45: Spring ME JavaOne

45

Current Status and What's Next

Page 46: Spring ME JavaOne

46

Current status

> 'Request' scope

> 'Session' scope

> 'Global session' scope

> BeanFactoryAware, but ...

> BeanPostProcessor (without reflection?)

> BeanFactoryPostProcessor, but ...

> FactoryBean, but ...

Page 47: Spring ME JavaOne

47

If there's only one thing you remember

> “ME” as in “supporting Java ME”> “ME” as in “a microscopic small version of Spring”> Useful for Java ME> Useful for GWT> Useful for Java SE> Potentially useful for Java Card and Java EE

Page 48: Spring ME JavaOne

48

Other than that

> Version 1.0 just released> GPL + Classpath Exception> Integration with J2ME Polish> JSR 296 on ME> http://springframework.me/> [email protected]

Page 49: Spring ME JavaOne

Wilfred Springerwilfred at flotsam.nl

http://springframework.me/