Class BackendServersBase

java.lang.Object
com.google.appengine.tools.development.BackendServersBase
All Implemented Interfaces:
LocalServerController, AbstractContainerService.PortMappingProvider, BackendContainer
Direct Known Subclasses:
BackendServers, BackendServersEE8

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.
  • Field Details

    • SYSTEM_PROPERTY_STATIC_PORT_NUM_PREFIX

      public static final String SYSTEM_PROPERTY_STATIC_PORT_NUM_PREFIX
      See Also:
  • Constructor Details

    • BackendServersBase

      public BackendServersBase()
  • Method Details

    • getInstance

      public static BackendServersBase getInstance()
    • init

      public void init(String address, ApplicationConfigurationManager.ModuleConfigurationHandle moduleConfigurationHandle, File externalResourceDirectory, Map<String,Object> containerConfigProperties, DevAppServer devAppServer)
      Specified by:
      init in interface BackendContainer
    • setServiceProperties

      public void setServiceProperties(Map<String,String> properties)
      Specified by:
      setServiceProperties in interface BackendContainer
    • shutdownAll

      public void shutdownAll() throws Exception
      Description copied from interface: BackendContainer
      Shutdown all backend instances.
      Specified by:
      shutdownAll in interface BackendContainer
      Throws:
      Exception
    • getBackendState

      public TreeMap<String,LocalServerController.BackendStateInfo> getBackendState(String requestHostName)
      Description copied from interface: LocalServerController
      Returns a map containing all information about current backend state.
      Specified by:
      getBackendState in interface LocalServerController
      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

      public void startBackend(String serverToStart) throws IllegalStateException
      Description copied from interface: LocalServerController
      Start all instances in STOPPED state of a single backend.
      Specified by:
      startBackend in interface LocalServerController
      Parameters:
      serverToStart - The backend to start.
      Throws:
      IllegalStateException - is the specified backend does not exist.
    • stopBackend

      public void stopBackend(String serverToStop) throws Exception
      Description copied from interface: LocalServerController
      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.
      Specified by:
      stopBackend in interface LocalServerController
      Parameters:
      serverToStop - The backend to stop.
      Throws:
      Exception - if an error occurred that prevented the backend from resetting cleanly.
    • configureAll

      public void configureAll(ApiProxyLocal local) throws Exception
      Throws:
      Exception
    • startupAll

      public void startupAll() throws Exception
      Description copied from interface: BackendContainer
      Start all backend instances.
      Specified by:
      startupAll in interface BackendContainer
      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

      public int getAndReserveFreeInstance(String requestedServer)
      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

      public void returnServingPermit(String serverName, int instance)
      Method for returning a serving permit after a request has completed.
      Parameters:
      serverName - The server name
      instance - The server instance
    • getPort

      public int getPort(String serverName, int instance)
      Returns the port for the requested instance.
    • checkInstanceExists

      public boolean checkInstanceExists(String serverName, int instance)
      Verifies if a specific server/instance is configured.
      Parameters:
      serverName - The server name
      instance - The server instance
      Returns:
      true if the server/instance is configured, false otherwise.
    • checkServerExists

      public boolean checkServerExists(String serverName)
      Verifies if a specific server is configured.
      Parameters:
      serverName - The server name
      Returns:
      true if the server is configured, false otherwise.
    • checkServerStopped

      public boolean checkServerStopped(String serverName)
      Verifies if a specific server is stopped.
      Parameters:
      serverName - The server name
      Returns:
      true if the server is stopped, false otherwise.
    • checkInstanceStopped

      public boolean checkInstanceStopped(String serverName, int instance)
      Verifies if a specific server/instance is stopped.
      Parameters:
      serverName - The server name
      instance - The server instance
      Returns:
      true if the server/instance is stopped, false otherwise.
    • getPortMapping

      public Map<String,String> getPortMapping()
      Allows the servers API to get the current mapping from server and instance to listening ports.
      Specified by:
      getPortMapping in interface AbstractContainerService.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

      public String getServerNameFromPort(int port)
      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