Class GrpcController

java.lang.Object
org.pipservices4.grpc.controllers.GrpcController
All Implemented Interfaces:
org.pipservices4.components.config.IConfigurable, org.pipservices4.components.refer.IReferenceable, org.pipservices4.components.refer.IUnreferenceable, org.pipservices4.components.run.IClosable, org.pipservices4.components.run.IOpenable, IRegisterable
Direct Known Subclasses:
CommandableGrpcController

public abstract class GrpcController extends Object implements org.pipservices4.components.run.IOpenable, org.pipservices4.components.config.IConfigurable, org.pipservices4.components.refer.IReferenceable, org.pipservices4.components.refer.IUnreferenceable, IRegisterable
Used for creating GRPC endpoints. An endpoint is a URL, at which a given service can be accessed by a client.

### Configuration parameters ###

Parameters to pass to the configure(org.pipservices4.components.config.ConfigParams) method for component configuration:

 - dependencies:
   - endpoint:              override for GRPC Endpoint dependency
   - controller:            override for Controller dependency
 - connection(s):
   - discovery_key:         (optional) a key to retrieve the connection from IDiscovery
   - protocol:              connection protocol: http or https
   - host:                  host name or IP address
   - port:                  port number
   - uri:                   resource URI or connection string with all parameters in it
 - credential - the HTTPS credentials:
   - ssl_key_file:         the SSL private key in PEM
   - ssl_crt_file:         the SSL certificate in PEM
   - ssl_ca_file:          the certificate authorities (root cerfiticates) in PEM
 

### References ###

A logger, counters, and a connection resolver can be referenced by passing the following references to the object's setReferences(org.pipservices4.components.refer.IReferences) method:

- *:logger:*:*:1.0 (optional) ILogger components to pass log messages - *:counters:*:*:1.0 (optional) ICounters components to pass collected measurements - *:discovery:*:*:1.0 (optional) IDiscovery services to resolve connection - *:endpoint:grpc:*:1.0 (optional) GrpcEndpoint reference

See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected org.pipservices4.observability.count.CompositeCounters
    The performance counters.
    protected org.pipservices4.components.refer.DependencyResolver
    The dependency resolver.
    protected GrpcEndpoint
    The GRPC endpoint that exposes this service.
    protected org.pipservices4.observability.log.CompositeLogger
    The logger.
    protected org.pipservices4.observability.trace.CompositeTracer
    The tracer.
  • Constructor Summary

    Constructors
    Constructor
    Description
    GrpcController(io.grpc.ServiceDescriptor serviceDescriptor)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    close(org.pipservices4.components.context.IContext context)
    Closes component and frees used resources.
    void
    configure(org.pipservices4.components.config.ConfigParams config)
    Configures component by passing configuration parameters.
    protected org.pipservices4.rpc.trace.InstrumentTiming
    instrument(org.pipservices4.components.context.IContext context, String name)
    Adds instrumentation to log calls and measure call time.
    boolean
    Checks if the component is opened.
    void
    open(org.pipservices4.components.context.IContext context)
    Opens the component.
    abstract void
    Registers all service routes in Grpc endpoint.
    protected void
    Registers a middleware for methods in GRPC endpoint.
    protected <TRequest extends com.google.protobuf.GeneratedMessageV3, TResponse extends com.google.protobuf.GeneratedMessageV3>
    void
    registerMethod(String name, org.pipservices4.data.validate.Schema schema, GrpcFunc<TRequest,io.grpc.stub.StreamObserver<TResponse>> action)
    Registers a method in GRPC service.
    void
    setReferences(org.pipservices4.components.refer.IReferences references)
    Sets references to dependent components.
    void
    Unsets (clears) previously set references to dependent components.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • _endpoint

      protected GrpcEndpoint _endpoint
      The GRPC endpoint that exposes this service.
    • _dependencyResolver

      protected org.pipservices4.components.refer.DependencyResolver _dependencyResolver
      The dependency resolver.
    • _logger

      protected org.pipservices4.observability.log.CompositeLogger _logger
      The logger.
    • _counters

      protected org.pipservices4.observability.count.CompositeCounters _counters
      The performance counters.
    • _tracer

      protected org.pipservices4.observability.trace.CompositeTracer _tracer
      The tracer.
  • Constructor Details

    • GrpcController

      public GrpcController(io.grpc.ServiceDescriptor serviceDescriptor)
  • Method Details

    • configure

      public void configure(org.pipservices4.components.config.ConfigParams config) throws org.pipservices4.commons.errors.ConfigException
      Configures component by passing configuration parameters.
      Specified by:
      configure in interface org.pipservices4.components.config.IConfigurable
      Parameters:
      config - configuration parameters to be set.hnnhhjjnnmmkkkjjhhujnmjjhhhhhh
      Throws:
      org.pipservices4.commons.errors.ConfigException
    • setReferences

      public void setReferences(org.pipservices4.components.refer.IReferences references) throws org.pipservices4.components.refer.ReferenceException, org.pipservices4.commons.errors.ConfigException
      Sets references to dependent components.
      Specified by:
      setReferences in interface org.pipservices4.components.refer.IReferenceable
      Parameters:
      references - references to locate the component dependencies.
      Throws:
      org.pipservices4.components.refer.ReferenceException
      org.pipservices4.commons.errors.ConfigException
    • unsetReferences

      public void unsetReferences()
      Unsets (clears) previously set references to dependent components.
      Specified by:
      unsetReferences in interface org.pipservices4.components.refer.IUnreferenceable
    • instrument

      protected org.pipservices4.rpc.trace.InstrumentTiming instrument(org.pipservices4.components.context.IContext context, String name)
      Adds instrumentation to log calls and measure call time. It returns a Timing object that is used to end the time measurement.
      Parameters:
      context - (optional) a context to trace execution through call chain.
      name - a method name.
      Returns:
      Timing object to end the time measurement.
    • isOpen

      public boolean isOpen()
      Checks if the component is opened.
      Specified by:
      isOpen in interface org.pipservices4.components.run.IOpenable
      Returns:
      true if the component has been opened and false otherwise.
    • open

      public void open(org.pipservices4.components.context.IContext context) throws org.pipservices4.commons.errors.ApplicationException
      Opens the component.
      Specified by:
      open in interface org.pipservices4.components.run.IOpenable
      Parameters:
      context - (optional) a context to trace execution through call chain.
      Throws:
      org.pipservices4.commons.errors.ApplicationException
    • close

      public void close(org.pipservices4.components.context.IContext context) throws org.pipservices4.commons.errors.InvalidStateException
      Closes component and frees used resources.
      Specified by:
      close in interface org.pipservices4.components.run.IClosable
      Parameters:
      context - (optional) a context to trace execution through call chain.
      Throws:
      org.pipservices4.commons.errors.InvalidStateException
    • registerInterceptor

      protected void registerInterceptor(InterceptorFunc action)
      Registers a middleware for methods in GRPC endpoint.
      Parameters:
      action - an action function that is called when middleware is invoked.
    • registerMethod

      protected <TRequest extends com.google.protobuf.GeneratedMessageV3, TResponse extends com.google.protobuf.GeneratedMessageV3> void registerMethod(String name, org.pipservices4.data.validate.Schema schema, GrpcFunc<TRequest,io.grpc.stub.StreamObserver<TResponse>> action)
      Registers a method in GRPC service.
      Parameters:
      name - a method name
      schema - a validation schema to validate received parameters.
      action - an action function that is called when operation is invoked.
    • register

      public abstract void register()
      Registers all service routes in Grpc endpoint.

      This method is called by the service and must be overriden in child classes.

      Specified by:
      register in interface IRegisterable