Archive

Posts Tagged ‘Google App Engine’

Google Wave Robots: A Pictured Java Tutorial

September 24th, 2009

This post is a reference to Google’s own Java Tutorial for Google Wave Robots with an example of robot code that performs word replacement.

In my previous post, I have also briefly explained what Google Wave is about.

What you need to run a simple Java Wave Robot.

1) Eclipse IDE + JDK 6
2) Google Wave Java Client libraries
3) Google App Engine Account

Yes, you only require 3 items but most importantly, to access Google Wave, you need a Google Wave Id.

1) Eclipse IDE + JDK 6

Download Eclipse IDE here : http://www.eclipse.org/downloads/

eclipse_download

Download JDK 6 here : http://java.sun.com/javase/downloads/index.jsp

jdk6_download

Install the Google Plugin and the App Engine SDK:

eclipse_update

Depending on the version of Eclipse IDE you downloaded, you will need to follow Google Wave’s guide to update using either one of the following URL:
http://dl.google.com/eclipse/plugin/3.5
or
http://dl.google.com/eclipse/plugin/3.4

eclipse_update_site

2) Google Wave Java Client libraries
Download the Java client libraries from http://code.google.com/p/wave-robot-java-client/downloads/list
Jar files required are :

  • wave-robot-api-.jar
  • json.jar
  • jsonrpc.jar

Save those files to your project library under \WEB-INF\lib

java_wave_client_lib

3) Code your Wave Robot

You can use Google Wave Java Tutorial source code directly if you want to, but I figure that I need to make some difference and hence thought of a simple words replacement robot.

hack1

hack2

My customization is highlighted in bold, you would want to change it with your own code.

Following is my source code of MarvyServlet (pardon me for the profanity in the source code, but this is a profanity filter robot afterall 🙂 )

package net.marvinlee.marvy;

import com.google.wave.api.*;

public class MarvyServlet extends AbstractRobotServlet {

      @Override
      public void processEvents(RobotMessageBundle bundle) {
        Wavelet wavelet = bundle.getWavelet();

        if (bundle.wasSelfAdded()) {
          Blip blip = wavelet.appendBlip();
          TextView textView = blip.getDocument();
          textView.append("I'm here to ensure you have a nice and polite wave.");
        }

        for (Event e: bundle.getEvents()) {

          if (e.getType() == EventType.WAVELET_PARTICIPANTS_CHANGED) {
            Blip blip = wavelet.appendBlip();
            TextView textView = blip.getDocument();
            textView.append("Hi, everybody! I will be censoring profanities in your conversation.");
          }

          if (e.getType() == EventType.BLIP_SUBMITTED) {
            Blip blip = e.getBlip();
            TextView textView = blip.getDocument();
            String blipText = textView.getText();
            textView.delete();
            textView.append(replaceProfanity(blipText));
          }
        }
      }

        private static String replaceProfanity(String text)
        {
            String[] vulgars = {"shit", "damn", "fark"};
            String[] vulgarReplacement = {"sh#t", "darn", "f##k"};
            String niceText = "";

            System.out.println("Input:" + text);
            for (int i=0; i< vulgars.length; i++)
            {
                String key = vulgars[i];
                if (text.indexOf(key) > 0)
                {
                    text = text.replaceAll(vulgars[i], vulgarReplacement[i]);
                    System.out.println(vulgars[i] + " replaced with " + vulgarReplacement[i] );
                }

                niceText = text;
            }

            System.out.println("Output:" + niceText);
            return niceText;
        } 

    }

capabilities.xml file under _wave

<?xml version="1.0" encoding="utf-8"?>
<w:robot xmlns:w="http://wave.google.com/extensions/robots/1.0">
  <w:capabilities>
    <w:capability name="WAVELET_PARTICIPANTS_CHANGED" content="true" />
    <w:capability name="BLIP_SUBMITTED" content="true" />
  </w:capabilities>
  <w:version>1</w:version>
</w:robot>

web.xml under WEB-INF

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE web-app PUBLIC
 "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
 "http://java.sun.com/dtd/web-app_2_3.dtd">

<web-app xmlns="http://java.sun.com/xml/ns/javaee" version="2.5">
    <servlet>
        <servlet-name>Marvy</servlet-name>
        <servlet-class>net.marvinlee.marvy.MarvyServlet</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>Marvy</servlet-name>
        <url-pattern>/_wave/robot/jsonrpc</url-pattern>
    </servlet-mapping>
</web-app>

appengine-web.xml – marvinleebot is my application name, and is unique in Google App Engine.
If you do not have a Google App Engine yet, follow step 4) below and come back again.

<?xml version="1.0" encoding="utf-8"?>
<appengine-web-app xmlns="http://appengine.google.com/ns/1.0">
    <application>marvinleebot</application>
    <version>1</version>

    <!-- Configure java.util.logging -->
    <system-properties>
        <property name="java.util.logging.config.file" value="WEB-INF/logging.properties"/>
    </system-properties>

</appengine-web-app>

You can make other changes by viewing the Wave JavaDoc.

4) Deploy to Google App Engine
You will need to create an application in your Google App Engine first if you have not.

create_app_engine

You might also need to verify your account with a mobile number, just follow through the steps.
Create your app here : https://appengine.google.com/start
Your app name has to be unique so take some time to figure one or if you’re like me, just a lame bot name like marvinleebot might do the trick.

Once you’re done with your app name and created successfully, make sure that your appengine-web.xml file contains your own app name.

<application><your_app_name_here></application>

When you’re ready, just hit the Deploy App Engine Project button.

eclipse_google_plugin

Submit your App Engine Account Email and Password.

deploy_app_engine

5) Test your Wave Robot

As I’ve mentioned earlier, the single most important thing for it to work is to have a Google Wave Id.

If you have one, you can login Wave Sandbox at http://wavesandbox.com/.

wave_sandbox_login

If you do not have a Google Wave Id yet, request one here.

Create a new wave, and then add the bot you have created by adding a participant : <your_app_name>@appspot.com

This is how the bot looks like and how my marvinleebot worked (click to enlarge). I was using a test Wave Id from Nazroll.

wave_sandbox

You can also monitor your bot/app from your App Engine dashboard.
app_engine

Google, Java, Open Source , , , , ,

Eclipse Day 2009 video presentations

September 14th, 2009

Eclipse Day is not the day the solar eclipse happened.

Eclipse Day 2009 is a full day event for developers to learn about different Eclipse projects and related technologies in Googleplex.

Being a Java Developer, Eclipse is one of the best Java IDE around, and in fact some developer uses Eclipse exclusively.

For non-developers who doesn’t know Eclipse, it is a tool for you to do programming and the tool itself is open source, meaning people can actually read the code on how the program runs, or even build additional tools for it.

Eclipse has grown a lot since founded in 2001, with numerous plugins for various technologies including OSGi, Android, and Google related apps like Google App Engine (GAE), Google Web Toolkit (GWT) and even the upcoming Google Wave (well you can do it on GAE Java ).

Some of the videos recorded from the Eclipse Day 2009.



For the full video listing, visit Google’s Open Source blog.

Google, Open Source, Software , , , , , ,

Build Java web applications and host on Google App Engine for Free

August 18th, 2009

ae_gwt_java

I came to know about Google App Engine (GAE) in 2008 trying to find a host for my OpenSocial app experiment. It boast of a cloud computing architecture, so that when the traffic to your site grows, your application or site will not go down and with Google’s infrastructure, it can accommodate the high traffic.
You do not need to worry about the sudden extreme high load or load balancing for your application.
It is only half true though, read on to know why. 🙂

It sure sounds cool then, but to me the disappointment was it runs only in Python. That was in 2008.

However, there seems to be a lot of Java developers interested with having a Java version for GAE too. I wonder why?

So came the good news, although I came to know about it like a couple of months late. The Java version for GAE indeed has been made available since April 2009.

Official Google App Engine for Java : http://code.google.com/appengine/docs/java/overview.html

The site has everything you need to know and get started on Google App Engine easily, and like any other useful frameworks, they have sample applications with source code bundled together.

Download the Google App Engine SDK for Java here.

In case you would like to have a summary of GAE Java:

JVM Version
App Engine runs on Java 6 virtual machine (JVM), but supports application built on JDK 5 and later. Uses Java Servlet for applications.

Note that not all Java classes are supported but most of them are. See the JRE Class White List here.

As there are so many Java technologies and frameworks, so by default with Google App Engine Java, it basically supports a huge list of libraries and frameworks including GWT (of course), Grails, JSF, MyFaces, Spring MVC, Struts, Tapestry, Tiles and some say OSGI.
For the full list, go here.

Datastore
App Engine supports 2 standard Java interfaces: Java Data Objects (JDO) 2.3 and Java Persistence API (JPA) 1.0.

These interfaces are implemented using DataNucleus Access Platform, the open source implementation of these standards.

Access to database is via JDOQL using POJO (Plain Old Java Objects).

Other Services
Caching: http://code.google.com/appengine/docs/java/memcache/
URL Fetch : http://code.google.com/appengine/docs/java/urlfetch/
Java Mail : http://code.google.com/appengine/docs/java/mail/ (limitation of sending using Google account of the app administrator only)
Also supports application authentication using Google Accounts.
Cron Jobs : http://code.google.com/appengine/docs/java/config/cron.html

The download for GAE Java includes a development server for your computer and you can run and test your application (war file) locally before uploading it to Google server.

The uploading can also be done with its AppCfg command tool.
Do note though, you need to create your application in App Engine Administration Console first, at : https://appengine.google.com/.

Limitation of GAE Java
Knowing the features of GAE Java, you should also probably know a bit of its limitation.

1 The Java datastore interface does not support the != and IN filter operators that are implemented in the Python datastore interface. (In the Python interface, these operators are implemented in the client-side libraries as multiple datastore queries; they are not features of the datastore itself.)
2 Due to the way the App Engine datastore executes queries, a single query cannot use inequality filters (< <= >= >) on more than one property.

Quotas
While you are still excited about the free hosting and the ability to withstand sudden high load for your application, (I’m not sure about DDOS though), there is a quota for the free bandwidth and resources on your Google App Engine Java application.

“App Engine will always remain free to get started. We believe these new levels will continue to serve a reasonably efficient application around 5 million page views per month, completely free.”

So instead of sourcing for web hosting, you get a free hosting for your Java application, which is a good deal considering it’s not easy to find one and to compare them with Google’s infra?
When the need arises and your application is so popular that it gets 5 million page views per month, I guess then it is time you decide to pay for the additional resources, or port your application with funding or sell it to somebody else (or Google?).

CPU Time (billable)

Resource Free Default Quota Billing Enabled Quota
Daily Limit Maximum Rate Daily Limit Maximum Rate
Requests 1,300,000 requests 7,400 requests/minute 43,000,000 requests 30,000 requests/minute
Outgoing Bandwidth (billable, includes HTTPS) 1 gigabyte 56 megabytes/minute 1 gigabyte free; 1,046 gigabytes maximum 740 megabytes/minute
Incoming Bandwidth (billable, includes HTTPS) 1 gigabyte 56 megabytes/minute 1 gigabyte free; 1,046 gigabytes maximum 740 megabytes/minute
CPU Time (billable) 6.5 CPU-hours 15 CPU-minutes/minute 6.5 CPU-hours free; 1,729 CPU-hours maximum 72 CPU-minutes/minute

Datastore

Resource Free Default Quota Billing Enabled Quota
Daily Limit Maximum Rate Daily Limit Maximum Rate
Datastore API Calls 10,000,000 calls 57,000 calls/minute 140,000,000 calls 129,000 calls/minute
Stored Data (billable) 1 gigabyte None 1 gigabytes free; no maximum None
Data Sent to API 12 gigabytes 68 megabytes/minute 72 gigabytes 153 megabytes/minute
Data Received from API 115 gigabytes 659 megabytes/minute 695 gigabytes 1,484 megabytes/minute
Datastore CPU Time 60 CPU-hours 20 CPU-minutes/minute 1,200 CPU-hours 50 CPU-minutes/minute

Mail

Resource Free Default Quota Billing Enabled Quota
Daily Limit Maximum Rate Daily Limit Maximum Rate
Mail API Calls 7,000 calls 32 calls/minute 1,700,000 calls 4,900 calls/minute
Recipients Emailed (billable) 2,000 recipients 8 recipients/minute 2,000 recipients free; 7,400,000 recipients maximum 5,100 recipients/minute
Admins Emailed 5,000 mails 24 mails/minute 3,000,000 mails 9,700 mails/minute
Message Body Data Sent 60 megabytes 340 kilobytes/minute 29 gigabytes 84 megabytes/minute
Attachments Sent 2,000 attachments 8 attachments/minute 2,900,000 attachments 8,100 attachments/minute
Attachment Data Sent 100 megabytes 560 kilobytes/minute 100 gigabytes 300 megabytes/minute

URL Fetch

Resource Free Default Quota Billing Enabled Quota
Daily Limit Maximum Rate Daily Limit Maximum Rate
UrlFetch API Calls 657,000 calls 3,000 calls/minute 46,000,000 calls 32,000 calls/minute
UrlFetch Data Sent 4 gigabytes 22 megabytes/minute 1,046 gigabytes 740 megabytes/minute
UrlFetch Data Received 4 gigabytes 22 megabytes/minute 1,046 gigabytes 740 megabytes/minute

Image Manipulation

Resource Free Default Quota Billing Enabled Quota
Daily Limit Maximum Rate Daily Limit Maximum Rate
Image Manipulation API Calls 864,000 calls 4,800 calls/minute 45,000,000 calls 31,000 calls/minute
Data Sent to API 1 gigabytes 5 megabytes/minute 560 gigabytes 400 megabytes/minute
Data Received from API 5 gigabytes 28 megabytes/minute 427 gigabytes 300 megabytes/minute
Transformations executed 2,500,000 transforms 14,000 transforms/minute 47,000,000 transforms 32,000 transforms/minute

Memcache

Resource Free Default Quota Billing Enabled Quota
Daily Limit Maximum Rate Daily Limit Maximum Rate
Memcache API Calls 8,600,000 48,000 calls/minute 96,000,000 108,000 calls/minute
Data Sent to API 10 gigabytes 56 megabytes/minute 60 gigabytes 128 megabytes/minute
Data Received from API 50 gigabytes 284 megabytes/minute 315 gigabytes 640 megabytes/minute

Full Quota listing viewable here.

Resources
Google App Engine : http://code.google.com/appengine/
Google Plugin for Eclipse : http://code.google.com/eclipse/
Eclipse Quick Start Guide : http://code.google.com/eclipse/docs/getting_started.html
Google App Engine FAQs : http://code.google.com/appengine/kb/
Google App Engine SDK Code : http://code.google.com/p/googleappengine/
Sample Apps Code : http://code.google.com/p/google-app-engine-samples/

Sample application and photos:
gae_gwt_sticky

gae_java1

gae_java2

gae_java3

gae_java4

gae_java6

gae_java7

mandelbrot

Google, Internet, Java, Software, Technology , , , ,