6. What is Phobos?
● Lightweight web application framework
● Running on the Java™ platform
● All application logic is JavaScript
● Most of the framework itself is in JavaScript
● Deploy to any servlet container
● IDE support for ease of development
6
10. Development Process
1. Start NetBeans
2. Create skeleton application using wizard
3. Run it in debug mode
4. Map out the URLs for pages, services, Ajax
5. Attach logic to them
6. Test out interactively
7. Go back to step 4, repeat
8. Stop the application, you're done
10
11. Tool Support
● Phobos ships as NetBeans plugins
● Project and component wizards
● jMaki widget palette
● Multithreaded debugger
– Breakpoints, inspectors, watches, ...
● Server runs embedded in the IDE
11
13. Defining New Patterns
● Add new rules at startup or on the fly
application.mapping.rules.push({
url: ”/feed/@id”,
factory: quot;module.atom.createFeedResourcequot;,
fn: quot;library.mapping.maybeRESTquot;
});
Named functions in yellow
13
17. Using JavaScript Libraries
● No special treatment for built-in libraries
● Dojo 0.9, Prototype, YUI all usable
● Load them in a controller (or using an
event handler)
library.dojo.load(“/application/dojo0.9”);
library.scripting.run(“prototype.js”);
● Be careful in modifying Object.prototype
and friends in the presence of pooling
● Other globals OK
17
18. Scripting Engine Integration
● Optional compilation to bytecode
● Compiled scripts are cached
● Engines are pooled
● Works with any JSR-223 engine
● JavaScript engine hooked to debugger API
18
19. Using Java Libraries
● Complete interoperability
– Call into any Java libraries
– Implement any Java interfaces
– Subclass any Java classes
● Phobos can coexist with regular servlets
and any Java web framework
● Tap into any Java libraries you need
19
20. Mozilla Rhino + Extensions
● Dynamic objects via JSAdapter
● E4X
● property get/set with Rhino 1.6R6
● Lots of constructs become possible:
– autoloaded modules
– builders
– multiple inheritance
– missing_method / doesNotUnderstand:
20
21. E4X
● ECMA 357
● XML support at the language level
– literals, namespaces, interpolation
● XPath like syntax
doc..*::customer.@name
● for each construct
● Powerful, not entirely intuitive
21
22. E4X - Examples
// HTML
var doc = <html/>;
doc.head.title = “Hello, world!”;
doc.body.@bgcolor = “#224466”;
doc.body.p = “What's up, doc?”;
// ATOM
var nsATOM = new Namespace(quot;atomquot;, quot;http://www.w3.org/2005/Atomquot;);
default xml namespace = nsATOM;
var doc = <entry><title>{args.title}</title><summary>{args.summary}
/summary></entry>;
22
24. Response Post-Processing
● Capture rendered page
● HTML parsed to DOM via TagLib
● Post-processing stage is similar to the
browser model
– scripts traverse/modify the document object
● Unified programming model
24
26. jMaki Support in Phobos
● Built-in library.jmaki
● Configured with JSON
● Use common resource layout
● Widget palette in NetBeans
● Small footprint
– Widget libraries added on first use
26
27. REST Support
● Not controller-based
● Resources are classes
● Methods are HTTP methods
● Code deals with HTTP entities
● Framework takes care of HTTP details
.e.g. ETags, conditional operations, etc.
● Sample AtomPub server
27
28. Asynchronous Tasks
● Multithreaded runtime
● Schedule scripts for execution in the
background
● Pass arguments in JSON format
● library.lang.invokeAsync calls a named
function in a new thread
● Currently prototyping an Actor library
● Alternative: XMLHttpRequest-like object
28
29. Persistence Options
● Java solutions more mature
– JavaScript wrapper for Java Persistence
– Native JavaScript DB API on top of JDBC
● Pure JavaScript solutions being developed
– ActiveRecord port to JavaScript
– Port of low-level Gears API
– Port of GearsORM**
29
30. “Soft” Scripting Engines
● Non-embedded DSL facility
● Translate to favorite target language
● Plug new languages
● Implemented by one JavaScript function
● Inherit debugging support from lower layer
● Example: Narrative JavaScript (.njs files)
30
31. Narrative JavaScript
● New “yield” operator (->) for async calls
● Implemented as a preprocessor
● Separate browser/server runtime
● End goals:
– Painless asynchronous processing
– Continuation-like behavior without the cost
31
32. IDE in the Browser
● Ongoing work
● Started with the “system apps” concept
● In-browser debugger prototype
● Running in the same space as the
debuggee
● Some careful separation is in order...
32
34. GlassFish V3
● Next-generation application server
● Open source, open development process
● Small footpring, fast startup
● Modular, extensible
● Ideal container for scripting applications
34
35. Conclusions
● JavaScript is a real language
● Dynamic characteristics valuable on the
server too
● Implementations getting more
sophisticated every day
● Great integration with Java libraries and
frameworks
● The question is: why not?
35