Class ApiProxyLocalImpl

java.lang.Object
com.google.appengine.tools.development.ApiProxyLocalImpl
All Implemented Interfaces:
ApiProxyLocal, DevServices, ApiProxy.Delegate<ApiProxy.Environment>

public class ApiProxyLocalImpl extends Object implements ApiProxyLocal, DevServices
Implements ApiProxy.Delegate such that the requests are dispatched to local service implementations. Used for both the DevAppServer and for unit testing services.
  • Field Details

  • Constructor Details

    • ApiProxyLocalImpl

      public ApiProxyLocalImpl(LocalServerEnvironment environment)
      Creates the local proxy in a given context
      Parameters:
      environment - the local server environment.
  • Method Details

    • log

      public void log(ApiProxy.Environment environment, ApiProxy.LogRecord record)
      Specified by:
      log in interface ApiProxy.Delegate<ApiProxy.Environment>
    • flushLogs

      public void flushLogs(ApiProxy.Environment environment)
      Specified by:
      flushLogs in interface ApiProxy.Delegate<ApiProxy.Environment>
    • makeSyncCall

      public byte[] makeSyncCall(ApiProxy.Environment environment, String packageName, String methodName, byte[] requestBytes)
      Specified by:
      makeSyncCall in interface ApiProxy.Delegate<ApiProxy.Environment>
    • makeAsyncCall

      public Future<byte[]> makeAsyncCall(ApiProxy.Environment environment, String packageName, String methodName, byte[] requestBytes, @Nullable ApiProxy.ApiConfig apiConfig)
      Specified by:
      makeAsyncCall in interface ApiProxy.Delegate<ApiProxy.Environment>
    • getRequestThreads

      public List<Thread> getRequestThreads(ApiProxy.Environment environment)
      Specified by:
      getRequestThreads in interface ApiProxy.Delegate<ApiProxy.Environment>
    • setProperty

      public void setProperty(String serviceProperty, String value)
      Description copied from interface: ApiProxyLocal
      Sets an individual service property.
      Specified by:
      setProperty in interface ApiProxyLocal
      Parameters:
      serviceProperty - name of the property to set
      value - new value of the property
    • setProperties

      public void setProperties(Map<String,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.
    • appendProperties

      public void appendProperties(Map<String,String> properties)
      Appends the given service properties to properties.
      Specified by:
      appendProperties in interface ApiProxyLocal
      Parameters:
      properties - a set of properties to append for local services.
    • stop

      public void stop()
      Stops all services started by this ApiProxy and releases all of its resources.
      Specified by:
      stop in interface ApiProxyLocal
    • getService

      public final LocalRpcService getService(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.
    • getLogService

      public DevLogService getLogService()
      Specified by:
      getLogService in interface DevServices
    • getClock

      public Clock getClock()
      Specified by:
      getClock in interface ApiProxyLocal
      Returns:
      The clock with which all local services are initialized. Local services use the clock to determine the current time.
    • setClock

      public void setClock(Clock clock)
      Description copied from interface: ApiProxyLocal
      Sets the clock with which all local services are initialized. Local services use the clock to determine the current time. Note that calling this method after a local service has already initialized will have no effect.
      Specified by:
      setClock in interface ApiProxyLocal
      Parameters:
      clock -