Class ApiProxyLocalImpl
java.lang.Object
com.google.appengine.tools.development.ApiProxyLocalImpl
- All Implemented Interfaces:
ApiProxyLocal,DevServices,ApiProxy.Delegate<ApiProxy.Environment>
Implements ApiProxy.Delegate such that the requests are dispatched to local service
implementations. Used for both the
DevAppServer
and for unit testing services.-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionApiProxyLocalImpl(LocalServerEnvironment environment) Creates the local proxy in a given context -
Method Summary
Modifier and TypeMethodDescriptionvoidappendProperties(Map<String, String> properties) Appends the given service properties toproperties.voidflushLogs(ApiProxy.Environment environment) getClock()getRequestThreads(ApiProxy.Environment environment) final LocalRpcServicegetService(String pkg) Method needs to be synchronized to ensure that we don't end up starting multiple instances of the same service.voidlog(ApiProxy.Environment environment, ApiProxy.LogRecord record) Future<byte[]> makeAsyncCall(ApiProxy.Environment environment, String packageName, String methodName, byte[] requestBytes, @Nullable ApiProxy.ApiConfig apiConfig) byte[]makeSyncCall(ApiProxy.Environment environment, String packageName, String methodName, byte[] requestBytes) voidSets the clock with which all local services are initialized.voidsetProperties(Map<String, String> properties) Resets the service properties toproperties.voidsetProperty(String serviceProperty, String value) Sets an individual service property.voidstop()Stops all services started by this ApiProxy and releases all of its resources.
-
Field Details
-
IS_OFFLINE_REQUEST_KEY
- See Also:
-
-
Constructor Details
-
ApiProxyLocalImpl
Creates the local proxy in a given context- Parameters:
environment- the local server environment.
-
-
Method Details
-
log
- Specified by:
login interfaceApiProxy.Delegate<ApiProxy.Environment>
-
flushLogs
- Specified by:
flushLogsin interfaceApiProxy.Delegate<ApiProxy.Environment>
-
makeSyncCall
public byte[] makeSyncCall(ApiProxy.Environment environment, String packageName, String methodName, byte[] requestBytes) - Specified by:
makeSyncCallin interfaceApiProxy.Delegate<ApiProxy.Environment>
-
makeAsyncCall
public Future<byte[]> makeAsyncCall(ApiProxy.Environment environment, String packageName, String methodName, byte[] requestBytes, @Nullable ApiProxy.ApiConfig apiConfig) - Specified by:
makeAsyncCallin interfaceApiProxy.Delegate<ApiProxy.Environment>
-
getRequestThreads
- Specified by:
getRequestThreadsin interfaceApiProxy.Delegate<ApiProxy.Environment>
-
setProperty
Description copied from interface:ApiProxyLocalSets an individual service property.- Specified by:
setPropertyin interfaceApiProxyLocal- Parameters:
serviceProperty- name of the property to setvalue- new value of the property
-
setProperties
Resets the service properties toproperties.- Specified by:
setPropertiesin interfaceApiProxyLocal- Parameters:
properties- a maybenullset of properties for local services.
-
appendProperties
Appends the given service properties toproperties.- Specified by:
appendPropertiesin interfaceApiProxyLocal- 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:
stopin interfaceApiProxyLocal
-
getService
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:
getServicein interfaceApiProxyLocal- Parameters:
pkg- The package identifying the service we want.- Returns:
- The requested service, or
nullif no service identified by the given package is available.
-
getLogService
- Specified by:
getLogServicein interfaceDevServices
-
getClock
- Specified by:
getClockin interfaceApiProxyLocal- Returns:
- The clock with which all local services are initialized. Local services use the clock to determine the current time.
-
setClock
Description copied from interface:ApiProxyLocalSets 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:
setClockin interfaceApiProxyLocal- Parameters:
clock-
-