Post on 11-May-2015
Copyright 2008 © IBM Corporation
Rob Nicholson - Project Zero
projectzero.orgZero complexity. Zero overhead. Zero obstacles.
Project Zero
Rob Nicholsonrob_nicholson@uk.ibm.com or nicholsr@php.net
2Rob Nicholson - Project Zero
projectzero.org
Zero complexity. Zero overhead. Zero obstacles.
Agenda
What is Project Zero
Why should I care?
Creating Applications and REST web services - DEMO
Assembling Applications - DEMO
Deploying application
Running an existing PHP application - DEMO
Web IDE prototype DEMO
3Rob Nicholson - Project Zero
projectzero.org
Zero complexity. Zero overhead. Zero obstacles.
Introduction
Project Zero is an IBM technology incubator project.
Building a radically simplified platform to enable the productive development and deployment of rich internet applications.
System language is JavaTMTM.Zero runs on a JavaTMTM Virtual Machine.
Supports Linux, Mac and Windows.
Application languages are PHP and Groovy.Zero contains a PHP 5 interpreter written in JavaTMTM
4Rob Nicholson - Project Zero
projectzero.org
Zero complexity. Zero overhead. Zero obstacles.
Some Simplifications We Are Aiming For
Creating new agile web applications.Sharing assets from different languages.
Implementing REST services.
Building a rich user interface.I want to spend less time sorting out browser incompatibilities!Accessibility.
Assembling applications and services.
Deploying applications.Versioning dependencies.
5Rob Nicholson - Project Zero
projectzero.org
Zero complexity. Zero overhead. Zero obstacles.
Top Level 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 PDT Prototype web IDE.
Command line for deployment.
The application is the web server.
REST
6Rob Nicholson - Project Zero
projectzero.org
Zero complexity. Zero overhead. Zero obstacles.
PHP Runtime Architecture • 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)
• Cache and Interpret IR
• Compile ->bytecode prototype
•Extensibility via XAPI
• XAPI-C for C extensions from php.net
• XAPI-J for new Java extensions, native libraries invoked over JNI and Project Zero interface
• Extension language choice opaque to PHP script
•Java 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
7Rob Nicholson - Project Zero
projectzero.org
Zero complexity. Zero overhead. Zero obstacles.
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
8Rob Nicholson - Project Zero
projectzero.org
Zero complexity. Zero overhead. Zero obstacles.
Demo – Your first Zero Application.
See http://www.projectzero.org/wiki/bin/view/Documentation/Videos
9Rob Nicholson - Project Zero
projectzero.org
Zero complexity. Zero overhead. Zero obstacles.
Implementing REST Services
Zero provides a really simple way to create REST services.
REST services fit well with test-driven development.
Convention 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
10Rob Nicholson - Project Zero
projectzero.org
Zero complexity. Zero overhead. Zero obstacles.
REST Services in Project Zero
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
update
deleteCollection
Member/people/1
retrieve
create
postMember delete
11Rob Nicholson - Project Zero
projectzero.org
Zero complexity. Zero overhead. Zero obstacles.
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
12Rob Nicholson - Project Zero
projectzero.org
Zero complexity. Zero overhead. Zero obstacles.
Demo – REST in Project Zero,
See http://www.projectzero.org/wiki/bin/view/Documentation/Videos
13Rob Nicholson - Project Zero
projectzero.org
Zero complexity. Zero overhead. Zero obstacles.
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 eventsFired by your application.
Sharing Assets - Events
14Rob Nicholson - Project Zero
projectzero.org
Zero complexity. Zero overhead. Zero obstacles.
Sharing Assets - Rendering
Zero provides renderers for generating output.Renderers are programming language agnostic.
View renderer serves up script output:zput('/request/view', 'hello.php');
render_view();
XML, JSON and ATOM for well known data types:zput("/request/view", "JSON");
zput("/request/json/output", $obj);
render_view();
Error renderer serves up standard error pages.
15Rob Nicholson - Project Zero
projectzero.org
Zero complexity. Zero overhead. Zero obstacles.
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.
16Rob Nicholson - Project Zero
projectzero.org
Zero complexity. Zero overhead. Zero obstacles.
Global Content Zones
Divided into zones representing different data lifecycles
Zone Scope/Visibility LifecycleConfig All requests all users. Loaded from config
files.Application All requests for all users of the
applicationLife 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
17Rob Nicholson - Project Zero
projectzero.org
Zero complexity. Zero overhead. Zero obstacles.
Accessing the Global Context
Action PHP Example Java Example
Get HTTP Request URI zget (/request/uri) GlobalContext.get("/request/uri"
Get value of user-agent request header
zget(/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
zget(/request/params/ParmName)
((String []) GlobalContext.get("/request/params/parmName"))[0]
Set status zput (/request/status,200) request.status = 200
Of course PHP (super)globals are also available.
18Rob Nicholson - Project Zero
projectzero.org
Zero complexity. Zero overhead. Zero obstacles.
Meerkat Demo
19Rob Nicholson - Project Zero
projectzero.org
Zero complexity. Zero overhead. Zero obstacles.
Java Bridge
20Rob Nicholson - Project Zero
projectzero.org
Zero complexity. Zero overhead. Zero obstacles.
Dojo is the preferred Ajax/JavaScript toolkit for Zero.
Open source toolkit to simplify rich web applications.http://www.dojotoolkit.orgv1.0 released on 5th November 2007.
Addresses key problem with browser compatibility.
Dijit library provides rich set of user interface widgets.Accessibility built inInternationalisedTheme 100% customisable
DojoX adds experimental and specialised extensions.Wire, XML, cryptography, network
Building A Rich User Interface
21Rob Nicholson - Project Zero
projectzero.org
Zero complexity. Zero overhead. Zero obstacles.
Input controls – buttons, combo box, sliders, text areas.
Layout – accordion, split/stack containers, tabs.
Command – button, menu, toolbar.
User assistance and feedback – progress bar, tooltip, dialog.
Advanced editing and display – editor, tree, colour palette
22Rob Nicholson - Project Zero
projectzero.org
Zero complexity. Zero overhead. Zero obstacles.
Dojo Core Widget Set (Dijit) Accessibility
ARIA specification implemented in all widgets.Fully keyboard accessible in Firefox and Internet Explorer.
Screen reader accessible in Firefox.
Works in operating system high-contrast mode (system colours).
Works with images off (regular <img> tags).Currently only auto-detected in Firefox.
Must be in high contrast mode for image-off support in Internet Explorer.
More information available from: http://www.w3.org/WAI/intro/aria.
23Rob Nicholson - Project Zero
projectzero.org
Zero complexity. Zero overhead. Zero obstacles.
Deploying Applications
Web server
Application Code
Language runtimes
JVM
The application is the server
Hundreds of applications per box.
Applications started on demand – inetd style
Applications isolation
Quality of service and management built in.
24Rob Nicholson - Project Zero
projectzero.org
Zero complexity. Zero overhead. Zero obstacles.
Deploying on the command linePackage 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 ]
See http://www.projectzero.org/wiki/bin/view/Documentation/Videos
25Rob Nicholson - Project Zero
projectzero.org
Zero complexity. Zero overhead. Zero obstacles.
Versioning Dependencies
Modules are the building blocks of an application.
A module is simply a collection of files packaged together.Includes a module name, version and author details.
An 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
26Rob Nicholson - Project Zero
projectzero.org
Zero complexity. Zero overhead. Zero obstacles.
Visual assembly of feeds and flows - Assemble
http://www.projectzero.org/wiki/bin/view/Documentation/Videos
27Rob Nicholson - Project Zero
projectzero.org
Zero complexity. Zero overhead. Zero obstacles.
PHP Application Demo
28Rob Nicholson - Project Zero
projectzero.org
Zero complexity. Zero overhead. Zero obstacles.
Web tool prototype
29Rob Nicholson - Project Zero
projectzero.org
Zero complexity. Zero overhead. Zero obstacles.
Installing Project 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.
Community, blogs, questions, answers, opinions and thoughts:http://www.projectzero.org/wiki/bin/view/Community/WebHome
30Rob Nicholson - Project Zero
projectzero.org
Zero complexity. Zero overhead. Zero obstacles.
Features of Zero we have not covered today
File Serving
Error Handling
Logging/Tracing/Debugging
Client Programming with Dojo
Security
Nested resources
31Rob Nicholson - Project Zero
projectzero.org
Zero complexity. Zero overhead. Zero obstacles.
PHP Runtime Architecture
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
32Rob Nicholson - Project Zero
projectzero.org
Zero complexity. Zero overhead. Zero obstacles.
XAPI-J example
33Rob Nicholson - Project Zero
projectzero.org
Zero complexity. Zero overhead. Zero obstacles.
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.
34Rob Nicholson - Project Zero
projectzero.org
Zero complexity. Zero overhead. Zero obstacles.
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.
35Rob Nicholson - Project Zero
projectzero.org
Zero complexity. Zero overhead. Zero obstacles.
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
36Rob Nicholson - Project Zero
projectzero.org
Zero complexity. Zero overhead. Zero obstacles.
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.
37Rob Nicholson - Project Zero
projectzero.org
Zero complexity. Zero overhead. Zero obstacles.
PROJECT ZERO COMMUNITYWWW.PROJECTZERO.ORG
38Rob Nicholson - Project Zero
projectzero.org
Zero complexity. Zero overhead. Zero obstacles.
39Rob Nicholson - Project Zero
projectzero.org
Zero complexity. Zero overhead. Zero obstacles.
Summary
Project Zero is incubating technologies to build web applicationsSimply!
Project zero contains a PHP runtime which runs on a JVM.
Project Zero enables same process interoperability between PHP, Java and Groovy.
40Rob Nicholson - Project Zero
projectzero.org
Zero complexity. Zero overhead. Zero obstacles.
Questions?
41Rob Nicholson - Project Zero
projectzero.org
Zero complexity. Zero overhead. Zero obstacles.
Thank You!
42Rob Nicholson - Project Zero
projectzero.org
Zero complexity. Zero overhead. Zero obstacles.
Legal Notices
Java and all Java-based trademarks and logos are trademarks of Sun Microsystems, Inc. in the United States, other countries, or both.
Microsoft, Windows, Windows NT, and the Windows logo are trademarks of Microsoft Corporation in the United States, other countries, or both.
Intel and Pentium are trademarks or registered trademark of Intel Corporation or its subsidiaries in the United States and other countries.
UNIX is a registered trademark of The Open Group in the United States and other countries.
Linux is a trademark of Linus Torvalds in the United States, other countries, or both.
Other company, product, or service names may be trademarks or service marks of others.