Class BackendServersBase
java.lang.Object
com.google.appengine.tools.development.BackendServersBase
- All Implemented Interfaces:
LocalServerController,AbstractContainerService.PortMappingProvider,BackendContainer
- Direct Known Subclasses:
BackendServers,BackendServersEE8
public class BackendServersBase
extends Object
implements BackendContainer, LocalServerController, AbstractContainerService.PortMappingProvider
Controls backend servers configured in appengine-web.xml. Each server is started on a separate
port. All servers run the same code as the main app.
-
Nested Class Summary
Nested classes/interfaces inherited from interface com.google.appengine.api.backends.dev.LocalServerController
LocalServerController.BackendStateInfo, LocalServerController.InstanceStateInfo -
Field Summary
FieldsFields inherited from interface com.google.appengine.api.backends.dev.LocalServerController
BACKEND_CONTROLLER_ATTRIBUTE_KEY -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanacquireServingPermit(String serverName, int instanceNumber, boolean allowQueueOnBackends) This method guards access to servers to limit the number of concurrent requests.booleancheckInstanceExists(String serverName, int instance) Verifies if a specific server/instance is configured.booleancheckInstanceStopped(String serverName, int instance) Verifies if a specific server/instance is stopped.booleancheckServerExists(String serverName) Verifies if a specific server is configured.booleancheckServerStopped(String serverName) Verifies if a specific server is stopped.voidconfigureAll(ApiProxyLocal local) intgetAndReserveFreeInstance(String requestedServer) Reserves an instance for this request.getBackendState(String requestHostName) Returns a map containing all information about current backend state.static BackendServersBaseintReturns the port for the requested instance.Allows the servers API to get the current mapping from server and instance to listening ports.intgetServerInstanceFromPort(int port) Returns the server instance serving on a specific local portgetServerNameFromPort(int port) Returns the server serving on a specific local portvoidinit(String address, ApplicationConfigurationManager.ModuleConfigurationHandle moduleConfigurationHandle, File externalResourceDirectory, Map<String, Object> containerConfigProperties, DevAppServer devAppServer) voidreturnServingPermit(String serverName, int instance) Method for returning a serving permit after a request has completed.voidsetServiceProperties(Map<String, String> properties) voidShutdown all backend instances.voidstartBackend(String serverToStart) Start all instances in STOPPED state of a single backend.voidStart all backend instances.voidstopBackend(String serverToStop) Stop all instances in RUNNING state of a single backend, reset the internal state of each instance, and set state to STOPPED so that any subsequent requests receive a 500 error code response.
-
Field Details
-
SYSTEM_PROPERTY_STATIC_PORT_NUM_PREFIX
- See Also:
-
-
Constructor Details
-
BackendServersBase
public BackendServersBase()
-
-
Method Details
-
getInstance
-
init
public void init(String address, ApplicationConfigurationManager.ModuleConfigurationHandle moduleConfigurationHandle, File externalResourceDirectory, Map<String, Object> containerConfigProperties, DevAppServer devAppServer) - Specified by:
initin interfaceBackendContainer
-
setServiceProperties
- Specified by:
setServicePropertiesin interfaceBackendContainer
-
shutdownAll
Description copied from interface:BackendContainerShutdown all backend instances.- Specified by:
shutdownAllin interfaceBackendContainer- Throws:
Exception
-
getBackendState
public TreeMap<String,LocalServerController.BackendStateInfo> getBackendState(String requestHostName) Description copied from interface:LocalServerControllerReturns a map containing all information about current backend state.- Specified by:
getBackendStatein interfaceLocalServerController- Parameters:
requestHostName- The hostname of the request, if null is specified the listen address will be used.- Returns:
- Backend name -> backend information mapping for all configured backends.
-
startBackend
Description copied from interface:LocalServerControllerStart all instances in STOPPED state of a single backend.- Specified by:
startBackendin interfaceLocalServerController- Parameters:
serverToStart- The backend to start.- Throws:
IllegalStateException- is the specified backend does not exist.
-
stopBackend
Description copied from interface:LocalServerControllerStop all instances in RUNNING state of a single backend, reset the internal state of each instance, and set state to STOPPED so that any subsequent requests receive a 500 error code response.- Specified by:
stopBackendin interfaceLocalServerController- Parameters:
serverToStop- The backend to stop.- Throws:
Exception- if an error occurred that prevented the backend from resetting cleanly.
-
configureAll
- Throws:
Exception
-
startupAll
Description copied from interface:BackendContainerStart all backend instances.- Specified by:
startupAllin interfaceBackendContainer- Throws:
Exception
-
acquireServingPermit
public boolean acquireServingPermit(String serverName, int instanceNumber, boolean allowQueueOnBackends) This method guards access to servers to limit the number of concurrent requests. Each request running on a server must acquire a serving permit. If no permits are available a 500 response should be sent.- Parameters:
serverName- The server for which to acquire a permit.instanceNumber- The server instance for which to acquire a permit.allowQueueOnBackends- If set to false the method will return instantly, if set to true (and the specified server allows pending queues) this method can block for up to 10 s waiting for a serving permit to become available.- Returns:
- true if a permit was acquired, false otherwise
-
getAndReserveFreeInstance
Reserves an instance for this request. For workers this method will return -1 if no free instances are available. For backends this method will assign this request to the instance with the shortest queue and block until that instance is ready to serve the request.- Parameters:
requestedServer- Name of the server the request is to.- Returns:
- the instance id of an available server instance, or -1 if no instance is available.
-
returnServingPermit
Method for returning a serving permit after a request has completed.- Parameters:
serverName- The server nameinstance- The server instance
-
getPort
Returns the port for the requested instance. -
checkInstanceExists
Verifies if a specific server/instance is configured.- Parameters:
serverName- The server nameinstance- The server instance- Returns:
- true if the server/instance is configured, false otherwise.
-
checkServerExists
Verifies if a specific server is configured.- Parameters:
serverName- The server name- Returns:
- true if the server is configured, false otherwise.
-
checkServerStopped
Verifies if a specific server is stopped.- Parameters:
serverName- The server name- Returns:
- true if the server is stopped, false otherwise.
-
checkInstanceStopped
Verifies if a specific server/instance is stopped.- Parameters:
serverName- The server nameinstance- The server instance- Returns:
- true if the server/instance is stopped, false otherwise.
-
getPortMapping
Allows the servers API to get the current mapping from server and instance to listening ports.- Specified by:
getPortMappingin interfaceAbstractContainerService.PortMappingProvider- Returns:
- The port map
-
getServerInstanceFromPort
public int getServerInstanceFromPort(int port) Returns the server instance serving on a specific local port- Parameters:
port- the local tcp port that received the request- Returns:
- the server instance, or -1 if no server instance is running on that port
-
getServerNameFromPort
Returns the server serving on a specific local port- Parameters:
port- the local tcp port that received the request- Returns:
- the server name, or null if no server instance is running on that port
-