27 August 2009

GAE + GWT Starter Project. 6) Building up the Server

The server side of this design is a cache pipeline wrapped by a GWT RPC service. Today I attempted to implement this.

First I built up the cache pipeline. This was a simple design with each cache stage basically the code below.

public V get(K key) {
  V value = cacheActual.get(key);
  if (value == null) {
if (nextStage != null) {
value = nextStage.get(key);
if (value != null) {
cacheActual.put(key, value); 
}
}
  }
  return value;
}
public void put(K key, V value) {
  V val = cacheActual.get(key);
  if (!(val != null && val.equals(value))) {
cacheActual.put(key, value);
if (nextStage != null) {
nextStage.put(key);
}
  }
}


Building this up took 5 Java classes

  • CacheStage.java (the code above)
  • CachePipeline.java  (hooks together CacheStage's in a pipeline)
  • CacheActual.java  (interface for actual caches)
  • CacheCache.java  (memcache implementation)
  • CacheDB.java  (datastore + web-service implementation with datastore intially stubbed)
There were no surprises in this.

Next I wrapped this a GWT style RPC server. This took some classes
  • PersonService.java  (interface for class containing the RPC call)
  • PersonServiceAsync.java (async version of  PersonService.java)
  • PersonServiceImpl.java (server side implementation of PersonService.java)
Defining these classes required defining the person class that is seen by clients.
  • PersonClient.java  (the client-side person class)
  • PersonFetch.java  (person + tracking data to cross-reference to requests, required for best-effort operation)
  • PersonClientGroup.java (a class to wrap all the data returned by the RPC call)
  • PersonTrait.java (since the server and client person classes differ, we need to specify the canonical person traits such as name, address, uniqueID, and have all person classes implement this interface)
That, plus a few helper classes, got the first iteration of the server implemented. There were 21 .java files which seemed like a lot for the amount of functionality created, but most of them were simple. Code is here.

You can watch this project's progress here.

0 comments: