Package com.google.api.server.spi
Class SystemService
- java.lang.Object
-
- com.google.api.server.spi.SystemService
-
public class SystemService extends Object
System service that execute service methods.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classSystemService.BuilderASystemServicebuilder which encapsulates common logic for building its dependencies.static classSystemService.EndpointNode
-
Field Summary
Fields Modifier and Type Field Description static intDUPLICATE_SERVICE_REGISTER_COUNTstatic StringMIME_JSON
-
Constructor Summary
Constructors Constructor Description SystemService(ApiConfigLoader configLoader, String appName, ApiConfigWriter configWriter, boolean isIllegalArgumentBackendError)Constructs aSystemServicewith no registered services.SystemService(ApiConfigLoader configLoader, String appName, ApiConfigWriter configWriter, Object[] services, boolean isIllegalArgumentBackendError)Constructs aSystemServiceand registers the provided services.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static SystemService.Builderbuilder()ObjectfindService(String name)Finds a service object with thenameMethodfindServiceMethod(Object service, String methodName)Finds a method object with the givenmethodNameon theserviceobject.Map<ApiKey,String>getApiConfigs()Generates wire-format configuration for all loaded APIs.com.google.common.collect.ImmutableList<SystemService.EndpointNode>getEndpoints()ApiSerializationConfiggetSerializationConfig(String serviceName)Gets the serialization configuration for the API corresponding to the named service.voidinvokeServiceMethod(Object service, Method method, ParamReader paramReader, ResultWriter resultWriter)Invokes amethodon aservicegiven aparamReaderto read parameters and aresultWriterto write result.intregisterService(Class<?> serviceClass, Object service)Registers a service class.intregisterService(Object service)EndpointMethodresolveService(String serviceName, String methodName)Finds a service object with theserviceNameornullif not found.<T> SystemService.EndpointNodeupdateEndpointConfig(T endpoint, ApiConfig newConfig, SystemService.EndpointNode oldNode)
-
-
-
Field Detail
-
MIME_JSON
public static final String MIME_JSON
- See Also:
- Constant Field Values
-
DUPLICATE_SERVICE_REGISTER_COUNT
public static final int DUPLICATE_SERVICE_REGISTER_COUNT
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
SystemService
public SystemService(ApiConfigLoader configLoader, String appName, ApiConfigWriter configWriter, Object[] services, boolean isIllegalArgumentBackendError) throws ApiConfigException
Constructs aSystemServiceand registers the provided services.- Parameters:
configLoader- The loader used to read annotation from service classesappName- The application's idservices- The service classes to be registered- Throws:
ApiConfigException
-
SystemService
public SystemService(ApiConfigLoader configLoader, String appName, ApiConfigWriter configWriter, boolean isIllegalArgumentBackendError) throws ApiConfigException
Constructs aSystemServicewith no registered services.- Parameters:
configLoader- The loader used to read annotation from service classesappName- The application's id- Throws:
ApiConfigException
-
-
Method Detail
-
registerService
public int registerService(Class<?> serviceClass, Object service) throws ApiConfigException
Registers a service class. Only public methods in this class and all its superclasses, except Object, are registered. Two methods are not allowed to have the same name. Registering a different service with an existing name is a no-op.- Parameters:
serviceClass- is the class to start parsing endpointsservice- Service object- Returns:
- number of service methods added, -1 on duplicate insertion
- Throws:
ApiConfigException
-
registerService
public int registerService(Object service) throws ApiConfigException
- Throws:
ApiConfigException
-
updateEndpointConfig
public <T> SystemService.EndpointNode updateEndpointConfig(T endpoint, ApiConfig newConfig, @Nullable SystemService.EndpointNode oldNode)
-
resolveService
public EndpointMethod resolveService(String serviceName, String methodName) throws ServiceException
Finds a service object with theserviceNameornullif not found.- Parameters:
serviceName- either a full class name or a simple name of a service objectmethodName- the method name of a service object- Throws:
ServiceException- when more than one service is mapped to the samenameor when the named service does not exist
-
getSerializationConfig
public ApiSerializationConfig getSerializationConfig(String serviceName)
Gets the serialization configuration for the API corresponding to the named service.
-
findService
public Object findService(String name) throws ServiceException
Finds a service object with thename- Throws:
ServiceException- when more than one service is mapped to the samenameor when the named service does not exist
-
findServiceMethod
public Method findServiceMethod(Object service, String methodName) throws ServiceException
Finds a method object with the givenmethodNameon theserviceobject.- Throws:
ServiceException- if method does not exist
-
invokeServiceMethod
public void invokeServiceMethod(Object service, Method method, ParamReader paramReader, ResultWriter resultWriter) throws IOException
Invokes amethodon aservicegiven aparamReaderto read parameters and aresultWriterto write result.- Throws:
IOException
-
getApiConfigs
public Map<ApiKey,String> getApiConfigs() throws ApiConfigException
Generates wire-format configuration for all loaded APIs.- Returns:
- A map from
ApiKeys to wire-formatted configuration strings. - Throws:
ApiConfigException
-
getEndpoints
public com.google.common.collect.ImmutableList<SystemService.EndpointNode> getEndpoints()
-
builder
public static SystemService.Builder builder()
-
-