com.google.appengine.tools.development
Class ApiProxyLocalImpl

java.lang.Object
  extended by com.google.appengine.tools.development.ApiProxyLocalImpl
All Implemented Interfaces:
ApiProxyLocal

public class ApiProxyLocalImpl
extends java.lang.Object
implements ApiProxyLocal

Implements ApiProxy.Delegate such that the requests are dispatched to local service implementations. Used for both the DevAppServer and for unit testing services.


Method Summary
 com.google.appengine.tools.development.LocalRpcService getService(java.lang.String pkg)
          Method needs to be synchronized to ensure that we don't end up starting multiple instances of the same service.
 void log(ApiProxy.Environment environment, LogRecord record)
           
 java.util.concurrent.Future<byte[]> makeAsyncCall(ApiProxy.Environment environment, java.lang.String packageName, java.lang.String methodName, byte[] requestBytes, ApiProxy.ApiConfig apiConfig)
           
 byte[] makeSyncCall(Environment environment, java.lang.String packageName, java.lang.String methodName, byte[] requestBytes)
           
 void setProperties(java.util.Map<java.lang.String,java.lang.String> properties)
          Resets the service properties to properties.
 void setProperty(java.lang.String property, java.lang.String value)
          Sets an individual service property.
 void stop()
          Stops all services started by this ApiProxy and releases all of its resources.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

log

public void log(ApiProxy.Environment environment,
                LogRecord record)

makeSyncCall

public byte[] makeSyncCall(Environment environment,
                           java.lang.String packageName,
                           java.lang.String methodName,
                           byte[] requestBytes)

makeAsyncCall

public java.util.concurrent.Future<byte[]> makeAsyncCall(ApiProxy.Environment environment,
                                                         java.lang.String packageName,
                                                         java.lang.String methodName,
                                                         byte[] requestBytes,
                                                         ApiProxy.ApiConfig apiConfig)

setProperty

public void setProperty(java.lang.String property,
                        java.lang.String value)
Description copied from interface: ApiProxyLocal
Sets an individual service property.

Specified by:
setProperty in interface ApiProxyLocal
Parameters:
property - name of the property to set
value - new value of the property

setProperties

public void setProperties(java.util.Map<java.lang.String,java.lang.String> properties)
Resets the service properties to properties.

Specified by:
setProperties in interface ApiProxyLocal
Parameters:
properties - a maybe null set of properties for local services.

stop

public void stop()
Stops all services started by this ApiProxy and releases all of its resources. TODO(tobyr) When we fix DevAppServer to support hot redeployment, it MUST call into stop when it is attempting to GC a webapp (otherwise background threads won't be stopped, etc...)

Specified by:
stop in interface ApiProxyLocal

getService

public final com.google.appengine.tools.development.LocalRpcService getService(java.lang.String pkg)
Method needs to be synchronized to ensure that we don't end up starting multiple instances of the same service. As an example, we've seen a race condition where the local datastore service has not yet been initialized and two datastore requests come in at the exact same time. The first request looks in the service cache, doesn't find it, starts a new local datastore service, registers it in the service cache, and uses that local datastore service to handle the first request. Meanwhile the second request looks in the service cache, doesn't find it, starts a new local datastore service, registers it in the service cache (stomping on the original one), and uses that local datastore service to handle the second request. If both of these requests start txns we can end up with 2 requests receiving the same txn id, and that yields all sorts of exciting behavior. So, we synchronize this method to ensure that we only register a single instance of each service type.

Specified by:
getService in interface ApiProxyLocal
Parameters:
pkg - The package identifying the service we want.
Returns:
The requested service, or null if no service identified by the given package is available.