<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress.com" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	>

<channel>
	<title>appengine &amp;laquo; WordPress.com Tag Feed</title>
	<link>http://en.wordpress.com/tag/appengine/</link>
	<description>Feed of posts on WordPress.com tagged "appengine"</description>
	<pubDate>Thu, 10 Dec 2009 11:02:54 +0000</pubDate>

	<generator>http://en.wordpress.com/tags/</generator>
	<language>en</language>

<item>
<title><![CDATA[My head's in the "cloud"]]></title>
<link>http://jacobcynamon.wordpress.com/2009/12/09/my-heads-in-the-cloud/</link>
<pubDate>Thu, 10 Dec 2009 02:49:26 +0000</pubDate>
<dc:creator>Jacob Cynamon-Murphy</dc:creator>
<guid>http://jacobcynamon.wordpress.com/2009/12/09/my-heads-in-the-cloud/</guid>
<description><![CDATA[Cloud computing seems to be one of the big industry buzzwords.  But what&#8217;s all the buzz about?]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p><em>Cloud computing</em> seems to be one of the big industry buzzwords.  But what&#8217;s all the buzz about?</p>
<p>Well, for one thing, $50/application and a potential $15K in prize money, thanks to <a title="Elance" href="http://www.elance.com" target="_blank">Elance</a> and Microsoft&#8230; but more on that later.  In addition to crafty gimmicks in which yours truly hopes to take part, cloud computing seems to be catching on in organizations and among professionals seeking to reduce time to market, equipment costs and service outages.  Several major players are on board, including Microsoft (<a title="Windows Azure" href="http://www.microsoft.com/windowsazure/" target="_blank">Windows Azure</a>), Amazon.com (<a title="Amazon Web Services" href="http://aws.amazon.com/" target="_blank">Amazon Web Services</a>), Google (Google Apps, <a title="Google AppEngine" href="http://code.google.com/appengine/" target="_blank">AppEngine</a>) and Salesforce.com (<a title="Force.com" href="http://www.salesforce.com/platform/" target="_blank">Force.com</a>).  There are many other players and I&#8217;m not intentionally leaving any off the list &#8211; for the detail-oriented (and marketing managers), feel free to add a comment promoting your service of choice.  I don&#8217;t mind&#8230; really.</p>
<p>I&#8217;ve personally dabbled with Windows Azure and Amazon Web Services.  It&#8217;s worth discussing both, as they represent fairly different service models.  Amazon Web Services encompasses a number of offerings within the AWS brand (like <a title="Amazon Mechanical Turk" href="http://aws.amazon.com/mturk/" target="_blank">Mechanical Turk</a>, my personal favorite), but is most well-known for EC2, the <em>elastic compute cloud</em>.  To put it as simply as possible, imagine an unlimited number of servers that you had access to whenever you needed to scale up or down your applications and services.  Essentially, that&#8217;s what Amazon offers with EC2.  It&#8217;s akin to an infinite supply of ready-to-use servers in a remote data center &#8211; you can access the machines remotely, set up software and services and be up and running.  This is often referred to as &#8220;infrastructure as a service.&#8221;  On the other end of the spectrum, you have Windows Azure, often described as &#8220;platform as a service.&#8221;  To be frank, I hear that most often from people who are not fond of Microsoft, so I&#8217;m not sure how far removed from Amazon&#8217;s service Azure truly is.  Many of the services available to users are mirrored; if Amazon has a data storage service, Microsoft&#8217;s is comparable, both in terms of functionality and price.  However, I have heard that the encapsulation of some functionality &#8211; you don&#8217;t create &#8220;from scratch&#8221; images in Windows Azure &#8211; makes it easier to get up and running, while limiting your overall flexibility.</p>
<p>For the past few months, I have been attending the recently organized <a title="AWS Chicago Meet-up" href="http://www.amazonchicago.com" target="_blank">Amazon Web Services Chicago Meet-up</a> to learn more about AWS and cloud computing.  For those of you in the area, I encourage dropping in for the January meeting.  Everyone is very friendly, the breakfast hits the spot and lots of knowledge is served up.  On the other hand, if you are into Windows Azure, you might check out this promotion that Microsoft and Elance are offering (which I eluded to above&#8230; you were patient enough to read everything first, right?).  Yesterday night, I got an email from Elance inviting me to participate in a special project to create a Windows Azure application.  Every successful proposal would receive $50 on completion of a live project &#8211; it&#8217;s brilliant and everyone wins.  Microsoft has several new developers using and promoting Azure, Elance has a bunch of new professionals seeking projects (not to mention the publicity from this event) and I get $50 &#8211; sweet!</p>
<p>Stay tuned &#8211; once I get approved, I will share details of my Windows Azure application, which everyone will be welcome to beta test.</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[AppEngine SDK 1.2.8 now supports JAXB...and a lot more]]></title>
<link>http://turbomanage.wordpress.com/2009/12/05/appengine-sdk-1-2-8-now-supports-jaxb-and-a-lot-more/</link>
<pubDate>Sat, 05 Dec 2009 16:34:28 +0000</pubDate>
<dc:creator>David Chandler</dc:creator>
<guid>http://turbomanage.wordpress.com/2009/12/05/appengine-sdk-1-2-8-now-supports-jaxb-and-a-lot-more/</guid>
<description><![CDATA[In case you missed it, the latest AppEngine for Java release adds support for JAXB (the single most ]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>In case you missed it, the latest AppEngine for Java release adds support for JAXB (the single most requested feature according to <a href="http://groups.google.com/group/google-appengine-java/browse_thread/thread/18e49b1559752fae">Google&#8217;s announcement</a>!). In addition, AppEngine 1.2.8 significantly beefs up ORM support, now supporting inheritance, IN queries, and <a href="http://groups.google.com/group/google-appengine-java/browse_thread/thread/fe334c9e461026fa/5f96cc5f64421973?lnk=gst&#38;q=appengine+1.2.8+IN+queries#5f96cc5f64421973">much more</a>.</p>
<p>I had already found workarounds to these limitations for my current project, but the latest release further demonstrates Google&#8217;s commitment to a superior platform and eliminates many more excuses for not <a href="http://code.google.com/appengine/downloads.html">giving it a try</a>.</p>
<div id="_mcePaste" style="overflow:hidden;position:absolute;left:-10000px;top:0;width:1px;height:1px;">http://groups.google.com/group/google-appengine-java/browse_thread/thread/18e49b1559752fae</div>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Persisting enums with AppEngine Datastore]]></title>
<link>http://turbomanage.wordpress.com/2009/12/04/persisting-enums-with-appengine-datastore/</link>
<pubDate>Fri, 04 Dec 2009 16:32:37 +0000</pubDate>
<dc:creator>David Chandler</dc:creator>
<guid>http://turbomanage.wordpress.com/2009/12/04/persisting-enums-with-appengine-datastore/</guid>
<description><![CDATA[Much of Java&#8217;s appeal (not to mention JSF, ORM, and GWT with a little help) is the ability to ]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>Much of Java&#8217;s appeal (not to mention JSF, ORM, and GWT with a little help) is the ability to code in terms of rich domain objects such as the enumerated type. My next several blog posts will demonstrate the use of enums throughout a GAE+GWT application, beginning with persistence.</p>
<p>According to the <a href="http://code.google.com/appengine/docs/java/datastore/dataclasses.html#Core_Value_Types">AppEngine docs</a>,  Java enums are not one of the core value types, which might lead one to believe that they&#8217;re not supported. However, closer examination reveals that enums are indeed supported by DataNucleus JDO and JPA, which take care of mapping enums to Datastore core value types String (JDO + JPA) or Integer (JPA).</p>
<h3>JDO</h3>
<p><a href="http://www.datanucleus.org/products/accessplatform/jdo/types.html">JDO mapping</a> requires no special annotations and persists the enum as a String by name. One of the DataNucleus doc <a href="http://www.datanucleus.org/products/accessplatform/rdbms/jdoql2_methods.html">pages</a> (search for &#8220;ordinal&#8221;) suggests it may be possible to persist by ordinal instead; however, I haven&#8217;t found this documented for JDO. Persistence by name is likely better, anyway, as it allows you the flexibility to add new enum values later in any ordinal position.</p>
<pre class="brush: java;">
	public enum ScheduleMethod {RANDOM, FILL, CUSTOM};
	@Persistent
	private ScheduleMethod scheduleMethod = ScheduleMethod.RANDOM;
</pre>
</pre>
<p>Note that Google does have a <a href="http://www.google.com/codesearch/p?hl=en&#38;sa=N&#38;cd=2&#38;ct=rc#79kbA0UmWLw/trunk/tests/org/datanucleus/test/HasEnumJDO.java">unit test</a> for enum persistence in JDO.</p>
<h3>JPA</h3>
<p><a href="http://www.datanucleus.org/products/accessplatform/jpa/annotations.html#Enumerated">JPA mapping</a> requires the use of the @Enumerated annotation, which additionally lets you specify whether to map by name (String) or ordinal (Integer).</p>
<h3>Roll-your-own</h3>
<p>Of course, you can always roll your own mapping strategy if for some reason you need special behavior. With AppEngine Datastore, you can persist any object class by making it <a href="http://code.google.com/appengine/docs/java/datastore/dataclasses.html#Serializable_Objects">Serializable</a> or <a href="http://code.google.com/appengine/docs/java/datastore/dataclasses.html#Embedded_Classes">Embedded</a>, although the former has the disadvantage that you can't use object properties in queries. You can also create a custom enum class and persist the enum by any core value type as in the example below.</p>
<pre class="brush: java;">
	public static enum Frequency
	{
		DAILY(1),
		WEEKLY(7),
		MONTHLY(30),
		QUARTERLY(90),
		YEARLY(365);

		private int periodDays;

		Frequency(int periodDays)
		{
			this.periodDays = periodDays;
		}

		public int getPeriodDays()
		{
			return periodDays;
		}

		public static Frequency getValue(int i)
		{
			for (Frequency f : Frequency.values())
			{
				if (f.getPeriodDays() == i)
					return f;
			}
			throw new IllegalArgumentException(&#34;Invalid frequency period days: &#34; + i);
		}
	}

	@Persistent
	private Integer periodDays = Frequency.WEEKLY.getPeriodDays();

	/**
	 * Convenience method to get frequency as an enum
	 * @return Frequency
	 */
	public Frequency getFrequency()
	{
		return Frequency.getValue(this.getPeriodDays());
	}

	public void setFrequency(Frequency f)
	{
		this.setPeriodDays(f.getPeriodDays());
	}
</pre>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[AppEngine Cold Starts]]></title>
<link>http://turbomanage.wordpress.com/2009/12/02/appengine-cold-starts/</link>
<pubDate>Thu, 03 Dec 2009 04:11:38 +0000</pubDate>
<dc:creator>David Chandler</dc:creator>
<guid>http://turbomanage.wordpress.com/2009/12/02/appengine-cold-starts/</guid>
<description><![CDATA[It appears that some of the startup delay I had previously blamed on GWT may actually have been due ]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>It appears that some of the startup delay I had previously blamed on GWT may actually have been due to the phenomenon that is popping up on the AppEngine forums lately. In order to conserve resources, AppEngine doesn&#8217;t keep your JVM &#8220;hot&#8221; unless it&#8217;s getting a lot of traffic, and it takes a few seconds to swap it back in. The resulting cold start delay, it would appear, is part of the price of &#8220;free.&#8221;</p>
<p>See <a href="http://groups.google.com/group/google-appengine/browse_thread/thread/22692895421825cb/">this thread</a> for more info.</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[AppEngine needs an AppStore]]></title>
<link>http://turbomanage.wordpress.com/2009/11/30/appengine-needs-an-appstore/</link>
<pubDate>Mon, 30 Nov 2009 16:45:16 +0000</pubDate>
<dc:creator>David Chandler</dc:creator>
<guid>http://turbomanage.wordpress.com/2009/11/30/appengine-needs-an-appstore/</guid>
<description><![CDATA[I continue to be blown away by the power and EASE of Google AppEngine: one-button deploy from Eclips]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>I continue to be blown away by the power and EASE of Google AppEngine: one-button deploy from Eclipse, all the admin tools built right in (log viewer, data viewer, task queues, cron jobs, etc.), a graphical dashboard for monitoring performance and usage quotas, and even a <a href="http://code.google.com/status/appengine">system status page</a> that lets me know how the Google infrastructure is performing.</p>
<p>I&#8217;m convinced this is a killer platform on which to deploy applications, especially for small businesses already moving into the cloud with Google Apps. And wouldn&#8217;t you know, you can already link AppEngine and Google Apps in two important ways:</p>
<ol>
<li>Your AppEngine apps can show up on your Google Apps home page. This happened for me automatically when linking my AppEngine app to a custom domain name using my Google Apps account.</li>
<li>Your AppEngine apps can authenticate Google Apps users.</li>
</ol>
<p>The only problem is, many of the small businesses likely to use Google Apps are doing so precisely because they don&#8217;t have an IT staff to maintain servers, email, etc. So they&#8217;re certainly not going to have software developers on staff to write custom AppEngine applications for their businesses. But there are plenty of folks like myself willing to write such apps, and AppEngine is already well suited for delivery of pre-packaged applications. It&#8217;s already got the control panel and admin tools built in, doesn&#8217;t require any database set up, and it&#8217;s easy to upload code.</p>
<p>All that&#8217;s needed is a marketplace for these applications. That&#8217;s where an AppStore comes in. Imagine if you could just sign up your business for a Google Apps account and select from thousands of pre-built applications for managing your business with the same ease as downloading an app for your iPhone. As a developer, I&#8217;d love to market such applications, and what better place to reach them than their Google Apps control panel? I&#8217;d be ecstatic to give Google a cut of the action! Besides their cut of the application purchase, Google gets more Google Apps sign-ups and sells more AppEngine resources. Google is already a market maker for small business applications through the core search engine and accompanying ad revenue, but a Google AppStore would be far more efficient for both buyer and seller. An AppStore would make many niche applications economically viable by eliminating fixed costs up front and enabling super-efficient marketing, thus realizing the much-written-about &#8220;long tail&#8221; of software development.</p>
<p>Google, are you listening? You&#8217;ve got something here! AppEngine is fantastic, and an AppStore would take it through the stratosphere!</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[AppEngine task queue problems resolved for now]]></title>
<link>http://turbomanage.wordpress.com/2009/11/27/appengine-task-queue-problems-resolved-for-now/</link>
<pubDate>Sat, 28 Nov 2009 01:06:00 +0000</pubDate>
<dc:creator>David Chandler</dc:creator>
<guid>http://turbomanage.wordpress.com/2009/11/27/appengine-task-queue-problems-resolved-for-now/</guid>
<description><![CDATA[I&#8217;ve been able to get Deferred.defer() working by Base64 encoding the serialized object stream]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>I&#8217;ve been able to get <a href="http://turbomanage.wordpress.com/2009/11/21/weird-serialization-error-in-appengine/">Deferred.defer()</a> working by Base64 encoding the serialized object stream for the task before queuing it. I think something in the task queue processing chain doesn&#8217;t handle raw binary data. I&#8217;ll post a link to the code once smarter folks than I have had a chance to discuss this and review it.</p>
<p>You can follow <a href="http://groups.google.com/group/google-appengine-java/browse_thread/thread/6f736624cc820d5b">the discussion</a> on the AppEngine forum.</p>
<p>&#160;</p>
<div id="_mcePaste" style="overflow:hidden;position:absolute;left:-10000px;top:0;width:1px;height:1px;">http://turbomanage.wordpress.com/2009/11/21/weird-serialization-error-in-appengine/</div>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Problems with task queues]]></title>
<link>http://turbomanage.wordpress.com/2009/11/25/problems-wirh-taak-queues/</link>
<pubDate>Thu, 26 Nov 2009 03:50:13 +0000</pubDate>
<dc:creator>David Chandler</dc:creator>
<guid>http://turbomanage.wordpress.com/2009/11/25/problems-wirh-taak-queues/</guid>
<description><![CDATA[As I hoped (sort of), the weird serialization error I wrote about a couple days ago came back, and I]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>As I hoped (sort of), the weird serialization error I wrote about a couple days ago came back, and I don&#8217;t think it&#8217;s related to a field name. Might do some more testing after turkey tomorrow&#8230;</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[REST based message queue]]></title>
<link>http://zenmachine.wordpress.com/2009/11/22/rest-based-message-queue/</link>
<pubDate>Sun, 22 Nov 2009 14:10:38 +0000</pubDate>
<dc:creator>gm</dc:creator>
<guid>http://zenmachine.wordpress.com/2009/11/22/rest-based-message-queue/</guid>
<description><![CDATA[I&#8217;ve been playing with lots of message queues lately, and with each of one, a protocol is favo]]></description>
<content:encoded><![CDATA[I&#8217;ve been playing with lots of message queues lately, and with each of one, a protocol is favo]]></content:encoded>
</item>
<item>
<title><![CDATA[Weird serialization error in AppEngine]]></title>
<link>http://turbomanage.wordpress.com/2009/11/21/weird-serialization-error-in-appengine/</link>
<pubDate>Sat, 21 Nov 2009 22:51:03 +0000</pubDate>
<dc:creator>David Chandler</dc:creator>
<guid>http://turbomanage.wordpress.com/2009/11/21/weird-serialization-error-in-appengine/</guid>
<description><![CDATA[My previous post discussed a very cool way to do background processing in AppEngine using Deferred.d]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>My <a href="http://turbomanage.wordpress.com/2009/11/20/deferred-defer-is-a-thing-of-beauty/">previous post</a> discussed a very cool way to do background processing in AppEngine using Deferred.defer. Unfortunately, the AdminEmailTask example I posted results in a cryptic error when the task is dequeued and the Deferred servlet attemps to deserialize it:</p>
<pre>com.newatlanta.appengine.taskqueue.Deferred deserialize: invalid type code: 00</pre>
<p>After nearly a day&#8217;s worth of experimentation, I am really weirded out by what I&#8217;ve found: the problem seems to be the name of the private field &#8220;msgSubject&#8221; in AdminEmailTask. I tried shorter names, longer names, and other names without any problem. I changed the class name, moved it into a different package, and generally pulled my hair out until I simply tried changing the name of the field. At first, I thought it was <a href="http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6434149">this JDK bug</a>, but I wasn&#8217;t using an array type. Nevertheless, I subclassed ObjectInputStream and overrode the resolveClass method as per the bug&#8217;s workaround, only to find out that AppEngine&#8217;s implementation of ObjectInputStream doesn&#8217;t call the overridden resolveClass and throws a security exception on enableResolveObject(true).</p>
<p>I can only guess that the field name &#8220;msgSubject&#8221; results in a binary sequence that is somehow special to AppEngine&#8217;s implementation of ObjectInputStream, or perhaps it&#8217;s a bug in the JDK.</p>
<p>At any rate, if you get the java.io.StreamCorruptedException with invalid type code: 00, try renaming your class fields! I really, really hope I&#8217;m mistaken about this.</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[[CTA] Catch Them All o cómo obtener la dirección ip de cualquier equipo en Internet]]></title>
<link>http://andalinux.wordpress.com/2009/11/21/cta-catch-them-all-o-como-obtener-la-direccion-ip-de-cualquier-equipo-en-internet/</link>
<pubDate>Sat, 21 Nov 2009 15:44:58 +0000</pubDate>
<dc:creator>jasvazquez</dc:creator>
<guid>http://andalinux.wordpress.com/2009/11/21/cta-catch-them-all-o-como-obtener-la-direccion-ip-de-cualquier-equipo-en-internet/</guid>
<description><![CDATA[Hasta ahora os había contado cómo obtener la dirección IP de cualquier correo electrónico que os env]]></description>
<content:encoded><![CDATA[Hasta ahora os había contado cómo obtener la dirección IP de cualquier correo electrónico que os env]]></content:encoded>
</item>
<item>
<title><![CDATA[Deferred.defer() is a thing of beauty]]></title>
<link>http://turbomanage.wordpress.com/2009/11/20/deferred-defer-is-a-thing-of-beauty/</link>
<pubDate>Fri, 20 Nov 2009 22:23:41 +0000</pubDate>
<dc:creator>David Chandler</dc:creator>
<guid>http://turbomanage.wordpress.com/2009/11/20/deferred-defer-is-a-thing-of-beauty/</guid>
<description><![CDATA[How do you do background processing in an AppEngine environment? The AppEngine experimental Task Que]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>How do you do background processing in an AppEngine environment? The AppEngine experimental <a href="http://code.google.com/appengine/docs/java/taskqueue/overview.html">Task Queues API</a> provides a way using Web hooks, but it&#8217;s a bit of a pain because you have to package each background task as a servlet.</p>
<p>Comes <a href="http://blog.newatlanta.com/">Vince Bonfanti</a> of <a href="http://www.newatlanta.com/">New Atlanta</a> to the rescue with a <a href="http://groups.google.com/group/google-appengine-java/browse_thread/thread/6f736624cc820d5b/49210c1755fbbb4f?pli=1">Java implementation</a> of Nick Johnson&#8217;s original Deferred.defer implementation in Python. Now queuing a task for background processing is as simple as creating a task and calling Deferred.defer(task). Here&#8217;s an example task to send an email to the application administrator:</p>
<pre class="brush: java;">
package com.roa.server.service.task;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.Properties;

import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import javax.servlet.ServletException;

import com.newatlanta.appengine.taskqueue.Deferred;

	public class AdminEmailTask implements Deferred.Deferrable
	{
		private String msgBody;
		private String msgSubject;

		public AdminEmailTask(String msgSubject, String msgBody)
		{
			this.msgSubject = msgSubject;
			this.msgBody = msgBody;
		}

		@Override
		public void doTask() throws ServletException, IOException
		{
			Properties props = new Properties();
			Session session = Session.getDefaultInstance(props, null);

			try
			{
				Message msg = new MimeMessage(session);
				msg.setFrom(new InternetAddress(&#34;admin@example.com&#34;, &#34;admin&#34;));
				msg.addRecipient(Message.RecipientType.TO, new InternetAddress(
					&#34;admin@example.com&#34;, &#34;admin&#34;));
				msg.setSubject(msgSubject);
				msg.setText(msgBody);
				Transport.send(msg);
			}
			catch (AddressException e)
			{
				throw new ServletException(e);
			}
			catch (MessagingException e)
			{
				throw new ServletException(e);
			}
			catch (UnsupportedEncodingException e)
			{
				throw new ServletException(e);
			}

		}
	}
</pre>
<p>And here&#8217;s an example of queuing the task inside a gwt-dispatch ActionHandler:</p>
<pre class="brush: java;">
package com.roa.server.handler.admin;

import java.io.IOException;

import net.customware.gwt.dispatch.server.ActionHandler;
import net.customware.gwt.dispatch.server.ExecutionContext;
import net.customware.gwt.dispatch.shared.ActionException;

import com.google.inject.Inject;
import com.newatlanta.appengine.taskqueue.Deferred;
import com.roa.admin.shared.rpc.AdminEmailAction;
import com.roa.admin.shared.rpc.AdminEmailResult;
import com.roa.server.service.task.AdminEmailTask;
import com.turbomanage.gwt.server.PMF;

public class AdminEmailHandler implements ActionHandler&#60;AdminEmailAction, AdminEmailResult&#62;
{

	@Inject
	private PMF pmf;

	@Override
	public AdminEmailResult execute(AdminEmailAction action, ExecutionContext ctx)
		throws ActionException
	{
		AdminEmailTask adminEmailTask = new AdminEmailTask(action.getEmailSubject(), action
			.getEmailBody());
		try
		{
			Deferred.defer(adminEmailTask);
		}
		catch (IOException e)
		{
			throw new ActionException(e);
		}
		return new AdminEmailResult();
	}

	@Override
	public Class&#60;AdminEmailAction&#62; getActionType()
	{
		return AdminEmailAction.class;
	}

	@Override
	public void rollback(AdminEmailAction arg0, AdminEmailResult arg1, ExecutionContext arg2)
		throws ActionException
	{
		// TODO Auto-generated method stub

	}

}
</pre>
<p>You might ask why you&#8217;d use a deferred task like this to send an email? In this example, there really is no reason to, but imagine you were sending 1000 emails at once. In order to guarantee you won&#8217;t exceed AppEngine&#8217;s free quota of 8 recipients / minute, you could set up your deferred queue in queue.xml with that rate and then call Deferred.defer() for each recipient rather than calling the mail API directly 1000 times in a loop. That way, the AppEngine task queuing facility throttles your mail API calls.</p>
<p>Here&#8217;s a link to the <a href="http://groups.google.com/group/google-appengine-java/browse_thread/thread/6f736624cc820d5b/49210c1755fbbb4f?pli=1">whole discussion thread</a> and <a href="http://code.google.com/p/gaevfs/source/browse/trunk/src/com/newatlanta/appengine/taskqueue/Deferred.java">Vince&#8217;s code</a>.</p>
<p>If you&#8217;d like to see this added to the <a href="http://code.google.com/appengine/docs/java/taskqueue/overview.html">Task Queues API</a>, please star <a href="http://code.google.com/p/googleappengine/issues/detail?id=2381">this issue</a>.</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[The ISV is coming back (thanks to AppEngine)]]></title>
<link>http://turbomanage.wordpress.com/2009/11/18/the-isv-is-back-thanks-to-appengine/</link>
<pubDate>Thu, 19 Nov 2009 03:16:51 +0000</pubDate>
<dc:creator>David Chandler</dc:creator>
<guid>http://turbomanage.wordpress.com/2009/11/18/the-isv-is-back-thanks-to-appengine/</guid>
<description><![CDATA[Someone at last night&#8217;s AJUG meeting articulately expressed what I&#8217;ve been thinking for ]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>Someone at last night&#8217;s <a href="http://www.ajug.org/">AJUG</a> meeting articulately expressed what I&#8217;ve been thinking for the last several weeks as I&#8217;ve been learning Google AppEngine: this platform gives the independent software vendor (aka &#8220;the computer guy at your church&#8221;) a new lease on life. Why will AppEngine bring back affordable custom programming for small business?</p>
<ol>
<li>There are no servers to configure. Sys admin and tech support are the bane of every developer&#8217;s existence, which makes AppEngine a developer&#8217;s dream. Code, test, and deploy. No sys admin needed.</li>
<li>There&#8217;s nothing to buy up front: no servers, software, firewalls, backup solution&#8211;not even hosting fees until you exceed AppEngine&#8217;s generous usage limits.</li>
<li>You can log on to your AppEngine application with your Google account (Gmail) or Google Apps login. For many businesses, Google Apps is a compelling alternative to running your own file and document servers and paying for MS Office on every desk. If everyone in your business already has a Google Apps account, it&#8217;s a no-brainer to use AppEngine for your custom apps, too.</li>
</ol>
<p>As more folks learn how to create AppEngine apps in Python or Java, I expect there to be low-cost applications you can purchase for your business as well as pre-packaged applications that developers can buy and customize for your needs. The fabled long tail of software niche marketing is set to EXPLODE.</p>
<p>Shameless plug: if you&#8217;ve always dreamed of having software that could do (whatever) for your business, but thought it was probably too expensive, drop <a href="/dmc">me</a> a note. The game has changed.</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[GAE: Storing serializable objects in datastore]]></title>
<link>http://thesweeheng.wordpress.com/2009/11/16/gae-storing-serializable-objects-in-datastore/</link>
<pubDate>Mon, 16 Nov 2009 14:00:52 +0000</pubDate>
<dc:creator>thesweeheng</dc:creator>
<guid>http://thesweeheng.wordpress.com/2009/11/16/gae-storing-serializable-objects-in-datastore/</guid>
<description><![CDATA[Google AppEngine&#8217;s datastore supports a variety of simple Types and Property Classes by defaul]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>Google AppEngine&#8217;s datastore supports a variety of simple <a href="http://code.google.com/appengine/docs/python/datastore/typesandpropertyclasses.html" target="_blank">Types and Property Classes</a> by default. However if we want to store something like a dictionary, we typically have to serialize it and store it as a Blob. On fetching we will de-serialize it. While this approach works, it is repetitive and somewhat error-prone.</p>
<p>Wouldn&#8217;t it be great if there is a SerializableProperty class that can handle this automatically for us? It doesn&#8217;t exist but according to this <a href="http://code.google.com/appengine/articles/extending_models.html">article</a>, it is easy to create our own customized Property classes. So here is a simple implementation of SerializableProperty that worked for me:</p>
<blockquote>
<pre>import cPickle as pickle
import zlib
from google.appengine.ext import db

class SerializableProperty(db.Property):
  """
  A SerializableProperty will be pickled and compressed before it is
  saved as a Blob in the datastore. On fetch, it would be decompressed
  and unpickled. It allows us to save serializable objects (e.g. dicts)
  in the datastore.

  The sequence of transformations applied can be customized by calling
  the set_transforms() method.
  """

  data_type = db.Blob
  _tfm = [lambda x: pickle.dumps(x,2), zlib.compress]
  _itfm = [zlib.decompress, pickle.loads]

  def set_transforms(self, tfm, itfm):
    self._tfm = tfm
    self._itfm = itfm

  def get_value_for_datastore(self, model_instance):
    value = super(SerializableProperty,
        self).get_value_for_datastore(model_instance)
    if value is not None:
      value = self.data_type(reduce(lambda x,f: f(x), self._tfm, value))
    return value

  def make_value_from_datastore(self, value):
    if value is not None:
      value = reduce(lambda x,f: f(x), self._itfm, value)
    return value
</pre>
</blockquote>
<p>Usage is as simple as this:</p>
<blockquote>
<pre>class MyModel(db.Model):
  data = SerializableProperty()

entity = MyModel(data = {"key": "value"}, key_name="somekey")
entity.put()
entity = MyModel.get_by_key_name("somekey")
print entity.data
</pre>
</blockquote>
<p>Hope that helps!</p>
<p><strong>Update</strong> (20091126): I&#8217;ve changed db.Blob to self.data_type as suggested by Peritus in <a href="http://thesweeheng.wordpress.com/2009/11/16/gae-storing-serializable-objects-in-datastore/#comment-68" target="_blank">Comment</a>. The same comment also suggested a JSONSerializableProperty subclass:</p>
<blockquote>
<pre>import simplejson as json
class JSONSerializableProperty(SerializableProperty):
  data_type = db.Text
  _tfm = [json.dumps]
  _itfm = [json.loads]</pre>
</blockquote>
<p>Thanks Peritus!</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Correction: AppEngine Datastore and owned relationships]]></title>
<link>http://turbomanage.wordpress.com/2009/11/12/correction-appengine-datastore-and-owned-relationships/</link>
<pubDate>Thu, 12 Nov 2009 20:16:26 +0000</pubDate>
<dc:creator>David Chandler</dc:creator>
<guid>http://turbomanage.wordpress.com/2009/11/12/correction-appengine-datastore-and-owned-relationships/</guid>
<description><![CDATA[Last week, I mistakenly wrote that AppEngine Datastore would not retrieve Key fields (representing a]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>Last week, I mistakenly wrote that AppEngine Datastore would not retrieve Key fields (representing an unowned relationship) unless you annotated with defaultFetchGroup=&#8221;true&#8221;, but that it would automatically retrieve properties represented by an owned relationship. This was not correct, as AppEngine Datastore never allows joins. I&#8217;ve updated <a href="http://turbomanage.wordpress.com/2009/11/06/key-fields-are-not-retrieved-by-default/">the original post</a> accordingly.</p>
<p>&#160;</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[AppEngine JDO tip regarding detachCopy()]]></title>
<link>http://turbomanage.wordpress.com/2009/11/11/appengine-jdo-tip-regarding-detachcopy/</link>
<pubDate>Thu, 12 Nov 2009 03:59:37 +0000</pubDate>
<dc:creator>David Chandler</dc:creator>
<guid>http://turbomanage.wordpress.com/2009/11/11/appengine-jdo-tip-regarding-detachcopy/</guid>
<description><![CDATA[In order to avoid JDO and/or serialization exceptions, I always call some form of persistenceManager]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>In order to avoid JDO and/or serialization exceptions, I always call some form of persistenceManager.detachCopy() before returning objects from the Datastore back to GWT. I discovered today that you must set any non-persistent properties of the object <em>after</em> calling detachCopy(). My initial inclination is that detachCopy() does not copy properties annotated with @NotPersistent, but I have to do a little more testing&#8230;</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Let's Play Tic-Tac-Toe On Google AppEngine]]></title>
<link>http://robertfield.wordpress.com/2009/11/09/lets-play-tic-tac-toe-on-google-appengine/</link>
<pubDate>Mon, 09 Nov 2009 16:08:44 +0000</pubDate>
<dc:creator>Robert Field</dc:creator>
<guid>http://robertfield.wordpress.com/2009/11/09/lets-play-tic-tac-toe-on-google-appengine/</guid>
<description><![CDATA[Play Tic-Tac-Toe On Google AppEngine Here&#8217;s an application I put together in Python. It is an ]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p><span style="color:black;"></p>
<h3>Play Tic-Tac-Toe On Google AppEngine</h3>
<p>Here&#8217;s an application I put together in Python.  It is an unbeatable Tic-Tac-Toe opponent.  In its current state, the human player always goes first.  Just click on a square to start playing.<br />
<br />
<a href="http://rcf-first-app.appspot.com/">Click here to play</a><br />
<br />
The computer&#8217;s play is based on an exhaustive analysis of positions.  This is feasible since the game tree is small.<br />
<br />
If you win, let me know.  That&#8217;s a bug.<br />
</span></p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Key fields are not retrieved by default]]></title>
<link>http://turbomanage.wordpress.com/2009/11/06/key-fields-are-not-retrieved-by-default/</link>
<pubDate>Fri, 06 Nov 2009 15:44:44 +0000</pubDate>
<dc:creator>David Chandler</dc:creator>
<guid>http://turbomanage.wordpress.com/2009/11/06/key-fields-are-not-retrieved-by-default/</guid>
<description><![CDATA[I&#8217;ve noticed that AppEngine does not populate Key fields by default when querying. I&#8217;m s]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>I&#8217;ve noticed that AppEngine does not populate Key fields by default when querying. I&#8217;m sure it&#8217;s documented, but I can&#8217;t remember where. At any rate, you can annotate with defaultFetchGroup to resolve this. Same goes for properties of type Text and Blob.</p>
<pre class="brush: java;">
...
import com.google.appengine.api.datastore.Key;

@PersistenceCapable(identityType = IdentityType.APPLICATION)
public class PrayerItem implements Serializable
{
	@PrimaryKey
	@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
	private Long id;
	@Persistent(defaultFetchGroup=&#34;true&#34;)
	private Key list;
	...

}
</pre>
<p>In the case of owned relationships, where a property is represented by its actual domain class rather than a Key, it is also necessary to use defaultFetchGroup=&#8221;true&#8221;. Even though owned properties are in the same entity group and are therefore eligible for inclusion in a transaction, the AppEngine Datastore doesn&#8217;t allow joins, so owned relationships are not returned in the initial query. When you set defaultFetchGroup=&#8221;true&#8221; on an owned property, you will get this warning:</p>
<blockquote><p>WARNING: Meta-data warning for com&#8230;your_owned_property_name: The datastore does not support joins and therefore cannot honor requests to place child objects in the default fetch group.  The field will be fetched lazily on first access.  You can modify this warning by setting the datanucleus.appengine.ignorableMetaDataBehavior property in your config.  A value of NONE will silence the warning.  A value of ERROR will turn the warning into an exception.</p></blockquote>
<p>Lazy fetching does work as described in the message.</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[AppEngine JDO example #1: retrieve an object by ID]]></title>
<link>http://turbomanage.wordpress.com/2009/10/30/appengine-jdo-example-1-retrieve-an-object-by-id/</link>
<pubDate>Sat, 31 Oct 2009 03:03:12 +0000</pubDate>
<dc:creator>David Chandler</dc:creator>
<guid>http://turbomanage.wordpress.com/2009/10/30/appengine-jdo-example-1-retrieve-an-object-by-id/</guid>
<description><![CDATA[This is the first of a series of posts that will demonstrate a variety of JDO mappings and queries w]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>This is the first of a series of posts that will demonstrate a variety of JDO mappings and queries with AppEngine.</p>
<p>For starters, let&#8217;s retrieve an object from the Datastore given its ID. Here&#8217;s the User object in our domain model:</p>
<pre class="brush: java;">
package com.roa.client.domain;

import java.io.Serializable;

import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

@PersistenceCapable(identityType = IdentityType.APPLICATION)
public class User implements Serializable
{
	private static final long serialVersionUID = -1126191336687818754L;

	@PrimaryKey
	@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
	private Long id;
	@Persistent
	private String firstName;
	...
}
</pre>
<p>Now we want to retrieve a User object given the ID property obtained from getId(). Easy enough, you think, as the JDO PersistenceManager provides a method for this:</p>
<pre class="brush: java;">
// Doesn't quite work
User attachedUser = (User) getPM().getObjectById(userId);
</pre>
<p>But there&#8217;s a catch. Confusingly, the ID needed by getObjectById is a JDO ID, not the object property named &#8220;id&#8221; that we&#8217;ve annotated as an IDENTITY. You can get the JDO ID one of two ways. Whenever the object is attached, such as just after you&#8217;ve called makePersistent() on it, you can call persistenceManager.getObjectId(obj) and keep it in a safe place for later use. Alternatively, you can use a JDO helper method at any time to get the JDO ID from the object ID:</p>
<pre class="brush: java;">
		 // Must obtain the JDO ID first
		 Object idInstance = getPM().newObjectIdInstance(User.class, user.getId());
		 User attachedUser = (User) getPM().getObjectById(idInstance);
</pre>
<p>Fortunately, if you know the object&#8217;s class, there&#8217;s a 2-arg getObjectById that does take the object&#8217;s primary key property:</p>
<pre class="brush: java;">
User attachedUser = getPM().getObjectById(User.class, u.getId());
</pre>
<p>Of course, you can always just run a normal query on the object&#8217;s ID property, but it&#8217;s a bit ugly because the simplest query syntax always returns a Collection and we assume here that there will be only one matching object.</p>
<pre class="brush: java;">
		Query q = getPM().newQuery(User.class, &#34;id == :userId&#34;);
		List&#60;User&#62; users = (List&#60;User&#62;) q.execute(u.getId());
		User attachedUser = users.get(0);
</pre>
<p>Better to let the query language know that we expect a unique object:</p>
<pre class="brush: java;">
		Query q = getPM().newQuery(User.class, &#34;id == :userId&#34;);
		q.setUnique(true);
		User attachedUser = (User) q.execute(u.getId());
</pre>
<p>Finallly, there&#8217;s the low-level Datastore API:</p>
<pre class="brush: java;">
		Key key = KeyFactory.createKey(User.class.getSimpleName(), u.getId());
		Entity entity = DatastoreServiceFactory.getDatastoreService().get(key);
</pre>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Notes from CloudCamp]]></title>
<link>http://turbomanage.wordpress.com/2009/10/29/notes-from-cloudcamp/</link>
<pubDate>Thu, 29 Oct 2009 23:33:16 +0000</pubDate>
<dc:creator>David Chandler</dc:creator>
<guid>http://turbomanage.wordpress.com/2009/10/29/notes-from-cloudcamp/</guid>
<description><![CDATA[There were about 100 folks at CloudCamp Atlanta last night. Participatns were mostly interested in A]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>There were about 100 folks at CloudCamp Atlanta last night. Participatns were mostly interested in Amazon EC2 or the upcoming Windows Azure platform (Microsoft was the primary sponsor). A handful of folks turned out for my &#8220;show me the code&#8221; presentation on AppEngine and GWT+MVP.</p>
<p>My main takeaway is that I&#8217;m really, really glad to be a <a href="/gae">Google AppEngine</a> user. Most of the sessions and discussions centered around how to grow/shrink your Amazon server pool automatically and how to scale MySQL. These are things I don&#8217;t have to worry about at all as an AppEngine user. AppEngine is perfect for my application: launching a one-man startup that could go viral (not to mention it&#8217;s free to get started!) I&#8217;m just plain tired of sysadmin, and I&#8217;m willing to trade the  freedom to run any configuration of my choice for the scalability that comes with AppEngine&#8217;s constraints.</p>
<p>There was some discussion regarding the cloud  and SLAs (or lack thereof). Someone said they needed five nines, not three. I don&#8217;t know where they got either number, but .999 reliability is definitely good enough for me. I have a consumer-facing app that doesn&#8217;t involve money, and I&#8217;ll be ecstatic if I have only 8 hrs 46 minutes downtime in the coming year. It&#8217;s clear that cloud offerings (especially AppEngine) appeal more to lone developers and  small startups than to enterprises, although Amazon seems to have made great inroads in this area. It&#8217;s always going to be easier to start in the cloud than to move an existing data center. What excites me most about AppEngine and the like is that ONE developer can realistically create and deploy a scalable application. This has the potential to unleash a whole new wave of entrepreneurial energy on the Internet, and will make it possible for smaller companies that could never afford a data center to nevertheless get custom software for their needs. Which means we software engineers should get to do more coding and less sysadmin. Yay!</p>
<p>Other takeaways:</p>
<p>Lots of folks were happily using <a href="http://www.rightscale.com">RightScale</a> to manage Amazon EC2 instances and automatically grow or shrink the server pool based on load.</p>
<p><a href="http://aws.amazon.com/ibm/">IBM provides Amazon machine images</a> of its popular products like WebSphere  FREE for development use (other than Amazon charges, of course).</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[CloudCamp Atlanta tonight]]></title>
<link>http://turbomanage.wordpress.com/2009/10/28/cloudcamp-atlanta-tonight/</link>
<pubDate>Wed, 28 Oct 2009 15:38:27 +0000</pubDate>
<dc:creator>David Chandler</dc:creator>
<guid>http://turbomanage.wordpress.com/2009/10/28/cloudcamp-atlanta-tonight/</guid>
<description><![CDATA[I&#8217;m planning to do a short unconference session on securing AppEngine services with gwt-dispat]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>I&#8217;m planning to do a short unconference session on <a href="http://turbomanage.wordpress.com/2009/10/07/calling-appengine-securely-from-gwt-with-gwt-dispatch/">securing AppEngine services with gwt-dispatch</a> and <a href="http://turbomanage.wordpress.com/2009/10/20/how-to-unit-test-gwt-dispatch-actionhandlers-with-guice/">unit testing with AppEngine and gwt-dispatch</a> at tonight&#8217;s <a href="http://www.cloudcamp.com/?page_id=1288">CloudCamp Atlanta</a>.</p>
<p>I&#8217;m looking forward to meeting some local AppEngine developers, as I&#8217;ve been feeling awfully close to the bleeding edge lately. I routinely find that solutions have been posted on AppEngine forums just eight days ago, and sometimes don&#8217;t exist yet. I really need <a href="http://code.google.com/appengine/docs/java/taskqueue/">TaskQueue</a> in order to send out emails, which is still experimental in Labs, and would even more like to use <a href="http://code.google.com/appengine/articles/deferred.html">deferred.defer</a> (less than two weeks old), but alas, it&#8217;s currently only available for Python.</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Writing common test data services for gwt-dispatch with Guice]]></title>
<link>http://turbomanage.wordpress.com/2009/10/28/writing-common-test-data-services-for-gwt-dispatch-with-guice/</link>
<pubDate>Wed, 28 Oct 2009 12:00:57 +0000</pubDate>
<dc:creator>David Chandler</dc:creator>
<guid>http://turbomanage.wordpress.com/2009/10/28/writing-common-test-data-services-for-gwt-dispatch-with-guice/</guid>
<description><![CDATA[The way it stands now after my last several posts on unit testing is that each test method in a JUni]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>The way it stands now after my last several posts on unit testing is that each test method in a JUnit TestCase runs its own context, including its own PersistenceManager injected with Guice. Because I&#8217;m initializing the AppEngine test environment with LocalDatastoreService.NO_STORAGE_PROPERTY = TRUE, any test data I create in one test is not available to the next test method, even in the same TestCase class. This is typical behavior for JUnit test cases, and generally a good thing as each test should be independent, but it does mean we need a convenient way to create test data. My current strategy is twofold:</p>
<ol>
<li> Create test data used by all tests in the TestCase setUp() method that runs before each test</li>
<li>Create common test data (used by multiple TestCases) in test data generator services</li>
</ol>
<p>The first problem to solve is how to get access to a dispatch service and PersistenceManager inside the test data generators. Both are now being injected by Guice as covered in previous posts, so I&#8217;ve written a BaseTestDataService that does the Guice magic:</p>
<pre class="brush: java;">
package com.roa.test.service;

import net.customware.gwt.dispatch.client.standard.StandardDispatchService;

import com.google.inject.Guice;
import com.google.inject.Injector;
import com.roa.server.guice.ServerModule;
import com.turbomanage.gwt.server.PMF;
import com.turbomanage.gwt.server.guice.DispatchTestModule;

public class BaseTestDataService
{
	protected static Injector inj = Guice.createInjector(new ServerModule(),
		new DispatchTestModule());;

	protected static StandardDispatchService getService()
	{
		return inj.getInstance(StandardDispatchService.class);
	}

	protected static PMF getPMF()
	{
		return inj.getInstance(PMF.class);
	}
}
</pre>
<p>I&#8217;m intentionally using a static getPMF() method to make it as simple as possible to use the test data services in a unit test via static methods. Alternatively, I could have used instance methods and constructor injection, but then you&#8217;d have to create a new instance of a test data service in each test, which is just that much more code to write&#8230; Also, constructor injection is not possible in this case because the TestCases themselves are not instantiated by Guice, so instantiating a new test data service from a test case would not involve Guice, either.</p>
<p>It does not matter that the BaseTestDataService and BaseTest (below) are both calling Guice.createInjector() and thereby creating multiple Guice contexts, each having its own PMF instance. The important thing for these database tests is that they&#8217;re all going against one Datastore, not one PersistenceManager.</p>
<p>Here&#8217;s a simple test data generator that extends BaseTestDataService and provides a method to add a test user:</p>
<pre class="brush: java;">
package com.roa.test.service;

import com.roa.client.domain.User;
import com.roa.shared.rpc.AddUserAction;
import com.roa.shared.rpc.AddUserResult;

public class UserTestDataService extends BaseTestDataService
{
	public static User addTestUser() throws Exception
	{
		// Create new user
		User u = new User();
		u.setEmailAddress(&#34;test@example.com&#34;);
		u.setFirstName(&#34;Test&#34;);
		u.setLastName(&#34;User&#34;);
		u.setGoogleAccountId(&#34;testAccountId&#34;);
		AddUserResult userResult = (AddUserResult) getService().execute(
			new AddUserAction(u));
		u = userResult.getUser();
		return u;
	}
}
</pre>
<p>Note the call to getService() on line 17. Thanks to Guice, test data generator services can invoke gwt-dispatch ActionHandlers the same way as the tests themselves.<br />
Finally, here&#8217;s a test case that calls the above service to create a test user in the Datastore:</p>
<pre class="brush: java;">
package com.roa.test;

import java.util.List;

import javax.jdo.Query;

import com.appenginefan.toolkit.unittests.BaseTest;
import com.roa.client.domain.User;
import com.roa.test.service.UserTestDataService;

public class UserTestCase extends BaseTest
{

	@Override
	protected void setUp() throws Exception
	{
		super.setUp();
		UserTestDataService.addTestUser();
	}

	public void testUserAdded() throws Exception
	{
		// Run tests here
		Query q = pm.newQuery(User.class, &#34;emailAddress == e&#34;);
		q.declareParameters(&#34;java.lang.String e&#34;);
		List&#60;User&#62; users = (List&#60;com.roa.client.domain.User&#62;) q.execute(&#34;test@example.com&#34;);
		assertEquals(1, users.size());
		User user = users.get(0);
		assertNotNull(user.getId());
	}
}
</pre>
<p>I should probably show my BaseTest method, too. I&#8217;m using AppEngineFan&#8217;s BaseTest as discussed in previous posts and modified the setUp() method for Guice injection as follows:</p>
<pre class="brush: java;">
	/**
	 * Sets up the App Engine environment.
	 */
	@Override
	protected void setUp() throws Exception
	{
		if (initializer != null)
		{
			throw new UnsupportedOperationException(
				&#34;setup may only be called once!&#34;);
		}
		super.setUp();
		initializer = new TestInitializer(getEnvironmentOrNull());
		initializer.setUp();
		Injector inj = Guice.createInjector(new ServerModule(),
			new DispatchTestModule());
		this.testSvc = inj.getInstance(StandardDispatchService.class);
		this.pm = inj.getInstance(PMF.class).getPersistenceManager();
	}
</pre>
<p>Thanks to Guice, we can now get access to the PersistenceManager and call ActionHandlers via a dispatch test service even from static methods in test data generators. This greatly streamlines unit testing.</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[More on unit testing with an injected JDO PersistenceManager]]></title>
<link>http://turbomanage.wordpress.com/2009/10/27/more-on-unit-testing-with-an-injected-jdo-persistencemanager/</link>
<pubDate>Tue, 27 Oct 2009 17:27:56 +0000</pubDate>
<dc:creator>David Chandler</dc:creator>
<guid>http://turbomanage.wordpress.com/2009/10/27/more-on-unit-testing-with-an-injected-jdo-persistencemanager/</guid>
<description><![CDATA[Regarding my previous post, it turns out that I needed a TestPMF implementation sooner than I though]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>Regarding <a href="http://turbomanage.wordpress.com/2009/10/26/unit-testing-with-jdo-persistencemanager-injected-via-guice/">my previous post</a>, it turns out that I needed a TestPMF implementation sooner than I thought. The reason is the way I&#8217;m injecting a DispatchTestService in my unit tests (as described in <a href="http://turbomanage.wordpress.com/2009/10/20/how-to-unit-test-gwt-dispatch-actionhandlers-with-guice/">this post</a>). I&#8217;m calling createInjector() in the setUp() method, which gets run before each test method:</p>
<pre class="brush: java;">
	@Override
	protected void setUp() throws Exception
	{
		super.setUp();
		Injector inj = Guice.createInjector(new ServerModule(),
			new DispatchTestModule());
		testSvc = inj.getInstance(StandardDispatchService.class);
		// This pm is needed only for code in this class that calls a PM directly
		// ActionHandlers are injected with the PMF singleton from Guice
		pm = inj.getInstance(PMF.class).getPersistenceManager();
	}
</pre>
<p>Since setUp() gets called before each test method, Guice is initialized for each test method, and therefore Guice calls the constructor for my DefaultPMF class for each test method. Repeated from the previous post, the DefaultPMF class looks like:</p>
<pre class="brush: java;">
package com.turbomanage.gwt.server;

import javax.jdo.JDOHelper;
import javax.jdo.PersistenceManager;
import javax.jdo.PersistenceManagerFactory;

public final class DefaultPMF implements com.turbomanage.gwt.server.PMF
{
	private final PersistenceManagerFactory pmfInstance = JDOHelper
			.getPersistenceManagerFactory(&#34;transactions-optional&#34;);

	public DefaultPMF()
	{
	}

	@Override
	public PersistenceManager getPersistenceManager()
	{
		return pmfInstance.getPersistenceManager();
	}
}
</pre>
<p>Because DefaultPMF creates a named PersistenceManagerFactory, JDO complains that the named PersistenceManagerFactory has already been created. My solution for now is to replace the DefaultPMF with a TestPMF that uses a Properties map to initialize the PersistenceManager, just as the <a href="http://turbomanage.wordpress.com/2009/10/19/unit-testing-the-appengine-datastore-with-jdo/">AppEngineFan TestInitializer</a> does. Here&#8217;s a working TestPMF:</p>
<pre class="brush: java;">
package com.turbomanage.gwt.server;

import java.util.Properties;

import javax.jdo.JDOHelper;
import javax.jdo.PersistenceManager;
import javax.jdo.PersistenceManagerFactory;

public class TestPMF implements PMF
{
	private final PersistenceManagerFactory pmf;

	public TestPMF()
	{
		Properties newProperties = new Properties();
		newProperties
			.put(&#34;javax.jdo.PersistenceManagerFactoryClass&#34;,
				&#34;org.datanucleus.store.appengine.jdo.DatastoreJDOPersistenceManagerFactory&#34;);
		newProperties.put(&#34;javax.jdo.option.ConnectionURL&#34;, &#34;appengine&#34;);
		newProperties.put(&#34;javax.jdo.option.NontransactionalRead&#34;, &#34;true&#34;);
		newProperties.put(&#34;javax.jdo.option.NontransactionalWrite&#34;, &#34;true&#34;);
		newProperties.put(&#34;javax.jdo.option.RetainValues&#34;, &#34;true&#34;);
		newProperties.put(&#34;datanucleus.appengine.autoCreateDatastoreTxns&#34;,
			&#34;true&#34;);
		newProperties.put(&#34;datanucleus.appengine.autoCreateDatastoreTxns&#34;,
			&#34;true&#34;);
		pmf = JDOHelper.getPersistenceManagerFactory(newProperties);
	}

	@Override
	public PersistenceManager getPersistenceManager()
	{
		return pmf.getPersistenceManager();
	}

}
</pre>
<p>Now simply bind PMF to its TestPMF implementation in your Guice module for tests (DispatchTestModule in the setUp() method above), and each unit test method will run with a freshly created PersistenceManager.</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Blog on Rails]]></title>
<link>http://webapprentice.wordpress.com/2009/10/26/hello-everyone/</link>
<pubDate>Mon, 26 Oct 2009 17:23:41 +0000</pubDate>
<dc:creator>fceruti</dc:creator>
<guid>http://webapprentice.wordpress.com/2009/10/26/hello-everyone/</guid>
<description><![CDATA[This blog is about my road to become a multi millionaire web entreprener, dreaming is free . I]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p style="text-align:left;"><a rel="attachment wp-att-14" href="http://webapprentice.wordpress.com/2009/10/26/hello-everyone/marcas_web2_nacientes/"><img class="size-full wp-image-14 aligncenter" title="marcas_web2_nacientes" src="http://webapprentice.wordpress.com/files/2009/10/marcas_web2_nacientes.jpg" alt="marcas_web2_nacientes" width="420" height="312" /></a></p>
<p style="text-align:left;">This <strong>blog</strong> is about my road to become a <strong>multi millionaire web entreprener, </strong>dreaming is free . I&#8217;ll be writing lots of technical stuff, like GWT (Google Web Toolkit), Google AppEngine, Amazon EC2, Java, ruby, html5, css, linux or whatever topic I think is interesting. But also there&#8217;s going to be post about <strong>&#60;insert your topic here&#62;</strong>, which is really great! Haha, I say this because I don&#8217;t want to feel my hands are tied up because of some silly structure.</p>
<p style="text-align:center;"><a rel="attachment wp-att-23" href="http://webapprentice.wordpress.com/2009/10/26/hello-everyone/16-ways-to-save-100-01-af/"><img class="aligncenter size-full wp-image-23" title="16-ways-to-save-100-01-af" src="http://webapprentice.wordpress.com/files/2009/10/16-ways-to-save-100-01-af.jpg" alt="16-ways-to-save-100-01-af" width="344" height="209" /></a></p>
<p style="text-align:left;">That being said, <strong>&#8220;who the hell are you?&#8221;</strong> you may ask. Well my name is Francisco Ceruti, I&#8217;m a college student who&#8217;s biggest dream is to be <strong>&#8220;the most successful drop out&#8221;</strong>. Bill Gates said that phrase on a speech he gave to the Harvard graduates (you may guess, and correctly, that I&#8217;m a youtube junky), and I thought that was the biggest honor I could have, so right now, that&#8217;s my personal goal.</p>
<p style="text-align:left;">Please watch the following add:</p>
<p style="text-align:left;"><span style='text-align:center; display: block;'><object width='425' height='350'><param name='movie' value='http://www.youtube.com/v/jqLPHrCQr2I&#038;rel=1&#038;fs=1&#038;showsearch=0&#038;hd=0' /><param name='allowfullscreen' value='true' /><param name='wmode' value='transparent' /><embed src='http://www.youtube.com/v/jqLPHrCQr2I&#038;rel=1&#038;fs=1&#038;showsearch=0&#038;hd=0' type='application/x-shockwave-flash' allowfullscreen='true' width='425' height='350' wmode='transparent'></embed></object></span></p>
<p style="text-align:left;">I thought it was hilarious, and the reason I&#8217;m showing you that, is because I have someone I look forward to a lot, he is not as cool as the usb port inventor, but anyway, that guy is <strong>Steve Jobs</strong>. The man leads a team that makes elegant products, with really polished user interfases, cares about how it looks and feels in your hands, basically takes into account so many more factors than what the competition in general does. He really sets as a first priority the user experience. I&#8217;m not a mac user myself, mostly because they are <strong>so expensive</strong>, but if I had the money I would undoubtly have at least one. For now, I&#8217;m happy with <strong>Ubuntu</strong> (psss, 3 days for 9.10 Karmic Koala release).</p>
<p style="text-align:left;"><img class="aligncenter" title="Early days" src="http://chandrakantha.com/articles/indian_music/filmi_sangeet/media/1976_steve_jobs3.jpg" alt="" width="324" height="309" /><br />
I&#8217;ll try to submit new post on a weekly basis, and hopefully you will enjoy it. Also, I resently got <strong>twitter,</strong> so if you like you can follow me! Mi nick is fceruti.</p>
<p style="text-align:left;"><strong>PD:</strong>One thing I want to add is that my native language is<strong> not english</strong>, nor I live on a english speaking country, so any help with that would be greatly appreciated.</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Unit testing with JDO PersistenceManager injected via Guice]]></title>
<link>http://turbomanage.wordpress.com/2009/10/26/unit-testing-with-jdo-persistencemanager-injected-via-guice/</link>
<pubDate>Mon, 26 Oct 2009 14:34:17 +0000</pubDate>
<dc:creator>David Chandler</dc:creator>
<guid>http://turbomanage.wordpress.com/2009/10/26/unit-testing-with-jdo-persistencemanager-injected-via-guice/</guid>
<description><![CDATA[This is a follow-up to last week&#8217;s post on unit testing ActionHandlers with Guice. David Peter]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>This is a follow-up to last week&#8217;s post on <a href="http://turbomanage.wordpress.com/2009/10/20/how-to-unit-test-gwt-dispatch-actionhandlers-with-guice/">unit testing ActionHandlers with Guice</a>. David Peterson pointed out on the <a href="http://groups.google.com/group/gwt-dispatch/browse_thread/thread/5c55acec924381bb">gwt-dispatch mailing list</a> that I could inject a PersistenceManager into my ActionHandlers in order to provide an alternate PersistenceManager for unit testing. I don&#8217;t actually need an alternate PM yet as it is handled transparently by my <a href="http://turbomanage.wordpress.com/2009/10/19/unit-testing-the-appengine-datastore-with-jdo/">AppEngine test environment</a>, but I thought it would be easier to do it sooner rather than later, so here goes.</p>
<p>I&#8217;ve created an interface called PMF (in order to avoid confusion with JDO&#8217;s PersistenceManagerFactory).</p>
<pre class="brush: java;">
package com.turbomanage.gwt.server;

import javax.jdo.PersistenceManager;

public interface PMF
{
	PersistenceManager getPersistenceManager();
}
</pre>
<p>My default PMF implementation works exactly the same as before:</p>
<pre class="brush: java;">
package com.turbomanage.gwt.server;

import javax.jdo.JDOHelper;
import javax.jdo.PersistenceManager;
import javax.jdo.PersistenceManagerFactory;

public final class DefaultPMF implements com.turbomanage.gwt.server.PMF
{
	private final PersistenceManagerFactory pmfInstance = JDOHelper
			.getPersistenceManagerFactory(&#34;transactions-optional&#34;);

	public DefaultPMF()
	{
	}

	@Override
	public PersistenceManager getPersistenceManager()
	{
		return pmfInstance.getPersistenceManager();
	}
}
</pre>
<p>The DefaultPMF gets bound in my Guice ServerModule:</p>
<pre class="brush: java;">
	@Override
	protected void configureHandlers()
	{
		...
		bind(PMF.class).to(DefaultPMF.class).in(Singleton.class);
		...
	}
</pre>
<p>And finally, the PMF is injected into an ActionHandler:</p>
<pre class="brush: java;">
public class AddUserHandler implements
	ActionHandler&#60;AddUserAction, AddUserResult&#62;
{
	@Inject
	private PMF pmf;
	private PersistenceManager pm;

	@Override
	public AddUserResult execute(AddUserAction action, ExecutionContext context)
		throws ActionException
	{
		this.pm = pmf.getPersistenceManager();
		...
	}
	...
}
</pre>
<p>Now, when the need arises for a test implementation of PMF, I can easily bind a different implementation in my Guice TestModule as shown in the earlier post.</p>
<p>Update: I did not test this thoroughly before I posted, and  the need for a TestPMF arose just hours later. See my <a href="http://turbomanage.wordpress.com/2009/10/27/more-on-unit-testing-with-an-injected-jdo-persistencemanager/">next post</a> for the solution.</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Java on Google App Engine]]></title>
<link>http://fluxqubit.wordpress.com/2009/10/22/java-on-google-app-engine/</link>
<pubDate>Thu, 22 Oct 2009 08:07:25 +0000</pubDate>
<dc:creator>doxaras</dc:creator>
<guid>http://fluxqubit.wordpress.com/2009/10/22/java-on-google-app-engine/</guid>
<description><![CDATA[Image via CrunchBase I have readopted JDO recently. The cause ? Google App Engine&#8217;s big table ]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><div class="zemanta-image" style="float:right;"><a title="Non-free, could qualify as fair-use" href="http://www.crunchbase.com/product/google-app-engine"><img src="http://www.crunchbase.com/assets/images/resized/0001/6975/16975v2-max-250x250.jpg" alt="" /></a><br />
Image via <a href="http://www.crunchbase.com">CrunchBase</a></div>
<p>I have readopted JDO recently. The cause ? Google App Engine&#8217;s big table storage model that makes JDO, a storage agnostic framework for persistence, ideal for such implementations.</p>
<p>Some very useful links related to Java on the GAE are following</p>
<ol>
<li><a href="http://code.google.com/appengine/docs/java/jrewhitelist.html%20">JRE Class White List</a> A Java App Engine application&#8217;s access to the classes in the Java standard library (the Java Runtime Environment, or JRE) is limited to the classes displayed in that link.</li>
<li><a href="http://groups.google.com/group/google-appengine-java/web/will-it-play-in-app-engine">Will it Play in App Engine</a>. This google group post aggregates all known java technologies and frameworks with commenting on whether or not they are applicable to the appengine JVM runtime. As we have discussed before limitations to certain JEE classes will stop many of the well adopted frameworks to operate.</li>
<li><a href="http://code.google.com/p/sfdc-wsc/">Web Services Connector.</a> Due to limitations in the java.net core library many web services client frameworks fail to operate in appengine. Frameworks such as axis, axis2, JAX-WS do not have compatibility since they use not authorized classes. A simple and lightweight alternative is   WSC from people in salesforge.com that generates a simple jar client provided the wsdl document services definition. Another more nasty alternative is to implement the calls to the service by yourself and use JAXB or JIBX or even xmlnbeans to marshal/unmarshal the request/response documents.</li>
</ol>
</div>]]></content:encoded>
</item>

</channel>
</rss>
