F GAELYK
                          a lightweight Groovy toolkit
                          for Google App Engine



       ...
Guillaume Laforge
            Groovy Project Manager
                   on Groovy since 2003!
            JSR-241 Spec Lea...
Cloud
  Computing
mercredi 19 mai 2010
IaaS, PaaS, SaaS

            Software as a Service
                   Gmail, SalesForce.com   SaaS
            Platform a...
IaaS, PaaS, SaaS

            Software as a Service
                   Gmail, SalesForce.com   SaaS
            Platform a...
IaaS, PaaS, SaaS

            Software as a Service
                   Gmail, SalesForce.com   SaaS
            Platform a...
http://gaelyk.appspot.com




mercredi 19 mai 2010
                                  F
http://gaelyk.appspot.com




mercredi 19 mai 2010
                                  F
mercredi 19 mai 2010
Gaelyk
            Gaelyk is a lightweight Groovy toolkit on top of the
            Google App Engine Java SDK

          ...
Why Groovy?
            Groovy is a dynamic language for the JVM
                   very flexible, malleable, expressive an...
First steps...




       • Go to http://gaelyk.appspot.com
       • Download the template project
       • Put your first ...
The web.xml
                                                                                       ">
                    ...
MVC: Groovlets and templates

                       Groovlets                  Templates
                       (controll...
A groovlet
            Instead of writing full-blown servlets, just write
            Groovy scripts (aka Groovlets)
     ...
A template
                       <html>
                           <body>
                                <p><%
         ...
Shortcuts                              Variables available
                                             request / response...
Groovy sugar!




mercredi 19 mai 2010
Sending emails with Gaelyk

                       mail.send to: 'foobar@gmail.com',
                           from: 'oth...
...compared to Java
    Properties props = new Properties();
                                                     ops, nul...
Accessing the datastore
            Direct interaction with the low-level datastore API
                                  ...
Querying to be improved...
                  import com.google.appengine.api.datastore.*
                                 ...
...into something groovier?

                       def entities = datastore.createQuery {
                           sele...
...into something groovier?

                       def entities = datastore.createQuery {
                           sele...
Task queue API
                       // access a configured queue using the subscript notation
                       que...
Jabber / XMPP support (1/3)
            Sending instant messages

                       String recipient = "someone@gmail...
Jabber / XMPP support (2/3)
            Sending instant messages with an XML payload
                       String recipie...
Jabber / XMPP support (2/3)
            Sending instant messages with an XML payload
                       String recipie...
Jabber / XMPP support (3/3)
            Receving incoming instant messages
                   Configure the XmppServlet in ...
Memcache service
            Map notation access to the cache

                                                           ...
URL Routing system
            You can have friendly URL mappings with the URL
            routing system introduce in Gae...
Simple plugin system (1/3)
            Gaelyk 0.4 introduces a simple plugin system for
            extending your apps an...
Simple plugin system (2/3)
            A plugin is actually just a zip file!
                   Basically, just a Gaelyk ap...
Simple plugin system (3/3)
            An example plugin descriptor
                   /WEB-INF/plugins/jsonPlugin.groovy
...
What’s coming next?
            Gaelyk 0.4 was released a few days ago
                   Features a lightweight plugin sy...
Summary
            Easy access to a cloud solution
                   Deploying Java apps, as easily as you would with PH...
Questions & Answers




mercredi 19 mai 2010
Thanks for your attention!


                                          e
                                    aforg pment
 ...
Images used in this presentation
            Clouds
                   http://www.morguefile.com/archive/display/627059
   ...
Upcoming SlideShare
Loading in...5
×

Gaelyk quickie - GR8Conf Europe 2010 - Guillaume Laforge

3,112

Published on

Published in: Technology, Business
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
3,112
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
7
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Gaelyk quickie - GR8Conf Europe 2010 - Guillaume Laforge

  1. 1. F GAELYK a lightweight Groovy toolkit for Google App Engine Guillaume Laforge SpringSource, a division of VMWare mercredi 19 mai 2010
  2. 2. Guillaume Laforge Groovy Project Manager on Groovy since 2003! JSR-241 Spec Lead Head of Groovy Development at SpringSource (division of VMWare) Initiator of the Grails framework Creator of the Gaelyk toolkit Co-author of Groovy in Action International speaker mercredi 19 mai 2010
  3. 3. Cloud Computing mercredi 19 mai 2010
  4. 4. IaaS, PaaS, SaaS Software as a Service Gmail, SalesForce.com SaaS Platform as a Service Google App Engine PaaS Infrastructure as a Service Amazon EC2 IaaS mercredi 19 mai 2010
  5. 5. IaaS, PaaS, SaaS Software as a Service Gmail, SalesForce.com SaaS Platform as a Service Google App Engine PaaS Infrastructure as a Service Amazon EC2 IaaS mercredi 19 mai 2010
  6. 6. IaaS, PaaS, SaaS Software as a Service Gmail, SalesForce.com SaaS Platform as a Service Google App Engine PaaS Infrastructure as a Service Amazon EC2 IaaS mercredi 19 mai 2010
  7. 7. http://gaelyk.appspot.com mercredi 19 mai 2010 F
  8. 8. http://gaelyk.appspot.com mercredi 19 mai 2010 F
  9. 9. mercredi 19 mai 2010
  10. 10. Gaelyk Gaelyk is a lightweight Groovy toolkit on top of the Google App Engine Java SDK Gaelyk builds on Groovy’s servlet support Groovlets: Groovy scripts instead of raw servlets! Groovy templates: JSP-like template engine Both allow for a clean separation of views and logic Gaelyk provides several enhancements around the GAE Java SDK to make life easier, thanks to Groovy’s dynamic nature mercredi 19 mai 2010
  11. 11. Why Groovy? Groovy is a dynamic language for the JVM very flexible, malleable, expressive and concise syntax easy to learn for Java developers deriving from the Java 5 grammar provides powerful APIs to simplify the life of developers possibility to dynamically enrich existing APIs support for Groovlets and its own template engine The truth: We worked with the Google App Engine Java team before the official launch of the platform, to ensure Groovy would run well on this new environment mercredi 19 mai 2010
  12. 12. First steps... • Go to http://gaelyk.appspot.com • Download the template project • Put your first Groovlet in /WEB-INF/ groovy • And your templates at the root • And you’re ready to go! mercredi 19 mai 2010
  13. 13. The web.xml "> <web-app xmlns="http://java.sun.com/xml/ns/javaee" version="2.5 <servlet> <servlet-name>GroovletServlet</servlet-name> <servlet-class>groovyx.gaelyk.GaelykServlet</servlet-class> </servlet> <servlet> <servlet-name>TemplateServlet</servlet-name> -class> <servlet-class>groovyx.gaelyk.GaelykTemplateServlet</servlet </servlet> <servlet-mapping> <servlet-name>GroovletServlet</servlet-name> <url-pattern>*.groovy</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>TemplateServlet</servlet-name> <url-pattern>*.gtpl</url-pattern> </servlet-mapping> <welcome-file-list> <welcome-file>index.gtpl</welcome-file> </welcome-file-list> </web-app> mercredi 19 mai 2010
  14. 14. MVC: Groovlets and templates Groovlets Templates (controllers) (views) Entities (domain) mercredi 19 mai 2010
  15. 15. A groovlet Instead of writing full-blown servlets, just write Groovy scripts (aka Groovlets) def numbers = [1, 2, 3, 4] def now = new Date() html.html { body { numbers.each { number -> p number } p now } } mercredi 19 mai 2010
  16. 16. A template <html> <body> <p><% def message = "Hello World!" print message %> </p> <p><%= message %></p> <p>${message}</p> <ul> <% 3.times { %> <li>${message}</li> <% } %> </ul> </body> </html> mercredi 19 mai 2010
  17. 17. Shortcuts Variables available request / response Google services context / applicaiton datastore session blobstore params / header memcache out / sout / html urlFetch localMode / app.* mail userService / user Methods available defaultQueue / queues include / forward / redirect xmpp print / println mercredi 19 mai 2010
  18. 18. Groovy sugar! mercredi 19 mai 2010
  19. 19. Sending emails with Gaelyk mail.send to: 'foobar@gmail.com', from: 'other@gmail.com', subject: 'Hello World', htmlBody: '<bold>Hello</bold>' mercredi 19 mai 2010
  20. 20. ...compared to Java Properties props = new Properties(); ops, null); Ses sion session = Session.getDefaultInstance(pr String msgBody = "..."; try { Message msg = new MimeMessage(session); m", "Admin"));     msg.se tFrom(new InternetAddress("admin@example.co TO,     msg.addRecipient(Message.RecipientType. "Mr. User"));                      new InternetAddress("user@example.com", n activated");     msg .setSubject("Your Example.com account has bee     msg.setText(msgBody);     Transport.send(msg); } catch (AddressException e) {} } catch (MessagingException e) {} mercredi 19 mai 2010
  21. 21. Accessing the datastore Direct interaction with the low-level datastore API ty import com.google.appengine.api.datastore.Enti   Entity entity = new Entity("person")   map // subscript notation, like when accessing a entity['name'] = "Guillaume Laforge"   // normal property access notation entity.age = 32 entity.save() entity.delete() datastore.withTransaction { // do stuff with your entities // within the transaction } mercredi 19 mai 2010
  22. 22. Querying to be improved... import com.google.appengine.api.datastore.* der.* import static com.google.appengine.api.datastore.FetchOptions.Buil   // query the scripts stored in the datastore def query = new Query("savedscript")   // sort results by descending order of the creation date query.addSort("dateCreated", Query.SortDirection.DESCENDING)   author // filters the entities so as to return only scripts by a certain r) query.addFilter("author", Query.FilterOperator.EQUAL, params.autho   PreparedQuery preparedQuery = datastore.prepare(query)   // return only the first 10 results def entities = preparedQuery.asList( withLimit(10) ) mercredi 19 mai 2010
  23. 23. ...into something groovier? def entities = datastore.createQuery { select from: savedscript sort DESC, on: dateCreated where author == params.author limit 10 } as List mercredi 19 mai 2010
  24. 24. ...into something groovier? def entities = datastore.createQuery { select from: savedscript sort DESC, on: dateCreated where author == params.author te d! limit 10 en } as List l p em t Im t Ye N o mercredi 19 mai 2010
  25. 25. Task queue API // access a configured queue using the subscript notation queues['dailyEmailQueue']   // or using the property access notation queues.dailyEmailQueue   // you can also access the default queue with: queues.default defaultQueue // add a task to the queue queue << [ countdownMillis: 1000, url: "/task/dailyEmail", taskName: "sendDailyEmailNewsletter", method: 'PUT', params: [date: '20090914'], payload: content ] mercredi 19 mai 2010
  26. 26. Jabber / XMPP support (1/3) Sending instant messages String recipient = "someone@gmail.com"   // check if the user is online if (xmpp.getPresence(recipient).isAvailable()) { // send the message def status = xmpp.send(to: recipient, body: "Hello, how are you?")   // checks the message was successfully // delivered to all the recipients assert status.isSuccessful() } mercredi 19 mai 2010
  27. 27. Jabber / XMPP support (2/3) Sending instant messages with an XML payload String recipient = "service@gmail.com"   // check if the service is online if (xmpp.getPresence(recipient).isAvailable()) { // send the message def status = xmpp.send(to: recipient, xml: { customers { customer(id: 1) { name 'Google' } } })   // checks the message was successfully delivered to the service assert status.isSuccessful() } mercredi 19 mai 2010
  28. 28. Jabber / XMPP support (2/3) Sending instant messages with an XML payload String recipient = "service@gmail.com"   // check if the service is online if (xmpp.getPresence(recipient).isAvailable()) { // send the message def status = xmpp.send(to: recipient, xml: { customers { customer(id: 1) { <customers> name 'Google' <customer id=’1’> } <name>Google</name> } </customer> }) </customers>   // checks the message was successfully delivered to the service assert status.isSuccessful() } mercredi 19 mai 2010
  29. 29. Jabber / XMPP support (3/3) Receving incoming instant messages Configure the XmppServlet in web.xml Add the inbound message service in appengine-web.xml // get the body of the message message.body // get the sender Jabber ID message.from // get the list of recipients Jabber IDs message.recipients   // if the message is an XML document instead of a raw string message if (message.isXml()) { // get the raw XML message.stanza // get a document parsed with XmlSlurper message.xml } mercredi 19 mai 2010
  30. 30. Memcache service Map notation access to the cache } class Country implements Serialzable { String name   def countryFr = new Country(name: 'France')   in the cache // use the subscript notation to put a country object // (you can also use non-string keys) memcache['FR'] = countryFr   // check that a key is present in the cache if ('FR' in memcache) { the cache using a key // use the subscript notation to get an entry from def countryFromCache = memcache['FR'] } mercredi 19 mai 2010
  31. 31. URL Routing system You can have friendly URL mappings with the URL routing system introduce in Gaelyk 0.3.2 all "/blog/@year/@month/@day/@title", @day@title=@title" forward: "/blog.groovy?year=@year&month=@month@day= get "/blog/@year/@month/@day", @day" forward: "/blog.groovy?year=@year&month=@month@day= all "/aboutus", redirect: "/blog/2008/10/20/about-us" get "/book/isbn/@isbn", forward: "/book.groovy?isbn=@isbn", validate: { isbn ==~ /d{9}(d|X)/ } mercredi 19 mai 2010
  32. 32. Simple plugin system (1/3) Gaelyk 0.4 introduces a simple plugin system for extending your apps and share commonalities A plugin lets you provide additional groovlets and templates contribute new URL routes add new categories define variables in the binding provide any static content add new libraries do any initialization mercredi 19 mai 2010
  33. 33. Simple plugin system (2/3) A plugin is actually just a zip file! Basically, just a Gaelyk application, minus... the Groovy / Gaelyk / GAE JARs the web.xml and appengine-web.xml descriptors But with a /WEB-INF/plugins/myplugin.groovy descriptor A plugin must be referenced in /WEB-INF/ plugins.groovy with install myplugin shortcut to /WEB-INF/plugins/myplugin.groovy mercredi 19 mai 2010
  34. 34. Simple plugin system (3/3) An example plugin descriptor /WEB-INF/plugins/jsonPlugin.groovy import net.sf.json.* import net.sf.json.groovy.*   // add new variables in the binding binding { le jsonLibVersion = "2.3"          // a simple string variab  of a 3rd‐party JAR json = new JsonGroovyBuilder()  // an instance of a class }   // add new routes with the usual routing system format routes { get "/json", forward: "/json.groovy" }   // install a category you've developped categories jsonlib.JsonlibCategory   // any other initialization code you'd need mercredi 19 mai 2010
  35. 35. What’s coming next? Gaelyk 0.4 was released a few days ago Features a lightweight plugin system A 0.4.1 bug fix is coming soon Expect more sugar around the Datastore An SQL-like query DSL Easier relationship management (builder) Perhaps pre-compiled groovlets and templates More generally... Anything that’ll come up in upcoming GAE SDK versions mercredi 19 mai 2010
  36. 36. Summary Easy access to a cloud solution Deploying Java apps, as easily as you would with PHP Familiar to Java folks Your good old Servlet centric webapps style Pretty cheap You need a high-trafficed website to reach the quotas Gaelyk provides a simplified approach to creating Servlet centric webapps in a productive manner Leveraging Groovy’s servlet / template support and dynamic capabilities mercredi 19 mai 2010
  37. 37. Questions & Answers mercredi 19 mai 2010
  38. 38. Thanks for your attention! e aforg pment ume L Develo Guilla Groovy Hea d of m ail.com afo rge@g E mail: gl glaforge @ T witter : References: • http://gaelyk.appspot.com/ • http://groovy.codehaus.org/ • http://code.google.com/appengine/ mercredi 19 mai 2010
  39. 39. Images used in this presentation Clouds http://www.morguefile.com/archive/display/627059 http://www.morguefile.com/archive/display/625552 http://www.morguefile.com/archive/display/629785 Duke ok GAE http://code.google.com/images/duke-on-gae.jpg http://weblogs.java.net/blog/felipegaucho/archive/ae_gwt_java.png Python logo : http://python.org/images/python-logo.gif Gaelyc cross with clouds : http://www.morguefile.com/archive/display/37889 Speed limit : http://www.morguefile.com/archive/display/18492 Warehouse : http://www.morguefile.com/archive/display/85628 Snow foot steps : http://www.flickr.com/photos/robinvanmourik/2875929243/ Sugar : http://www.flickr.com/photos/ayelie/441101223/sizes/l/ mercredi 19 mai 2010
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×