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.

Post on 26-May-2020

13 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

Transcript

Project Zero

Rob Nicholson nicholsr@php.net

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.

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!

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

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

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.

7

projectzero.org

Demo – Your first Zero Application.

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

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

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

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

12

projectzero.org

Demo – REST in Project Zero,

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.

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.

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

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.

17

projectzero.org

Default Attributes (subset)

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.

19

projectzero.org

Demo – Officemon sample.

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.

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 ]

22

projectzero.org

Java Bridge

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

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

25

projectzero.org

XAPI-J example

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.

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.

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

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.

30

projectzero.org

PROJECT ZERO COMMUNITYWWW.PROJECTZERO.ORG

31

projectzero.org

32

projectzero.org

Questions?

33

projectzero.org

Acknowledgements

Java is a trademark of Sun Microsystems Inc.

top related