Project Zero JavaOne 2008

34
The Duke and the Elephant: PHP meets Java TM Technology. The best of both worlds. Rob Nicholson IBM Senior Technical Staff Member.

description

Project Zero PHP talk at JavaOne 2008. This talk describes IBM WebSphere sMash and the PHP support within it. For more information visit http://www.projectzero.org

Transcript of Project Zero JavaOne 2008

Page 1: Project Zero JavaOne 2008

The Duke and the Elephant: PHP meets JavaTM Technology. The best of both worlds.

Rob NicholsonIBM Senior Technical Staff Member.

Page 2: Project Zero JavaOne 2008

2008 JavaOneSM Conference | java.sun.com/javaone | 2© 2008 IBM Corporation

Agenda

Whys and Whats of PHP on the Java Virtual Machine (JVM™) software

How we mix PHP, Java platform and Groovy

Demonstration of PHP and Java Platform Interaction

ProjectZero Community

Page 3: Project Zero JavaOne 2008

2008 JavaOneSM Conference | java.sun.com/javaone | 3© 2008 IBM Corporation

Agenda

Whys and Whats of PHP on the Java Virtual Machine (JVM™) software

How we mix PHP, Java platform and Groovy

Demonstration of PHP and Java Platform Interaction

ProjectZero Community

Page 4: Project Zero JavaOne 2008

2008 JavaOneSM Conference | java.sun.com/javaone | 4© 2008 IBM Corporation

Why PHP?PHP present on 20M+ web domains (34% of internet)• Validated by significant web properties

PHP snippets and extensions exist to do almost anythingLanguage has evolved in open source• Survival of the simplest and fastest

Simple syntax and dynamic typing encourage situational applications

Gartner (Dec 2007)• PHP Developers to grow from 3

to 5.5 million by 2013• PHP Developers in Commercial

or Corporate IT to grow from 13% to 60% by 2013

• “Pay special attention to opportunities to leverage PHP in combination with Java development efforts”

TIOBE Programming Community Index (March 2008)

Page 5: Project Zero JavaOne 2008

2008 JavaOneSM Conference | java.sun.com/javaone | 5© 2008 IBM Corporation

Introducing WebSphere sMashWebSphere sMash is an Agile Web Application Platform• Architected around Dynamic Scripting, REST, Rich Web Interfaces,

AJAX, and Feeds• Optimized for

• Speed• Simplicity• Agility

Key Scenarios• Enables developers to build web 2.0-style applications by easily pulling in,

composing, and “cobbling together” pre-existing assets (PHP assets, services, feeds, code snippets) using dynamic scripting languages and simple consumption principles based on REST

• Leverages existing SOA investments by enabling rapid development of dynamic web applications that are assembled from enterprise assets and publicly available APIs

System language is Java platformApplication languages are and• Contains a PHP 5 interpreter written in Java programming language

Page 6: Project Zero JavaOne 2008

2008 JavaOneSM Conference | java.sun.com/javaone | 6© 2008 IBM Corporation

Project ZeroIncubating the Technology

Project Zero is the development and incubation community for WebSphere sMash• Live on the Internet since June 2007

Project Zero represents • The people that build and use WebSphere sMash • The incubation of new technology that will deliver in future versions of

WebSphere sMash • The community of 3rd party assets that leverage the WebSphere sMash platform

All released versions are called WebSphere sMash

Page 7: Project Zero JavaOne 2008

2008 JavaOneSM Conference | java.sun.com/javaone | 7© 2008 IBM Corporation

The Duke and the Elephpant

© Hideyuki Shimooka

Page 8: Project Zero JavaOne 2008

2008 JavaOneSM Conference | java.sun.com/javaone | 8© 2008 IBM Corporation

Top Level Architecture

Local repository

Remote repository

Remote repository

Java Virtual Machine

Zero Application

Global Context

PHP

Run

time

Gro

ovy

Run

time

JavaTM app

App components

app

app

Events

HTT

P s

erve

r

Package Manager

Dojo

Browser

Loose coupling:• Event driven architecture• Global Context• Virtual Directories

REST

Page 9: Project Zero JavaOne 2008

2008 JavaOneSM Conference | java.sun.com/javaone | 9© 2008 IBM Corporation

PHP Runtime Architecture• Runtime for PHP 5 scripts

• Implemented in Java code, runs on any Javaplatform 5.0+ VM

• PHP language elements represented as Java code objects

• Parse script to Intermediate Representation (IR)• Cache and Interpret IR• Compile ->bytecode prototype

• Extensibility via XAPI• XAPI-C for C extensions from php.net• XAPI-J for new Java platform extensions,

native libraries invoked over JNI™ API and Project Zero interface

• Extension language choice opaque to PHP script• Java Platform Bridge• Debug using via DBGp using Eclipse with PDT

P8 Runtime

PHP Scripts CLI

SAPI-J

PZ Http

Parser

Interpreter

Runtime

PHP Engine

Java ExtensionsC

Extensions

Stack

Resources

Classes

Objects

Variables

Debug (D

BG

p)PZ Extensions

CacheIR

XAPI-JXAPI-C

Native code

Page 10: Project Zero JavaOne 2008

2008 JavaOneSM Conference | java.sun.com/javaone | 10© 2008 IBM Corporation

XAPI-J exampleExtend PHP using Java Platform

@XAPIExtension("BigDecimal")public class BigDecimalExt extends ExtensionBaseImpl {

@XAPIFunction("add_bigdecimal")public void add(RuntimeContext ctxt) {

RuntimeServices rts = getRuntimeServices(); InvocationService inv =rts.getInvocationService(); Object[] args =

inv.parseArguments(ctxt, "ss", false);BigDecimal arg1 = new BigDecimal((

( XAPIString) args[0]).getString()); BigDecimal arg2 = new BigDecimal((

( XAPIString) args[1]).getString());BigDecimal result = arg1.add(arg2); ctxt.setReturnValue(result.toString());

}

Page 11: Project Zero JavaOne 2008

2008 JavaOneSM Conference | java.sun.com/javaone | 11© 2008 IBM Corporation

Java Platform BridgeEasy access to Java Classes from PHP

<?php $date = new Java("java.util.Date", 70, 9, 4);var_dump($date->toString());$map = new Java("java.util.HashMap");$map->put("title", "Java Bridge!");$map->put("when", $date); echo $map->get("when")->toString()."\n";echo $map->get("title")."\n";$array = array(1,2,3,4,5);$map->put("stuff", $array); // PHP array converted to

Java Mapvar_dump($map->get("stuff"))."\n";

?>

Page 12: Project Zero JavaOne 2008

2008 JavaOneSM Conference | java.sun.com/javaone | 12© 2008 IBM Corporation

Agenda

Whys and Whats of PHP on the Java Virtual Machine software

How we mix PHP, Java platform and Groovy

Demonstration of PHP and Java Platform Interaction

ProjectZero Community

Page 13: Project Zero JavaOne 2008

2008 JavaOneSM Conference | java.sun.com/javaone | 13© 2008 IBM Corporation

Virtualized Directories

Resources searched across application and dependencies.Apps behave as if directories merged.Applies to all script directories.

• /public /app/resources, /app/scripts, /app/views etc.First-one-wins precedence.

• Order based on dependency order in ivy files.• Default files searched within each directory first:

• {my application}/index.php• {my application}/index.html• {dependency1}/index.php• {dependency1}/index.html

Facilitate Application Composition

Page 14: Project Zero JavaOne 2008

2008 JavaOneSM Conference | java.sun.com/javaone | 14© 2008 IBM Corporation

REST ServicesMade easy

Zero provides a really simple way to create REST servicesConvention for create/retrieve/update/delete operations (CRUD) • You can also list the members in the collection.

HTTP Method URI DescriptionGET /people List members

POST /people Create member

GET /people/1 Retrieve member

PUT /people/1 Update member

DELETE /people/1 Delete member

Page 15: Project Zero JavaOne 2008

2008 JavaOneSM Conference | java.sun.com/javaone | 15© 2008 IBM Corporation

REST Services in WebSphere sMash

Each REST service is implemented by a script (called a handler)Scripts live in the directory: <apphome>/app/resourcesServices are accessed using a standard URL convention:•/resources/<collection name>[/member[/<path info>]]

HTTP requests mapped to handler methods as follows:

Resource GET PUT POST DELETE

Collection/people

list putCollection create deleteCollection

Member/people/1

retrieve update postMember delete

Page 16: Project Zero JavaOne 2008

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

Demo – REST in WebSphere sMash

Page 17: Project Zero JavaOne 2008

2008 JavaOneSM Conference | java.sun.com/javaone | 17© 2008 IBM Corporation

All behaviour in the system is modelled as a set of events.• Events are programming language agnostic

Fired by an application using fire_event().

fire_event('my_event', array(‘data'=>'foobar'));

Event handlers are defined in the Zero configuration file:/config/handlers += {

"events" : my_event,

"handler" : test.php

}

Request Processing events • requestBegin, secure, GET, PUT, POST, DELETE, log, requestEnd

Application specific events• Fired by your application

EventsPromote Loose Coupling

Page 18: Project Zero JavaOne 2008

2008 JavaOneSM Conference | java.sun.com/javaone | 18© 2008 IBM Corporation

Global ContextEvent handlers are stateless• interesting applications contain state

GC provides access/management of application state• It is NOT persistent. Persistent data goes into the database

Conceptually a map of dataDivided into a set of zones with different data lifecyclesUnderstands and provides intelligent access to certain data typesExternalizes state from the application logic• Enables clustering and scaling to be added transparently

Page 19: Project Zero JavaOne 2008

2008 JavaOneSM Conference | java.sun.com/javaone | 19© 2008 IBM Corporation

Global Content Zones

Divided into zones representing different data lifecyclesZone Scope/Visibility Lifecycle

Config All requests all users. Loaded from config files.

Application All requests for all users of the application

Life of the application, but not “persistent”

User All request for a particular user (HTTP Session equivalent)

For first access until user times out

Request All handlers along the path of a single request

For the duration of a single request

Event All handlers for a single event The duration of a single event

Page 20: Project Zero JavaOne 2008

2008 JavaOneSM Conference | java.sun.com/javaone | 20© 2008 IBM Corporation

Versioning Dependencies

Modules are the building blocks of an applicationA module is simply a collection of files packaged together

• Includes a module name, version and author detailsAn application declares the modules it depends on

Versioning ensures applications don’t break!• Specific versions can be set (v1.1.34)• Versions upwards from a particular release (v1.0+)• Ranges of acceptable versions (v1.0 – v1.5)

Remote catalog servers at PZ.net and maven2

Page 21: Project Zero JavaOne 2008

2008 JavaOneSM Conference | java.sun.com/javaone | 21© 2008 IBM Corporation

Deploying Applications

Web server

Application Code

Language runtimes

Java VM

The Application is the server

Hundreds of applications per boxApplications started on demand • inetd style

Applications isolation Quality of service and management built in

Page 22: Project Zero JavaOne 2008

2008 JavaOneSM Conference | java.sun.com/javaone | 22© 2008 IBM Corporation

Built in development tooling

Browser-Based Development IDEBuilt as a sMash application

Provides full development lifecycle for Zero applications

• Create, Edit, Test

Provides Visual Editors for Activities and Web Page construction

• Including a DOJO-enabled page editor

Basic Eclipse-based tooling also available if required

Page 23: Project Zero JavaOne 2008

2008 JavaOneSM Conference | java.sun.com/javaone | 23© 2008 IBM Corporation

Compose applications by “wiring” together REST services

Visually or programmatically combine existing feeds and services that enrich, sort, and filter data in a pipeline

Configure templates to alter pipeline routes, log events along the pipeline

Numerous built-in activities, including• Get Feed, Call Service, Aggregate, Sort, Transform,

Filter, Send Mail, XSLT, Conditionals, Loops

ActivitiesLet Developers Visually “Mash-up” Services and Feeds

Page 24: Project Zero JavaOne 2008

2008 JavaOneSM Conference | java.sun.com/javaone | 24© 2008 IBM Corporation

Installing WebSphere sMash

Get JavaTM 1.5(+) JDK

Get PHP Development Tools (PDT)All-in-one eclipse package Download installer (<800K)

Install Zero using the Eclipse update manager Libraries fetched as needed.

Eclipse CLI / Browser IDE

Links and walkthrough on www.projectzero.org

Page 25: Project Zero JavaOne 2008

2008 JavaOneSM Conference | java.sun.com/javaone | 25© 2008 IBM Corporation

Agenda

Whys and Whats of PHP on the Java Virtual Machine software

How we mix PHP, Java platform and Groovy

Demonstration of PHP and Java Platform Interaction.

ProjectZero Community

Page 26: Project Zero JavaOne 2008

2008 JavaOneSM Conference | java.sun.com/javaone | 26© 2008 IBM Corporation

Demo: Integration with SugarCRM

Scenario:

Scheduling meetings requires co-ordination across the business

Solution:

WebSphere sMash workflow triggered from SugarCRMPHP-Java Platform Interoperability• The best of both worlds

Page 27: Project Zero JavaOne 2008

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

Demo – Integration with SugarCRM

Page 28: Project Zero JavaOne 2008

2008 JavaOneSM Conference | java.sun.com/javaone | 28© 2008 IBM Corporation

Agenda

Whys and Whats of PHP on the Java Virtual Machine software

How we mix PHP, Java platform and Groovy

Demonstration of PHP and Java Platform Interaction

ProjectZero Community

Page 29: Project Zero JavaOne 2008

2008 JavaOneSM Conference | java.sun.com/javaone | 29© 2008 IBM Corporation

Community Driven Commercial Development

Evolve the core platform based on developer feedbackCommercial development using a transparent development process

Enabled via an external web site providing:

A focal point for all sMash development activitiesExpose the IBM® development process to the external developer communityAll design decisions are discussed and communicated via external forumsRegistered users can post comments and feedback to the forums

Frictionless download of latest code and documentation

Registration not required for binary downloadsLatest builds immediately available to developersSource code can be viewed by registered users

http://www.projectzero.org

Page 30: Project Zero JavaOne 2008

2008 JavaOneSM Conference | java.sun.com/javaone | 30© 2008 IBM Corporation

Site ContentsContent

• Documentation• Project information• Roadmaps• Design documents• Demos and Samples• iCal calendar• Future plans

Forum for interactive discussion• Help and Feedback for questions from users• Developer Alerts to notify users of new features and breaking changes• Zero Development for publicly accessible discussion amongst the Zero development team• 3554 Posts on 828 Topics to date

Blogs• Development blog with interesting commentary, demos, and opinion• News blog for project announcements

Binary Downloads (257,738 and counting…)Bug Tracking System (Bugzilla)Source code (Subversion)

3

Page 31: Project Zero JavaOne 2008

2008 JavaOneSM Conference | java.sun.com/javaone | 31© 2008 IBM Corporation

Features of sMash we have not covered today

File Serving

Error Handling

View Rendering

Logging, Tracing, Debugging

Client Programming with the Dojo Ajax Framework

Security

Nested resources

Page 32: Project Zero JavaOne 2008

2008 JavaOneSM Conference | java.sun.com/javaone | 32© 2008 IBM Corporation

Summary

Project Zero is incubating technologies to build web applications in WebSphere sMash• Simply!

WebSphere sMash contains a PHP runtime which runs on a JVM software

WebSphere sMash enables same process interoperability between PHP, Java platform and Groovy

Page 33: Project Zero JavaOne 2008

2008 JavaOneSM Conference | java.sun.com/javaone | 33© 2008 IBM Corporation

Questions?

Page 34: Project Zero JavaOne 2008

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

Rob Nicholson