33
Project Zero Rob Nicholson [email protected]

Project Zero - IBM...Application languages, PHP, Groovy, Others…. Zero contains a PHP 5 interpreter written in Java. Enables composite applications using assets from Java and PHP

  • Upload
    others

  • View
    13

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Project Zero - IBM...Application languages, PHP, Groovy, Others…. Zero contains a PHP 5 interpreter written in Java. Enables composite applications using assets from Java and PHP

Project Zero

Rob Nicholson [email protected]

Page 2: Project Zero - IBM...Application languages, PHP, Groovy, Others…. Zero contains a PHP 5 interpreter written in Java. Enables composite applications using assets from Java and PHP

2

projectzero.org

Introduction

Project Zero is a technology incubator.

Building a radically simplified platform to enable the productive development and deployment of Web-Oriented Applications.

System Language is Java.Zero runs on a Java Virtual Machine.

Application languages, PHP, Groovy, Others….Zero contains a PHP 5 interpreter written in Java.

Enables composite applications using assets from Java and PHP.Best of both worlds.

Page 3: Project Zero - IBM...Application languages, PHP, Groovy, Others…. Zero contains a PHP 5 interpreter written in Java. Enables composite applications using assets from Java and PHP

3

projectzero.org

Facets of Project Zero

CREATE: “WOA” Programming Model:Convention, Templates, Snippets, PHP, Groovy, JavaScript and Java syntaxes

ASSEMBLE: Application and Service Assembly:

Orchestrate, Mediate, Compose Solutions

EXECUTE: “New Reality” Runtime:A modified Java Runtime.Run Hundreds of Applications, Strong Isolation and resilience.Scripting Language Behavior – Run and Done!

Page 4: Project Zero - IBM...Application languages, PHP, Groovy, Others…. Zero contains a PHP 5 interpreter written in Java. Enables composite applications using assets from Java and PHP

4

projectzero.org

Zero Create Architecture

Local repository

Remote repository

Remote repository

Java Virtual Machine

Zero Application

Global Context

PHP

Run

time

Gro

ovy

Run

time

Java app

App components

app

app

Events

HTT

P s

erve

r

Package Manager

Dojo

Browser

Applications built from loosely coupled components.

Enabled by:Event driven architecture.

Global Context.

Virtual Directories.

Convention based configuration.

RESTful web services and AJAX.

IDE based around Eclipse and PDTCommand line for deployment.

The application is the web server.

REST

Page 5: Project Zero - IBM...Application languages, PHP, Groovy, Others…. Zero contains a PHP 5 interpreter written in Java. Enables composite applications using assets from Java and PHP

5

projectzero.org

Zero PHP Internals • Runtime for PHP 5 scripts

• Implemented in Java, runs on any Java 5.0 VM

• PHP language elements represented as Java objects

• Parse script to Intermediate Representation (IR).

• Currently interpret the IR.

• Later compile to bytecodes.

•Extensibility via XAPI

• XAPI-C for C extensions.

• XAPI-J for new Java extensions, native libraries invoked over JNI and Project Zero interface.

• Extension language choice opaque to PHP script

•Compatibility with PHP.net verified using PHP.net test suite and existing PHP applications.

P8 Runtime

PHP Scripts CLI

SAPI-J

Project Zero

Parser

Interpreter

Runtime

PHP Engine

XAPI-JXAPI-C

Java Extensions

CExtensions

Stack

Resources

Classes

Objects

IR

Variables

Debug

Project Zero

Page 6: Project Zero - IBM...Application languages, PHP, Groovy, Others…. Zero contains a PHP 5 interpreter written in Java. Enables composite applications using assets from Java and PHP

6

projectzero.org

Install of Zero

Get a Java 1.5 JDK.

Get the PHP Development Tools (PDT) Eclipse all-in-one.

Install Zero for PDT using the eclipse update manager.From the project zero download site.

Links and walkthrough on www.projectzero.org.

Page 7: Project Zero - IBM...Application languages, PHP, Groovy, Others…. Zero contains a PHP 5 interpreter written in Java. Enables composite applications using assets from Java and PHP

7

projectzero.org

Demo – Your first Zero Application.

Page 8: Project Zero - IBM...Application languages, PHP, Groovy, Others…. Zero contains a PHP 5 interpreter written in Java. Enables composite applications using assets from Java and PHP

8

projectzero.org

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

Page 9: Project Zero - IBM...Application languages, PHP, Groovy, Others…. Zero contains a PHP 5 interpreter written in Java. Enables composite applications using assets from Java and PHP

9

projectzero.org

REST design

Restful designs often use collections.

Collection is a simple model for modelling a set of resources.

Collections have members you can Create/Retrieve/Update/ Delete.

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 10: Project Zero - IBM...Application languages, PHP, Groovy, Others…. Zero contains a PHP 5 interpreter written in Java. Enables composite applications using assets from Java and PHP

10

projectzero.org

REST in project Zero

Handlers live in the virtualised directory:<apphome>/app/resources

Each script is a handler.Implements the collection and member operations.

URL convention:/resources/<collectionName>[/memberID[/<pathInfo>]]

HTTP methods mapped to collection and member events as follows:

Resource GET PUT POST DELETE

Collection list putCollection

update

deleteCollection

Member retrieve

create

postMember delete

Page 11: Project Zero - IBM...Application languages, PHP, Groovy, Others…. Zero contains a PHP 5 interpreter written in Java. Enables composite applications using assets from Java and PHP

11

projectzero.org

RESTful Resources

Values of <memberID> and <pathInfo> are available for member operations:

Http Method

URI Invokes method in <apphome>/app/resources/people.php

With event data (in global context)

GET /resources/people list

create

retrieve

update

delete

POST /resources/people

/request/params/peopleId = 1 /event/pathInfo = /accounts

/request/params/peopleId' = 1

GET /resources/people/1/accounts

PUT /resources/people/1

DELETE /resources/people/1 /request/params/peopleId' = 1

Page 12: Project Zero - IBM...Application languages, PHP, Groovy, Others…. Zero contains a PHP 5 interpreter written in Java. Enables composite applications using assets from Java and PHP

12

projectzero.org

Demo – REST in Project Zero,

Page 13: Project Zero - IBM...Application languages, PHP, Groovy, Others…. Zero contains a PHP 5 interpreter written in Java. Enables composite applications using assets from Java and PHP

13

projectzero.org

Events

All behaviour in the system is modelled as a set of events.Developer writes event handlers to respond to events and create the desired behaviour.Events are programming language agnostic.Application Lifecycle events

config, start, ready, stop

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

Application specific eventsFired by your application.

Page 14: Project Zero - IBM...Application languages, PHP, Groovy, Others…. Zero contains a PHP 5 interpreter written in Java. Enables composite applications using assets from Java and PHP

14

projectzero.org

Global Context

Event handlers are statelessinteresting applications contain state

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

Conceptually a map of data.

Divided into a set of zones with different data lifecycles.

Understands and provides intelligent access to certain data types.

Externalizes state from the application logic.Enables clustering and scaling to be added transparently.

Page 15: Project Zero - IBM...Application languages, PHP, Groovy, Others…. Zero contains a PHP 5 interpreter written in Java. Enables composite applications using assets from Java and PHP

15

projectzero.org

Global Content Zones

Divided into 4 zones representing different data lifecyclesZone Scope/Visibility Lifecycle

Application All requests for all users of the application

For the 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 16: Project Zero - IBM...Application languages, PHP, Groovy, Others…. Zero contains a PHP 5 interpreter written in Java. Enables composite applications using assets from Java and PHP

16

projectzero.org

Accessing the Global Context

Action PHP Example Java Example

Get HTTP Request URI get (/request/uri) GlobalContext.get("/request/uri"

Get value of user-agent request header

get (/request/headers/in/User-Agent)

GlobalContext.get("/request/headers/in/User-Agent")

Get list of request parameters list_keys('/request/params', false)

GlobalContext.get("/request/params")

Get value of request parameter parmName

get (/request/params/ParmName)

((String []) GlobalContext.get("/request/params/parmName"))[0]

Set status put (/request/status,200) request.status = 200

Of course PHP (super)globals are also available.

Page 17: Project Zero - IBM...Application languages, PHP, Groovy, Others…. Zero contains a PHP 5 interpreter written in Java. Enables composite applications using assets from Java and PHP

17

projectzero.org

Default Attributes (subset)

Page 18: Project Zero - IBM...Application languages, PHP, Groovy, Others…. Zero contains a PHP 5 interpreter written in Java. Enables composite applications using assets from Java and PHP

18

projectzero.org

Dojo

Dojo is the preferred AJAX toolkit for Zero.

Dojo is an open source javascript toolkit to simplify AJAX apps.Browser compatibility.

WidgetsTabs, tees, editor, date, time, menus

Animation effectsDrag and drop, fades, movement

Portable network IO.

Math/crypto Libraries.

Page 19: Project Zero - IBM...Application languages, PHP, Groovy, Others…. Zero contains a PHP 5 interpreter written in Java. Enables composite applications using assets from Java and PHP

19

projectzero.org

Demo – Officemon sample.

Page 20: Project Zero - IBM...Application languages, PHP, Groovy, Others…. Zero contains a PHP 5 interpreter written in Java. Enables composite applications using assets from Java and PHP

20

projectzero.org

Catalog and Dependencies

Applications declare a dependency on libraries or modules they desire to use.

A package management system (ivy) provides the ability to resolve those dependencies on the local machine.

A remote catalog server hosts the core and the libraries for easy network resolution.

Similar in spirit to Linux package managers (yum, apt-get), PEAR, Ruby Gems, Eclipse Plugins, etc.

Page 21: Project Zero - IBM...Application languages, PHP, Groovy, Others…. Zero contains a PHP 5 interpreter written in Java. Enables composite applications using assets from Java and PHP

21

projectzero.org

Deploying on the command line

Package the app from eclipse:File->export.

Download Zero command line from projectzero.org, unzip on target machine.

Unzip application.

Zero run :

C:\z\officemonitor-all>zero runResolving C:\z\officemonitor-all\config\ivy.xmlzeroinit apphome=C:\z\officemonitor-allzeromake zerohome=C:\zero\zero-1.0.6169.M2\ apphome=C:\z\officemonitor-all appname=officemonitor2007-10-29 20:58:20 zero.core.cfadapter.ZeroServer::writePid Thread-10

INFO [ PID file written to C:\z\officemonitor-all\logs\zero.pid]2007-10-29 20:58:20 zero.core.cfadapter.ZeroServer::run Thread-10

INFO [ C:/z/officemonitor-all running on port 8080 ]

Page 22: Project Zero - IBM...Application languages, PHP, Groovy, Others…. Zero contains a PHP 5 interpreter written in Java. Enables composite applications using assets from Java and PHP

22

projectzero.org

Java Bridge

Page 23: Project Zero - IBM...Application languages, PHP, Groovy, Others…. Zero contains a PHP 5 interpreter written in Java. Enables composite applications using assets from Java and PHP

23

projectzero.org

Features of Zero we have not covered today

Rendering

File Serving

Error Handling

Logging/Tracing/Debugging

Client Programming with Dojo

Security

Nested resources

Page 24: Project Zero - IBM...Application languages, PHP, Groovy, Others…. Zero contains a PHP 5 interpreter written in Java. Enables composite applications using assets from Java and PHP

24

projectzero.org

Zero PHP Internals.

P8 Runtime

PHP Scripts CLI

SAPI-J

Project Zero

Parser

Interpreter

Runtime

PHP Engine

XAPI-JXAPI-C

Java Extensions

CExtensions

Stack

Resources

Classes

Objects

IR

Variables

Debug

Project Zero

Page 25: Project Zero - IBM...Application languages, PHP, Groovy, Others…. Zero contains a PHP 5 interpreter written in Java. Enables composite applications using assets from Java and PHP

25

projectzero.org

XAPI-J example

Page 26: Project Zero - IBM...Application languages, PHP, Groovy, Others…. Zero contains a PHP 5 interpreter written in Java. Enables composite applications using assets from Java and PHP

26

projectzero.org

What we learned

PHP is reference implementation based language.

PHP has no spec.

Documentation is good for users.But not precise enough for language implementers.

Test suite is the real spec.

Many surprises.

Page 27: Project Zero - IBM...Application languages, PHP, Groovy, Others…. Zero contains a PHP 5 interpreter written in Java. Enables composite applications using assets from Java and PHP

27

projectzero.org

Quantum mechanics in PHP

In this example we see how observing a value can change how it behaves.

Counter-intuitive to non physicists.But similar in some ways to quantum physics.

Page 28: Project Zero - IBM...Application languages, PHP, Groovy, Others…. Zero contains a PHP 5 interpreter written in Java. Enables composite applications using assets from Java and PHP

28

projectzero.org

Quantum Mechanics in PHP (simple case)1. $a=array(“foo”);

0PHP String

“foo”$a

0PHP String

“foo”$a

3. $b=$a;

0PHP String

“foo”$b

0PHP String

“foo”

0PHP String

“bar”

4. $b[0]=“bar”;

$a

$b

Pictures show PHP programmer’s view. (Not internals).

Observe that $b and $a are independent.

2. // do nothing

Page 29: Project Zero - IBM...Application languages, PHP, Groovy, Others…. Zero contains a PHP 5 interpreter written in Java. Enables composite applications using assets from Java and PHP

29

projectzero.org

Quantum Mechanics in PHP (observing changes behaviour)1. $a=array(“foo”);

0PHP String

“foo”$a

0PHP String

“foo”$a

3. $b=$a;

0$b

0PHP String

“bar”

0

4. $b[0]=“bar”;

$a

$b

2. $c=&$a[0];

0PHP String

“foo”$a

$c

All we did was observe the value of $a[0]

Now $a and $b are not independent.

Page 30: Project Zero - IBM...Application languages, PHP, Groovy, Others…. Zero contains a PHP 5 interpreter written in Java. Enables composite applications using assets from Java and PHP

30

projectzero.org

PROJECT ZERO COMMUNITYWWW.PROJECTZERO.ORG

Page 31: Project Zero - IBM...Application languages, PHP, Groovy, Others…. Zero contains a PHP 5 interpreter written in Java. Enables composite applications using assets from Java and PHP

31

projectzero.org

Page 32: Project Zero - IBM...Application languages, PHP, Groovy, Others…. Zero contains a PHP 5 interpreter written in Java. Enables composite applications using assets from Java and PHP

32

projectzero.org

Questions?

Page 33: Project Zero - IBM...Application languages, PHP, Groovy, Others…. Zero contains a PHP 5 interpreter written in Java. Enables composite applications using assets from Java and PHP

33

projectzero.org

Acknowledgements

Java is a trademark of Sun Microsystems Inc.