240 likes | 400 Views
An Introduction to IBM WebSphere sMash. Robin Fernandes - PHP Runtime for WebSphere sMash robinf@php.net / robin_fernandes@uk.ibm.com . Why WebSphere sMash? . Developers want to: Build Web apps quickly . Re-use and combine existing apps simply .
E N D
An Introduction to IBM WebSphere sMash Robin Fernandes - PHP Runtime for WebSphere sMash robinf@php.net / robin_fernandes@uk.ibm.com Introduction to IBM WebSphere sMash
Why WebSphere sMash? • Developers want to: • Build Web apps quickly. • Re-use and combine existing apps simply. • Take an agile approach to Web app development. • Quick reaction to change • Cost-effective development • Ease of deployment Speed, Simplicity, Agility • Developers are adopting: • Dynamic scripting languages for application logic (PHP, Ruby, Groovy…) • Low barrier to entry, high productivity • Enable “Search, copy and paste” style development • REST, JSON to tie Web Apps together • Simple, works well with Ajax
What is WebSphere sMash? A complete platform for developing, assembling and executing agile Web 2.0 apps quickly and simply. • Started in 2007 as Project Zero, a community driven incubator project • http://projectzero.org • Released as WebSphere sMash product in May 2008 • Built from the ground up with a focus on Speed, Simplicity & Agility
JVM Web server Application Code Language runtimes WebSphere sMash: Speed (time to value) • Quick to get started • Download from projectzero.org and unzip • Scripting languages: low barrier to entry • PHP, Groovy • Convention over configuration • Common tasks shouldn't require configuration • Application-centric runtime • Write the app, run it, and it’s ready for use. • No need for a separate application server. sMash application:
WebSphere sMash: Simplicity • Small number of new concepts in sMash • Scripts, Events, Global Context • Focus on RESTful architecture • Build applications around CRUDL events on Resources • Tooling to encourage use of REST • Trivial deployment • To move an app to another machine: zip, copy, run
WebSphere sMash: Agility • A clean runtime for your applications • Each app has its own JVM process isolation • Short-lived processes (“ZSO” manages startup on 1st request, recycle) • App ready for use in <1s, footprint is ~380KB idle and ~28MB running • Modular architecture • Features and pre-built services downloaded as required • Core modules about ~5MB (includes HTTP stack, Groovy support) • Browser-based tooling for client and server-side development • Includes visual tools to simplify Web app interoperation
RTE DE Versions of WebSphere sMash
Demo: • WebSphere sMash on http://projectzero.org • The AppBuilder • Hello World on WebSphere sMash • Modules
Available Modules • There are 65+ modules available currently • Modules provide function in many categories • Data Formats (JSON, ATOM, RSS, XML) • Data Access • Resource Modelling • Security / Content Filtering • Activity Flows • Services • Amazon ECS, Flickr, Weather, etc • Utilities (such as HTML parsing) • Management Tools • Development Tooling • Reliable Transport Engine for Messaging Interactions
Key Concept: Events • WebSphere sMash initiates well-known system events. • Developers define the application behaviour by implementing event handlers. • Conventions define where sMash will search for event handlers. • Events are stateless. State information is stored in the Global Context.
Key Concept: The Global Context • It’s a map of data! • Language-agnostic • Used for passing data between events, for storing application state • Zones define the life time of the data: Non-persistent Spot the zget() & zput() calls in the next demo! Persistent http://www.projectzero.org/sMash/1.0.x/docs/zero.devguide.doc/zero.core/GlobalContextReference.html
Key Concept: RESTful Architecture • What is REST? • Application is defined in terms of Resources • Resources are exposed as URIs • Behaviour is governed by HTTP requests on these URIs • Standard HTTP methods specify the action to carry out on the resource (POST / GET / PUT / DELETE ) • Requests are stateless: HTTP requests contains enough information to carry out the desired operation in full Scalable, because the request can be handled by any back-end system • http://myshop.com/customer • GET: Returns a list of customers • POST: Creates a customer record • http://myshop.com/customer/homer • GET: Retrieves customer record ‘homer’ • PUT: Updates record ‘homer’ • DELETE: Deletes record ‘homer’
Demo: a RESTful Pastebin • What’s a Pastebin? see http://pastebin.com • Website for sharing snippets of text, usually code; get a URL for that snippet. • Useful for collaborating, heavily used by PHP community (help finding bugs in code, submitting patches etc…) • We’ll use the “Zero Resource Model” • The RESTful resource we’ll use in this demo: “snippet” : { “title”: string, “lang” : string, “body” : string }
JVM The PHP Engine • Why PHP in sMash? • Gartner predict that within 5 years, 60% of 5.5 million PHP developers will work in corporate IT (up from 13% of 3M today) • Vast amounts of PHP code available for “search/copy/paste” development • Wikipedia, Facebook, Flickr, Yahoo, phpBB, SugarCRM… • http://php.net: the de facto standard PHP engine • Open Source, written in C • Vast array of extension functions (String, image manipulation, IMAP…) • Why write a PHP engine in Java for sMash? • Dynamic Languages + JVM =♥ • Excellent interop with sMash’s Java APIs – and with any Java code!
PHP Engine Architecture Debug API (DBGp) Runtime • Runtime for PHP 5 scripts • Implemented in Java, runs on any Java 5+ VM • Parse script to intermediate representation • Compile to bytecode • JVM executes the bytecode • Bytecode calls back into runtime to access PHP language elements, which are represented as Java objects • 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 • Debug via DBGp using Eclipse with PDT PHP Scripts sMash CLI SAPI - J PHP Engine AST Parser P8 Runtime Variables Compiler opcodes Stack Interpreter Resources .class Classes Objects Cache XAPI-J XAPI-C Java Extensions C Extensions Native code sMash Extensions
PHP Language Support • Core PHP extensions supported • Currently supports a subset of PHP extensions • The goal is maximum re-use of existing PHP scripts and applications. phpBB SugarCRM
Two levels of PHP/Java Integration • <?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 to Java Map • var_dump($map->get("stuff"))."\n"; • ?> • Direct use of Java objects in PHP Code:
Two levels of PHP/Java Integration • Use annotations and a thin wrapper around your Java code • Allows definition of PHP specific attributes that could not be represented in plain Java code. @XAPIClass("ArrayObject") publicfinalclassArrayObjectDescriptor { @XAPIMethod(name = "setIteratorClass") @XAPIForbidStaticCalls @XAPIArguments( PassSemantics = { XAPIPassSemantics.ByValue }, MandatoryArguments = 1, MaximumArguments = 2, DefaultValues = { "ArrayIterator" } ) publicstaticvoid setIteratorClass(RuntimeContextStack runtime, intargsPassed){ //...
Show PHP interacting with a custom Java asset Demo: PHP / Java Integration PHP Code PHP Runtime in sMash Your Java code AST Generator! JVM
Features we didn’t cover • Client Programming with the Dojo Framework • Assemble Tooling • Data APIs • Security • Eclipse-based tooling • REST to SOAP adapter • Reliable Messaging • Error Handling • Logging, Tracing, Debugging • …
Summary • WebSphere sMash: • Runtime optimized for quickly and easily creating situational applications • Low barrier to entry • Browser-based tooling for client and server side development • Convention over configuration • Focus on REST • Java/PHP/Groovy interoperability • All, including PHP, run on the JVM
http://projectzero.org Community site for users and developers • Content • Documentation and User Guides • Design documents and Roadmaps • Demos and Samples • Forum for interactive discussion • Help and Feedback for questions from users • Developer Alerts to notify users of new features and breaking changes • Development discussion • 3554 Posts on 828 Topics to date • Blogs • Development blog with interesting commentary, demos, and opinion • News blog for project announcements • Binary Downloads (500,000 and counting…) • Bug Tracking System (Bugzilla) • Source code (Subversion)
Links • http://projectzero.org • Search for WebSphere sMash onhttp://www.ibm.com/developerworks • Thanks to the following for presentation material: • Colin Thorne, Stuart Hayton, Don Boulia, Rob Nicholson, Roland Barcia, Steve Ims Robin Fernandes robinf@php.net robin_fernandes@uk.ibm.com
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.