java.lang.Object
com.google.appengine.tools.development.Modules
All Implemented Interfaces:
ModulesController, ModulesFilterHelper
Direct Known Subclasses:
Modules, ModulesEE8

public class Modules extends Object implements ModulesController, ModulesFilterHelper
Manager for DevAppServer servers.
  • Constructor Details

  • Method Details

    • createModules

      public static Modules createModules(ApplicationConfigurationManager applicationConfigurationManager, String serverInfo, File externalResourceDir, String address, DevAppServer devAppServer)
    • getInstance

      public static Modules getInstance()
    • shutdown

      public void shutdown() throws Exception
      Throws:
      Exception
    • configure

      public void configure(Map<String,Object> containerConfigProperties) throws Exception
      Throws:
      Exception
    • setApiProxyDelegate

      public void setApiProxyDelegate(com.google.apphosting.api.ApiProxy.Delegate<?> apiProxyDelegate)
    • createConnections

      public void createConnections() throws Exception
      Throws:
      Exception
    • startup

      public void startup() throws Exception
      Throws:
      Exception
    • getMainModule

      public Module getMainModule()
    • getLocalServerEnvironment

      public LocalServerEnvironment getLocalServerEnvironment()
    • getModule

      public Module getModule(String moduleName)
    • getModuleNames

      public Iterable<String> getModuleNames()
      Description copied from interface: ModulesController
      Returns all the known module names.
      Specified by:
      getModuleNames in interface ModulesController
    • getVersions

      public Iterable<String> getVersions(String moduleName) throws com.google.apphosting.api.ApiProxy.ApplicationException
      Description copied from interface: ModulesController
      Returns all known versions of the requested module.
      Specified by:
      getVersions in interface ModulesController
      Throws:
      com.google.apphosting.api.ApiProxy.ApplicationException - with error code
      invalid reference
      .modules.ModulesServicePb.ModulesServiceError.ErrorCode#INVALID_MODULE_VALUE
      if the requested module is not configured
    • getDefaultVersion

      public String getDefaultVersion(String moduleName) throws com.google.apphosting.api.ApiProxy.ApplicationException
      Description copied from interface: ModulesController
      Returns the default version for a named module.
      Specified by:
      getDefaultVersion in interface ModulesController
      Throws:
      com.google.apphosting.api.ApiProxy.ApplicationException - with error code
      invalid reference
      .modules.ModulesServicePb.ModulesServiceError.ErrorCode#INVALID_MODULE_VALUE
      if the requested module is not configured
    • getNumInstances

      public int getNumInstances(String moduleName, String version) throws com.google.apphosting.api.ApiProxy.ApplicationException
      Description copied from interface: ModulesController
      Returns the number of instances for the requested module version.
      Specified by:
      getNumInstances in interface ModulesController
      Throws:
      com.google.apphosting.api.ApiProxy.ApplicationException - with error code
      invalid reference
      .modules.ModulesServicePb.ModulesServiceError.ErrorCode#INVALID_MODULE_VALUE
      if the requested module is not configured and
      invalid reference
      .modules.ModulesServicePb.ModulesServiceError.ErrorCode#INVALID_VERSION_VALUE
      if the requested version is not configured.
    • setNumInstances

      public void setNumInstances(String moduleName, String version, int numInstances) throws com.google.apphosting.api.ApiProxy.ApplicationException
      Description copied from interface: ModulesController
      Sets the number of instances for the requested module version.
      Specified by:
      setNumInstances in interface ModulesController
      Throws:
      com.google.apphosting.api.ApiProxy.ApplicationException - with error code
      invalid reference
      .modules.ModulesServicePb.ModulesServiceError.ErrorCode#INVALID_MODULE_VALUE
      if the requested module is not configured and
      invalid reference
      .modules.ModulesServicePb.ModulesServiceError.ErrorCode#INVALID_VERSION_VALUE
      if the requested version is not configured for setting instances .ErrorCode#INVALID_INSTANCES if numInstances is not a legal value.
    • getHostname

      public String getHostname(String moduleName, String version, int instance) throws com.google.apphosting.api.ApiProxy.ApplicationException
      Description copied from interface: ModulesController
      Returns the host name of the requested module version instance.
      Specified by:
      getHostname in interface ModulesController
      Parameters:
      moduleName - the moduleName whose host we return.
      version - the version whose host we return.
      instance - the instance whose host we return or
      invalid reference
      .tools.development.LocalEnvironment#MAIN_INSTANCE
      Throws:
      com.google.apphosting.api.ApiProxy.ApplicationException - with error code
      invalid reference
      .modules.ModulesServicePb.ModulesServiceError.ErrorCode#INVALID_MODULE_VALUE
      if the requested module is not configured and
      invalid reference
      .modules.ModulesServicePb.ModulesServiceError.ErrorCode#INVALID_VERSION_VALUE
      if the requested version is not configured and
      invalid reference
      .modules.ModulesServicePb.ModulesServiceError.ErrorCode#INVALID_INSTANCES_VALUE
      if the requested instance is not configured.
    • getModuleState

      public ModulesController.ModuleState getModuleState(String moduleName) throws com.google.apphosting.api.ApiProxy.ApplicationException
      Description copied from interface: ModulesController
      Returns the current state of this module.
      Specified by:
      getModuleState in interface ModulesController
      Throws:
      com.google.apphosting.api.ApiProxy.ApplicationException - with error code
      invalid reference
      .modules.ModulesServicePb.ModulesServiceError.ErrorCode#INVALID_MODULE_VALUE
      if the requested module is not configured
    • getScalingType

      public String getScalingType(String moduleName) throws com.google.apphosting.api.ApiProxy.ApplicationException
      Description copied from interface: ModulesController
      Returns the type of scaling in use for this module.
      Specified by:
      getScalingType in interface ModulesController
      Throws:
      com.google.apphosting.api.ApiProxy.ApplicationException - with error code
      invalid reference
      .modules.ModulesServicePb.ModulesServiceError.ErrorCode#INVALID_MODULE_VALUE
      if the requested module is not configured
    • startModule

      public void startModule(String moduleName, String version) throws com.google.apphosting.api.ApiProxy.ApplicationException
      Description copied from interface: ModulesController
      Starts the requested module version.
      Specified by:
      startModule in interface ModulesController
      Throws:
      com.google.apphosting.api.ApiProxy.ApplicationException -
      invalid reference
      .modules.ModulesServicePb.ModulesServiceError.ErrorCode#INVALID_MODULE_VALUE
      if the requested module is not a configured manual scaling module and .ErrorCode#INVALID_VERSION_VALUE if the requested version is not configured or is not a manual scaling module and .ModulesServiceError.ErrorCode#UNEXPECTED_STATE if the module instance is not stopped and ready to be started.
    • stopModule

      public void stopModule(String moduleName, String version) throws com.google.apphosting.api.ApiProxy.ApplicationException
      Description copied from interface: ModulesController
      Stops the requested module version.
      Specified by:
      stopModule in interface ModulesController
      Throws:
      com.google.apphosting.api.ApiProxy.ApplicationException -
      invalid reference
      .modules.ModulesServicePb.ModulesServiceError.ErrorCode#INVALID_MODULE_VALUE
      if the requested module is not a configured manual scaling module and .ModulesServiceError.ErrorCode#INVALID_VERSION_VALUE if the requested version is not configured or is not a manual scaling module and .ErrorCode#UNEXPECTED_STATE if the module instance is not running and ready to be stopped.
    • acquireServingPermit

      public boolean acquireServingPermit(String moduleName, int instanceNumber, boolean allowQueueOnBackends)
      Description copied from interface: ModulesFilterHelper
      This method guards access to module instances to limit the number of concurrent requests. Each request running on a module instance must acquire a serving permit. If no permits are available a 500 response should be sent.
      Specified by:
      acquireServingPermit in interface ModulesFilterHelper
      Parameters:
      moduleName - The module or backend 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 moduleName)
      Description copied from interface: ModulesFilterHelper
      Acquires a serving permit for an instance with available capacity and returns the instance id. If no instance has capacity this returns -1.

      For backends which support queued requests this may block for a limited time waiting for an instance to become available (see

      invalid reference
      AbstractBackendServers#getAndReserveFreeInstance
      for details). Supported for modules that support load balancing (currently ManualModule). The client can check with ModulesFilterHelper.isLoadBalancingInstance(String, int).
      Specified by:
      getAndReserveFreeInstance in interface ModulesFilterHelper
      Parameters:
      moduleName - Name of the requested module or backend.
      Returns:
      the instance id of an available server instance, or -1 if no instance is available.
    • returnServingPermit

      public void returnServingPermit(String moduleName, int instance)
      Description copied from interface: ModulesFilterHelper
      Returns a serving permit after a request has completed.
      Specified by:
      returnServingPermit in interface ModulesFilterHelper
      Parameters:
      moduleName - The server name
      instance - The server instance
    • checkInstanceExists

      public boolean checkInstanceExists(String moduleName, int instance)
      Description copied from interface: ModulesFilterHelper
      Verifies if a specific module instance is configured.
      Specified by:
      checkInstanceExists in interface ModulesFilterHelper
      Parameters:
      moduleName - The module or backend name
      instance - The module instance
      Returns:
      true if the module instance is configured and false otherwise.
    • checkModuleExists

      public boolean checkModuleExists(String moduleName)
      Description copied from interface: ModulesFilterHelper
      Verifies if a specific module or backend is configured.
      Specified by:
      checkModuleExists in interface ModulesFilterHelper
      Parameters:
      moduleName - The module or backend name
      Returns:
      true if the module is configured and false otherwise.
    • checkModuleStopped

      public boolean checkModuleStopped(String serverName)
      Description copied from interface: ModulesFilterHelper
      Verifies if a specific existing module or backend is stopped.
      Specified by:
      checkModuleStopped in interface ModulesFilterHelper
      Parameters:
      serverName - The module or backend name
      Returns:
      true if the module is stopped, false otherwise.
    • checkInstanceStopped

      public boolean checkInstanceStopped(String moduleName, int instance)
      Description copied from interface: ModulesFilterHelper
      Verifies if a specific existing module or backend instance is stopped.
      Specified by:
      checkInstanceStopped in interface ModulesFilterHelper
      Parameters:
      moduleName - The module or backedn name
      instance - The module instance
      Returns:
      true if the module instance is stopped and false otherwise.
    • isLoadBalancingInstance

      public boolean isLoadBalancingInstance(String moduleName, int instance)
      Description copied from interface: ModulesFilterHelper
      Returns true if the specified module or backend instance is a load balancing instance which will forward requests to an available instance.
      Specified by:
      isLoadBalancingInstance in interface ModulesFilterHelper
      Parameters:
      moduleName - The module or backend name
      instance - The requested instance which can be -1.
    • expectsGeneratedStartRequests

      public boolean expectsGeneratedStartRequests(String moduleName, int instance)
      Description copied from interface: ModulesFilterHelper
      Returns true if internally generated "/_ah/start" requests are provided for the specified module or backend instance.

      Http "/_ah/start" requests for instances where this returns true are presumed to be internally generated and receive special treatment by DevAppServerModulesFilter. Requests to "/_ah/start" for other instances are treated as normal requests.

      Specified by:
      expectsGeneratedStartRequests in interface ModulesFilterHelper
      Parameters:
      moduleName - The module or backend name
      instance - The module instance which can be -1.
    • getPort

      public int getPort(String moduleName, int instance)
      Description copied from interface: ModulesFilterHelper
      Returns the port for the specified module of backend instance.
      Specified by:
      getPort in interface ModulesFilterHelper
      Parameters:
      moduleName - The module or backend name
      instance - The requested instance which can be -1.