boldly go where the java programming language has never gone before

85
Boldly go where the Java programming language has never gone before Geert Bevin, Senior Developer, Terracotta Inc. TS-6213

Upload: elliando-dias

Post on 12-May-2015

2.702 views

Category:

Technology


4 download

TRANSCRIPT

Page 1: Boldly go where the Java programming language has never gone before

Boldly gowhere the Java programming languagehas never gone before

Geert Bevin, Senior Developer, Terracotta Inc.

TS-6213

Page 2: Boldly go where the Java programming language has never gone before

2008 JavaOneSM Conference | java.sun.com/javaone | 2

Learn that you don't have to master new languages, tools and libraries to deliver applications that go much further than what the standard Java™ Platform provides

Page 3: Boldly go where the Java programming language has never gone before

2008 JavaOneSM Conference | java.sun.com/javaone | 3

Who is Geert Bevin?

senior developer at Terracotta (http://terracotta.org)founder of Uwyn (http://uwyn.com)founder of RIFE (http://rifers.org)contributor to many open-source projects:Terracotta, RIFE, OpenLaszlo, Gentoo Linux,Bla-bla List, Drone, ...Sun Java Championcreator of native Java language continuationsbiker and gamer

Page 4: Boldly go where the Java programming language has never gone before

2008 JavaOneSM Conference | java.sun.com/javaone | 4

Agenda

Java programming language != Java Virtual Machine (JVM™) != Java platformTerracottaRIFE ContinuationsGoogle Web ToolkitGoogle Android

Page 5: Boldly go where the Java programming language has never gone before

2008 JavaOneSM Conference | java.sun.com/javaone | 5

Key differences

The Java programming language provides a syntax that allows the expression of application logicThe JVM provides a runtime environment that abstracts away the operating system and hardware differencesThe Java platform bundles the Java programming language and the JVM with tools and libraries to provide a complete development and runtime solution

Page 6: Boldly go where the Java programming language has never gone before

2008 JavaOneSM Conference | java.sun.com/javaone | 6

Different purposes

The Java programming language is for developmentThe JVM is for the execution of byte codeThe Java platform provides javac which compiles Java code to byte code

Page 7: Boldly go where the Java programming language has never gone before

2008 JavaOneSM Conference | java.sun.com/javaone | 7

This is what you use every day …

Page 8: Boldly go where the Java programming language has never gone before

2008 JavaOneSM Conference | java.sun.com/javaone | 8

… but it doesn’t have tobe this way

Page 9: Boldly go where the Java programming language has never gone before

2008 JavaOneSM Conference | java.sun.com/javaone | 9

You can change the language

Another language can be used for developmentFor example:• Groovy• JavaFX™ script• Scala• JRuby• Jython• ...

Page 10: Boldly go where the Java programming language has never gone before

2008 JavaOneSM Conference | java.sun.com/javaone | 10

You can change the tooling

Another tool can be used to create byte codeFor example:• ASM• AspectJ• BCEL• groovyc• ...

Page 11: Boldly go where the Java programming language has never gone before

2008 JavaOneSM Conference | java.sun.com/javaone | 11

You can change the runtime

Another runtime can be used to execute your logicFor example:• GCJ• Web browser• Dalvik virtual machine• …

Page 12: Boldly go where the Java programming language has never gone before

2008 JavaOneSM Conference | java.sun.com/javaone | 12

Today’s focus

Any variation on this theme is possibleAny of the layers can be replaced, extended or modifiedToday we'll focus on the Java programming language as the constant

Page 13: Boldly go where the Java programming language has never gone before

2008 JavaOneSM Conference | java.sun.com/javaone | 13

Disclaimer

The technologies in this presentation are being covered from a 'boldness' perspective. No judgment is made on

whether they're a good solution nor how they compare to alternatives. This presentation is also not intended to be a

comprehensive overview of their capabilities

Page 14: Boldly go where the Java programming language has never gone before

2008 JavaOneSM Conference | java.sun.com/javaone | 14

Agenda

Java programming language != JVM != Java platformTerracottaRIFE ContinuationsGoogle Web ToolkitGoogle Android

Page 15: Boldly go where the Java programming language has never gone before

2008 JavaOneSM Conference | java.sun.com/javaone | 15

Agenda

Java programming language != JVM != Java platformTerracottaRIFE ContinuationsGoogle Web ToolkitGoogle Android

Page 16: Boldly go where the Java programming language has never gone before

2008 JavaOneSM Conference | java.sun.com/javaone | 16

What is Terracotta?

Open Source Clustering for the Java Platform

Scalability and Availability for the JVM

Page 17: Boldly go where the Java programming language has never gone before

2008 JavaOneSM Conference | java.sun.com/javaone | 17

Terracotta Overview

Page 18: Boldly go where the Java programming language has never gone before

2008 JavaOneSM Conference | java.sun.com/javaone | 18

Terracotta’s approach

'Regular' Clustering• Scale out is complex• Requires custom Java code

Different approach• Cluster the JVM software• Eliminate need for custom

code

Page 19: Boldly go where the Java programming language has never gone before

2008 JavaOneSM Conference | java.sun.com/javaone | 19

Main features

Heap level replication• Declarative• No serialization• Fine grained / field Level• Only where resident

Large virtual heaps• As large as available disk• Dynamic paging

JVM coordination• Distributed synchronized• Distributed wait()/notify()• Fine grained locking

Management• Runtime visibility• Data introspection• Cluster monitoring

Page 20: Boldly go where the Java programming language has never gone before

2008 JavaOneSM Conference | java.sun.com/javaone | 20

Terracotta Essential FeaturesAnimation

Page 21: Boldly go where the Java programming language has never gone before

2008 JavaOneSM Conference | java.sun.com/javaone | 21

Terracotta Examples

Page 22: Boldly go where the Java programming language has never gone before

2008 JavaOneSM Conference | java.sun.com/javaone | 22

Example of shared stateHello World

Page 23: Boldly go where the Java programming language has never gone before

2008 JavaOneSM Conference | java.sun.com/javaone | 23

Hello World- tutorial/HelloWorld.java

Page 24: Boldly go where the Java programming language has never gone before

2008 JavaOneSM Conference | java.sun.com/javaone | 24

Hello World - tc-config.xml

Page 25: Boldly go where the Java programming language has never gone before

2008 JavaOneSM Conference | java.sun.com/javaone | 25

Demo Terracotta Shared StateHello World

Page 26: Boldly go where the Java programming language has never gone before

2008 JavaOneSM Conference | java.sun.com/javaone | 26

Hello World - trying it out

Start the server:$ start-tc-server.shStart a client:$ dso-java.sh -Dtc.config=tc-config.xmltutorial.HelloWorldOutput:Hello Thu Dec 13 17:46:58 CET 2007After starting the 2nd client:Hello Thu Dec 13 17:46:58 CET 2007Hello Thu Dec 13 17:47:06 CET 2007The state is preserved in the server between executions

Page 27: Boldly go where the Java programming language has never gone before

2008 JavaOneSM Conference | java.sun.com/javaone | 27

Example of coordinationEnhanced Hello World

using java.util.concurrent

Page 28: Boldly go where the Java programming language has never gone before

2008 JavaOneSM Conference | java.sun.com/javaone | 28

Coordination - HelloWorldConcurrent.java

Page 29: Boldly go where the Java programming language has never gone before

2008 JavaOneSM Conference | java.sun.com/javaone | 29

Coordination - tc-config-concurrent.xml

Page 30: Boldly go where the Java programming language has never gone before

2008 JavaOneSM Conference | java.sun.com/javaone | 30

Demo Terracotta CoordinationEnhanced Hello World

Page 31: Boldly go where the Java programming language has never gone before

2008 JavaOneSM Conference | java.sun.com/javaone | 31

Coordination - trying it out

Start the server:$ start-tc-server.shStart a client:$ dso-java.sh -Dtc.config=tc-config-concurrent.xml

-Dnodes=2 tutorial.HelloWorldConcurrentIt just hangs thereAfter starting the 2nd client:Hello Thu Dec 13 19:12:38 CET 2007Hello Thu Dec 13 19:13:56 CET 2007The cyclic barrier is clustered across JVMs

Page 32: Boldly go where the Java programming language has never gone before

2008 JavaOneSM Conference | java.sun.com/javaone | 32

Terracotta’s Boldness

Page 33: Boldly go where the Java programming language has never gone before

2008 JavaOneSM Conference | java.sun.com/javaone | 33

Terracotta's Boldness

Plug into the JVM with a bootjarTranslate threads to cluster nodesModify getfield, putfield, monitorenter, monitorexit byte code instructions to work across the clusterJava Memory Model as a contract for accessing shared state and coordination across the cluster

Page 34: Boldly go where the Java programming language has never gone before

2008 JavaOneSM Conference | java.sun.com/javaone | 34

Agenda

Java programming language != JVM != Java platformTerracottaRIFE ContinuationsGoogle Web ToolkitGoogle Android

Page 35: Boldly go where the Java programming language has never gone before

2008 JavaOneSM Conference | java.sun.com/javaone | 35

Agenda

Java programming language != JVM != Java platformTerracottaRIFE ContinuationsGoogle Web ToolkitGoogle Android

Page 36: Boldly go where the Java programming language has never gone before

2008 JavaOneSM Conference | java.sun.com/javaone | 36

What is RIFE?

Full-stack component framework toquickly and consistently develop and

maintain Java web applications

Page 37: Boldly go where the Java programming language has never gone before

2008 JavaOneSM Conference | java.sun.com/javaone | 37

What are continuations?

Page 38: Boldly go where the Java programming language has never gone before

2008 JavaOneSM Conference | java.sun.com/javaone | 38

… continuations are like

Save Game

Page 39: Boldly go where the Java programming language has never gone before

2008 JavaOneSM Conference | java.sun.com/javaone | 39

… Save Game

can be performed at certain locations in the game(or anywhere, depending on the type of game)captures the progress and your possessionsseveral saved games can exist at once

Page 40: Boldly go where the Java programming language has never gone before

2008 JavaOneSM Conference | java.sun.com/javaone | 40

… but they are also like

Load Game

Page 41: Boldly go where the Java programming language has never gone before

2008 JavaOneSM Conference | java.sun.com/javaone | 41

… Load Game

retrieve any saved gameload the saved gamerestore the progress and your possessionsresume exactly where you left off

Page 42: Boldly go where the Java programming language has never gone before

2008 JavaOneSM Conference | java.sun.com/javaone | 42

… all we have to do is replace

Game ApplicationSaved Game Continuation

Progress LocationPossession State

Page 43: Boldly go where the Java programming language has never gone before

2008 JavaOneSM Conference | java.sun.com/javaone | 43

… Pausecan be performed at certain locations in the gamecaptures the progress and your possessionsseveral saved games can exist at once

… Resumeretrieve any saved gamesload the saved gamerestore the progress and your possessionsresume exactly where you left off

gamethe progress your possessions

saved games

saved gamessaved game

the progress your possessions

Page 44: Boldly go where the Java programming language has never gone before

2008 JavaOneSM Conference | java.sun.com/javaone | 44

… Pausecan be performed at certain locations in the gamecaptures the progress and your possessionsseveral saved games can exist at once

… Resumeretrieve any saved gamesload the saved gamerestore the progress and your possessionsresume exactly where you left off

Page 45: Boldly go where the Java programming language has never gone before

2008 JavaOneSM Conference | java.sun.com/javaone | 45

… Pausecan be performed at certain locations in the gamecaptures the progress and your possessionsseveral saved games can exist at once

… Resumeretrieve any saved gamesload the saved gamerestore the progress and your possessionsresume exactly where you left off

applicationthe location the state

continuationcontinuation

the location the state

continuations

Page 46: Boldly go where the Java programming language has never gone before

2008 JavaOneSM Conference | java.sun.com/javaone | 46

Concretely

Page 47: Boldly go where the Java programming language has never gone before

2008 JavaOneSM Conference | java.sun.com/javaone | 47

Concretely : pseudo code

Page 48: Boldly go where the Java programming language has never gone before

2008 JavaOneSM Conference | java.sun.com/javaone | 48

Concretely : pseudo code

Program output isLet's call this backwardsContext and location are stored in a variableMultiple continuations can be active at once

Page 49: Boldly go where the Java programming language has never gone before

2008 JavaOneSM Conference | java.sun.com/javaone | 49

Continuations ExampleNumber guessing game(as a web application)

Page 50: Boldly go where the Java programming language has never gone before

2008 JavaOneSM Conference | java.sun.com/javaone | 50

Number Guessing - Game.java

Page 51: Boldly go where the Java programming language has never gone before

2008 JavaOneSM Conference | java.sun.com/javaone | 51

Demo ContinuationsNumber Guessing Game Running & Debugging

Page 52: Boldly go where the Java programming language has never gone before

2008 JavaOneSM Conference | java.sun.com/javaone | 52

RIFE’s Boldness

Page 53: Boldly go where the Java programming language has never gone before

2008 JavaOneSM Conference | java.sun.com/javaone | 53

RIFE’s Boldness

Java method calls are trapped at runtime when classes are loaded to rewrite the code sections they're executing in (pause(), call(), answer())Intuitive state handling, requiring no serializationRegular Java language statements direct application control flowRegular Java development tools like debuggers and IDEs can be used to develop, document and debug application control flowContinuation trees for backward and forward stepping

Page 54: Boldly go where the Java programming language has never gone before

2008 JavaOneSM Conference | java.sun.com/javaone | 54

Agenda

Java programming language != JVM != Java platformTerracottaRIFE ContinuationsGoogle Web ToolkitGoogle Android

Page 55: Boldly go where the Java programming language has never gone before

2008 JavaOneSM Conference | java.sun.com/javaone | 55

Agenda

Java programming language != JVM != Java platformTerracottaRIFE ContinuationsGoogle Web ToolkitGoogle Android

Page 56: Boldly go where the Java programming language has never gone before

2008 JavaOneSM Conference | java.sun.com/javaone | 56

What is Google Web Toolkit?

Create AJAX applications in the Java programming language using regular Java tools and deploy them to browser-

compliant HTML and Javascript™ technology

Page 57: Boldly go where the Java programming language has never gone before

2008 JavaOneSM Conference | java.sun.com/javaone | 57

Google Web Toolkit Overview

Page 58: Boldly go where the Java programming language has never gone before

2008 JavaOneSM Conference | java.sun.com/javaone | 58

Google Web Toolkit approach

'Regular' Ajax Dev• Write Javascript code and

DHTML• Learn all the intricacies

Different approach• Write Ajax applications in the

Java platform• Compile Java code to Javascript

code

Ajax Libraries

Javascript versions Browser differences

Client-side debuggers

Smart text editors Resource packaging

Difficult to test

Design RPC API and format

Google Web Toolkit (GWT)

use Java platform, standard APIs and your regular tools

Page 59: Boldly go where the Java programming language has never gone before

2008 JavaOneSM Conference | java.sun.com/javaone | 59

GWT’s main features

Two main execution modes• Hosted mode

• Executed with the JVM, no generated Javascript source code• Embedded browser hooks into Java libraries• Code-test-debug as regular Java applications

• Web mode• Compiles Java source code to Javascript source code• Runs inside browser without plugins

Standardized RPC• Implement RemoteService interface• Relies on serialization for arguments and return values• Supports asynchronous method calls

Page 60: Boldly go where the Java programming language has never gone before

2008 JavaOneSM Conference | java.sun.com/javaone | 60

GWT Examples(with Eclipse)

Page 61: Boldly go where the Java programming language has never gone before

2008 JavaOneSM Conference | java.sun.com/javaone | 61

Hello World

Page 62: Boldly go where the Java programming language has never gone before

2008 JavaOneSM Conference | java.sun.com/javaone | 62

GWT Hello World

Create a new project and generate the required files

Import project into Eclipse

Page 63: Boldly go where the Java programming language has never gone before

2008 JavaOneSM Conference | java.sun.com/javaone | 63

Hello World - com/client/HelloWorldApp.java

Page 64: Boldly go where the Java programming language has never gone before

2008 JavaOneSM Conference | java.sun.com/javaone | 64

Hello World - com/public/HelloWorldApp.html

Page 65: Boldly go where the Java programming language has never gone before

2008 JavaOneSM Conference | java.sun.com/javaone | 65

Demo GWTHello World

Page 66: Boldly go where the Java programming language has never gone before

2008 JavaOneSM Conference | java.sun.com/javaone | 66

RPC

Page 67: Boldly go where the Java programming language has never gone before

2008 JavaOneSM Conference | java.sun.com/javaone | 67

RPC Services

com/client/GreeterService.java

com/services/GreeterServiceImpl.java

com/client/GreeterServiceAsync.java

Page 68: Boldly go where the Java programming language has never gone before

2008 JavaOneSM Conference | java.sun.com/javaone | 68

RPC GWT Module - com/RpcApp.gwt.xml

Page 69: Boldly go where the Java programming language has never gone before

2008 JavaOneSM Conference | java.sun.com/javaone | 69

RPC App - com/client/RpcApp.java 1/2

Page 70: Boldly go where the Java programming language has never gone before

2008 JavaOneSM Conference | java.sun.com/javaone | 70

RPC App - com/client/RpcApp.java 2/2

Page 71: Boldly go where the Java programming language has never gone before

2008 JavaOneSM Conference | java.sun.com/javaone | 71

Demo GWTRPC

Page 72: Boldly go where the Java programming language has never gone before

2008 JavaOneSM Conference | java.sun.com/javaone | 72

GWT’s Boldness

Page 73: Boldly go where the Java programming language has never gone before

2008 JavaOneSM Conference | java.sun.com/javaone | 73

GWT’s Boldness

Two execution modes simplify both development and deploymentBrowser is hooked into Java libraries to provide real debugging during hosted modeThe Java source code is compiled to the Javascript source code during web mode to hide the difficulties of Ajax/DHTML development

Page 74: Boldly go where the Java programming language has never gone before

2008 JavaOneSM Conference | java.sun.com/javaone | 74

Agenda

Java programming language != JVM != Java platformTerracottaRIFE ContinuationsGoogle Web ToolkitGoogle Android

Page 75: Boldly go where the Java programming language has never gone before

2008 JavaOneSM Conference | java.sun.com/javaone | 75

Agenda

Java programming language != JVM != Java platformTerracottaRIFE ContinuationsGoogle Web ToolkitGoogle Android

Page 76: Boldly go where the Java programming language has never gone before

2008 JavaOneSM Conference | java.sun.com/javaone | 76

What is Google Android?

A platform for mobile devices wheresoftware is written in the Java

language and run on Dalvik, a customvirtual machine for embedded use

Page 77: Boldly go where the Java programming language has never gone before

2008 JavaOneSM Conference | java.sun.com/javaone | 77

Google Android Overview

Page 78: Boldly go where the Java programming language has never gone before

2008 JavaOneSM Conference | java.sun.com/javaone | 78

Google Android approach

'Regular' Mobile Dev• Proprietary platform• Java™ Platform, Micro Edition

(Java ME) is just another application

• Java applications run in the same virtual machine

Different approach• Open-source platform• All applications in Java

programming language• Dedicated virtual machine

per application

Page 79: Boldly go where the Java programming language has never gone before

2008 JavaOneSM Conference | java.sun.com/javaone | 79

Google Android Architecture

Page 80: Boldly go where the Java programming language has never gone before

2008 JavaOneSM Conference | java.sun.com/javaone | 80

Demo Google AndroidToo many snippets and resources toshow code in slides

Page 81: Boldly go where the Java programming language has never gone before

2008 JavaOneSM Conference | java.sun.com/javaone | 81

Google Android’s Boldness

Page 82: Boldly go where the Java programming language has never gone before

2008 JavaOneSM Conference | java.sun.com/javaone | 82

Google Android’s Boldness

Program everything in the Java programming languageOnly use Android's Java Platform Runtime Environment (JRE), which includes supported library classesCompile with javac and convert to Android bytecode for the Dalvik VM (.dex files)Debug through the Dalvik Debug Monitor Server (DDMS) which forwards ports from the emulator or device to the IDE

Page 83: Boldly go where the Java programming language has never gone before

2008 JavaOneSM Conference | java.sun.com/javaone | 83

Agenda

Java programming language != JVM != Java platformTerracottaRIFE ContinuationsGoogle Web ToolkitGoogle Android

Page 84: Boldly go where the Java programming language has never gone before

2008 JavaOneSM Conference | java.sun.com/javaone | 84

Conclusion

Using just the Java language you're able to do:• Transparent Clustering and Coordination:

Terracotta (http://www.terracotta.org)• Intuitive application control flow:

RIFE Continuations (http://rifers.org)• Ajax client application development:

Google Web Toolkit (http://code.google.com/webtoolkit)• First-class mobile application development:

Google Android (http://code.google.com/android)

Without learning new languages and tools, all these possibilities open up

Page 85: Boldly go where the Java programming language has never gone before

Boldly go where the Java programming language has never gone beforeGeert Bevin

http://terracotta.org - http://rifers.org