Building your next business with Google technologies Google App Engine & Google Web Toolkit
Part One - Introduction Hosting on Google Google App Engine Developing amazing web applications the easy way Google Web Toolkit
Some homework Set up your Java App Engine environment Google Plugin for Eclipse App Engine SDK
Hosting on Google
Some App Engine Partners
Managing Everything is Hard
DIY Hosting means hidden costs Idle capacity Software patches & upgrades License fees Lots of maintenance Traffic & utilization forecasting Upgrades
Google App Engine
Easy to build Easy to manage Easy to scale
Google App Engine “We wear pagers so you don’t have to”
Google App Engine
Appservers: What do they do?
Many applications Many concurrent requests Smaller app footprint + fast requests = more apps
Enforce Isolation Keeps apps safe from each other
Enforce statelessness Allows for scheduling flexibility
Service API requests
App Server
1. Checks for cached instance If it exists, no initialization
2. Execute request 3. Cache the instance System is designed to maximize caching
Slow first request, faster subsequent requests Optimistically cache data in your instances!
Web-based Admin Console
Web-based Admin Console
API Requests App Server
1. 2. 3. 4. 5.
App issues API call App Server accepts App Server blocks runtime App Server issues call Returns the response Use APIs to do things you don't want to do in your runtime, such as...
Basic Services Memcache
Mail
Images
Datastore
URL Fetch
XMPP
Cron
Blobstore
User Service
Specialized Services XMPP API - Send & Receive Channel API - Browser Push Fast Image Serving Matcher API Mapper Library Task Queue OpenID / OAuth
App Master
App Servers Serve dynamic requests Where your code runs App Master Schedules applications Informs Front Ends
App Engine Requests
Routed to the nearest Google datacenter Travels over Google's network to App Engine Frontends Same infrastructure other Google products use Lots of advantages for free
Request For Dynamic Content Routing at the Frontend
Front Ends route dynamic requests to App Servers
Request for Static Content Static Content Servers
Google Static Content Serving Built on shared Google Infrastructure Static files are physically separate from code files Specialized infrastructure App runtimes don't serve static content
Always free to get started - Example quotas 6.5 CPU hrs/day 1 GB storage 657K URL Fetch calls / day 2,000 recipients emailed / day 1 GB/day bandwidth 1,000,000 tasks enqueued 46,000,000 XMPP messages/day 26
Language runtimes
Extended Language support through JVM Java Scala JRuby (Ruby) Mirah Groovy Quercus (PHP) Rhino (JavaScript) Jython (Python) Clojure (Lisp)
Mirah: Making Java feel dynamic
Type inference Ruby syntax Blocks Closures Metaprogramming
Still statically compiles to fast bytecode with no runtime dependencies.
import javax.swing.* frame = JFrame.new "Welcome to Mirah" frame.setSize 300, 300 frame.setVisible true button = JButton.new "Press me" frame.add button frame.show button.addActionListener do |event| button.setText "Mirah Rocks!" end
Mirah
Works with App Engine, Android, and GWT. Still experimental, but getting closer to version 1.0
www.mirah.org
What’s new? Always On Large API Calls Channel API Mapper API Multitenant Apps with Namespace API High Performance Image Serving OpenId/Oauth integration High Replication Database Increased quotas Can pause Task Queues And other stuff.. See: http://googleappengine.blogspot. com/
App Engine Roadmap http://code.google.com/appengine/docs/roadmap.html
Background servers
Improved monitoring/alerting
SSL for your domain Hosted SQL
Datastore dump and restore facility
Mapping operations across datasets
Google App Engine for Business Same scalable cloud hosting platform. Designed for the enterprise.
Enterprise application management
Centralized domain console Enterprise reliability and support 99.9% Service Level Agreement Premium Developer Support Hosted SQL Managed relational SQL database in the cloud SSL on your domain Including "naked" domain support Secure by default Integrated Single Sign On (SSO) Pricing that makes sense Pay only for what you use
Google App Engine for Business
Google Web Toolkit Helping you create amazing web applications
Agenda Introduction Why in Java? Feature tour Developer productivity Compiler magic Need for speed Q&A
Mission statement "GWT's mission is to radically improve the web experience for users by enabling developers to use existing Java tools to build no-compromise AJAX for any modern browser."
Focus Productivity for developers Language, IDEs, tools, libraries People, ecosystem
Performance for your users 'Perfect' caching Whole program optimization Better than practical hand written code
Optimizing the entire development cycle Write
Debug
Optimize
Run
Core Java APIs
JVM Debugging
GWT Compiler
Desktop
Widgets
Development Mode
Image Bundle (Sprites)
Mobile
CSS Magic
Online/Offline
End User Performance
Gadgets
A real browser Libraries
Java IDEs
Developer Productivity
GWT Browser-Proofs Your JavaScript Code...
IE
Firefox
Safari Chrome
Opera
So what can you build with Google Web Toolkit?
GWT App Gallery http://gwtgallery.appspot.com/
Google products
Why in Java?
Can you find the bug?
Hint: JavaScript is a dynamic language
Catch errors at compile time
Java is a static language
Feature tour
More than just a compiler Development Mode
History just works
Pre-built widgets, e.g. Rich Text Area
RTL, I18N, L10N, A11Y
Simple, Powerful RPCs interface SpellService extends RemoteService { /** * Checks spelling and suggests * alternatives. * @param the word to check * @return the list of alternatives */ String[] suggest(String word); }
Widget Libraries GWT (http://code.google.com/webtoolkit/) Incubator (http://code.google.com/p/google-web-toolkit-incubator/) Smart GWT (http://code.google.com/p/smartgwt/) GWT-Ext (http://code.google.com/p/gwt-ext/) Vaadin (IT Mill Toolkit) (http://vaadin.com/) GWT mosaic (http://code.google.com/p/gwt-mosaic/) Ext GWT (http://extjs.com/products/gxt/) Advanced GWT Components (http://advanced-gwt.sourceforge.net/)
Developer productivity
GWT 2.0 operating modes Development Mode All about productivity Java + JavaScript In a real browser
Production Mode All about performance Compiled, pure JavaScript/CSS/HTML
Development Mode
Web Server
Code Server
Java Virtual Machine Duke, the Java mascot Copyright © Sun Microsystems Inc., all rights reserved.
Google Plugin for Eclipse
The end of the preaching
Fast is better than slow > Minimize bandwidth l Can you use gzip encoding? l Is your CSS compiled/minimized? > Limit your HTTP-requests l Do your user agent support multipart? l Can you leverage spriting? (minimize that whitespace!)
Conclusion >Know your audience. >Target devices based on your target market. >Render your content intelligently: leverage existing libraries to know their capabilities.
Part Two - Going Deeper Programming in App Engine Build simple app using key App Engine components Q&A Competition
Java Environment Apps run in the Java 6 virtual machine (JVM) App Engine SDK supports Java 5 and higher Uses the Java servlet standard for web apps Heavy use of common Java standards where possible JDO/JPA for Datastore JavaMail for Email Service java.net for URL Fetch Service JVM instance for each app is sandboxed for security No threads, local file system access or arbitrary network connections Seamless development in Eclipse via Google Eclipse Plugin Development server runs locally and simulates Datastore, services and sandbox restrictions
Python Environment Support for Python 2.5 or higher App interacts with the App Engine web server via the Common Gateway Interface (CGI) protocol Support for any WSGI-capable web application framework such as Django and and CherryPy Python interpreter runs in a sandbox for security No threads, local file system access, modules with C code or arbitrary network connections Tools for testing, uploading application files, managing Datastore indexes, downloading log data, etc. Development server runs locally and simulates Datastore, services and sandbox restrictions
Let's get our hands dirty Customer requirement Build a sample guest book application in Python (or Java) Expectations You have completed the Code Lab environment setup after you registered. Instructions here (http://goo.gl/cph4) Follow along the codelab here (http://goo.gl/SWEE)
Case Study: Guest Book App
Demo (goo.gl/tBAw)
Before you start, think about... Programming Language What runtime environment to use? (Python, or, Java) Logging in and logging out How to authenticate users? (Users Service) Storing data How to persist and query data? (Datastore) Look and feel How to design a dynamic UI? (Templates)
Functional requirements Set up your app Java: web.xml & appengine-web.xml Python: app.yaml Authentication: Application can log user in and log user out Application has different behaviour depending on whether a user is logged in or not Logged-out (anonymous) users can post shoutouts and see shoutouts of other anonymous users Logged-in (authenticated) users can post shoutouts and see their own shoutouts Datastore: Store shoutouts in a database
Java: Hello World (http://goo.gl/tBbu)
Java: Authentication
Java : Datastore
Java: Saving a Shoutout
Java: Retrieving Shoutouts
Python: Hello World (http://goo.gl/SWEE)
Python: Authentication
Python: Datastore
Python: Saving a Shoutout
Python: Retrieving Shoutouts greetings = db.GqlQuery("SELECT * FROM Greeting ORDER BY date DESC LIMIT 10") greetings = Greeting.gql("ORDER BY date DESC LIMIT 10") greetings = Greeting.gql("WHERE author = :1 ORDER BY date DESC", users.get_current_user()) greetings = Greeting.gql("WHERE author = :author ORDER BY date DESC", author=users.get_current_user())
Look and feel Separate application logic and appearance Should be easy to update without changing application logic The Java way JSP The Python way Django templates
Python: Templating with Django guestbook.html
Java: Templating with JSP guestbook.jsp
Java: Serving Static Files
Python: Serving Static Files
Uploading to AppEngine Go to appengine.google.com Create an application ID Change your local application ID to match that on appengine.google.com Click the 'Deploy' button to upload it to the Google App Engine cloud View your application at
.appspot.com
Useful App Engine Resources App Engine development in Java - http://goo.gl/hCBC App Engine development in Python - http://goo.gl/yhv5
Q&A
Case Study: StockWatcher App
Demo
Come see us at the Code Clinic Using Google App Engine and Web Toolkit from Eclipse
Appendix
Using Google App Engine + Web Toolkit With Eclipse using the Eclipse plugin
Homework Deploy to App Engine
Channel API Asynchronous Server
Client Communication
Channel-based Bi-directional
Server Send messages via ChannelService object Receive messages in a web hook
Client JavaScript library Receive server messages in a callback
Built on Gmail chat client (Google Talk)
Channel API - Server Interface /** * ChannelService allows you to manage two-way connections * with clients. */ public interface ChannelService { /** * Creates a channel associated with the provided applicationKey */ String createChannel(String applicationKey); /** * Sends a ChannelMessage to the client. */ void sendMessage(ChannelMessage message); /** * Parse the incoming message in request. This method * should only be called within a channel webhook. */ ChannelMessage parseMessage(HttpServletRequest request); }
Channel API - Client (JavaScript) // Create a new channel var channel = new wnd.goog.appengine.Channel(channelId); // Setup communications with the server var socket = channel.open(); socket.onopen = function(event) { // socket is now fully functional }; socket.onmessage = function(event) { // handle string msg (event.data) }; // Hello, server. How are you? socket.send(msg);
Dance Dance Robot
Mapper API Part 1 of the MapReduce story Batch processing at scale Sample Use Cases Report Generation Data export Schema Migration
Built on Task Queues Rate configurable
Mapper API - OSS Project Open source software - Apache 2 license http://mapreduce.appspot.com Patches welcome :)
Entirely user-space Just include it in your project!
Python & Java versions Features Automatic sharding Automatic rate limiting /mapreduce/status Counters Batching datastore operations
Presentations soon on: bit.ly/gksa
Follow the conversation: #gsaudi