Class ApiProxyLocalImpl
java.lang.Object
com.google.appengine.tools.development.ApiProxyLocalImpl
- All Implemented Interfaces:
ApiProxyLocal,DevServices,com.google.apphosting.api.ApiProxy.Delegate<com.google.apphosting.api.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(com.google.apphosting.api.ApiProxy.Environment environment) com.google.appengine.tools.development.ClockgetClock()getRequestThreads(com.google.apphosting.api.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(com.google.apphosting.api.ApiProxy.Environment environment, com.google.apphosting.api.ApiProxy.LogRecord record) Future<byte[]> makeAsyncCall(com.google.apphosting.api.ApiProxy.Environment environment, String packageName, String methodName, byte[] requestBytes, @Nullable com.google.apphosting.api.ApiProxy.ApiConfig apiConfig) byte[]makeSyncCall(com.google.apphosting.api.ApiProxy.Environment environment, String packageName, String methodName, byte[] requestBytes) voidsetClock(com.google.appengine.tools.development.Clock clock) Sets 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
public void log(com.google.apphosting.api.ApiProxy.Environment environment, com.google.apphosting.api.ApiProxy.LogRecord record) - Specified by:
login interfacecom.google.apphosting.api.ApiProxy.Delegate<com.google.apphosting.api.ApiProxy.Environment>
-
flushLogs
public void flushLogs(com.google.apphosting.api.ApiProxy.Environment environment) - Specified by:
flushLogsin interfacecom.google.apphosting.api.ApiProxy.Delegate<com.google.apphosting.api.ApiProxy.Environment>
-
makeSyncCall
public byte[] makeSyncCall(com.google.apphosting.api.ApiProxy.Environment environment, String packageName, String methodName, byte[] requestBytes) - Specified by:
makeSyncCallin interfacecom.google.apphosting.api.ApiProxy.Delegate<com.google.apphosting.api.ApiProxy.Environment>
-
makeAsyncCall
public Future<byte[]> makeAsyncCall(com.google.apphosting.api.ApiProxy.Environment environment, String packageName, String methodName, byte[] requestBytes, @Nullable com.google.apphosting.api.ApiProxy.ApiConfig apiConfig) - Specified by:
makeAsyncCallin interfacecom.google.apphosting.api.ApiProxy.Delegate<com.google.apphosting.api.ApiProxy.Environment>
-
getRequestThreads
- Specified by:
getRequestThreadsin interfacecom.google.apphosting.api.ApiProxy.Delegate<com.google.apphosting.api.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
public com.google.appengine.tools.development.Clock 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
public void setClock(com.google.appengine.tools.development.Clock clock) 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-
-