Interface ServiceNaming

Functional Interface:
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

@FunctionalInterface public interface ServiceNaming
Generates the default name of a Service from its ServiceRequestContext.
See Also:
  • Method Details

    • of

      static ServiceNaming of(String defaultServiceName)
      Returns the ServiceNaming that always returns the given hard-coded service name.
    • fullTypeName

      static ServiceNaming fullTypeName()
      Returns the ServiceNaming that returns the full name of an RPC stub class or the innermost class from the given service. It will be fully qualified name including the package name separated by a period. e.g. com.foo.HelloService.
      See Also:
    • simpleTypeName

      static ServiceNaming simpleTypeName()
      Returns the ServiceNaming that returns the simple name of an RPC stub class or the innermost class from the given service. It is supposed to have a class name without a period. e.g. HelloService.
    • shorten

      static ServiceNaming shorten(int targetLength)
      Returns the ServiceNaming that returns the shortened service name from the full name of an RPC stub class or the innermost class from the given service. It follows Logback's abbreviation algorithm. Please note that the rightmost segment in a service name is never abbreviated. For instance, com.foo.bar.HelloService is able to be shorten to c.f.b.HelloService.
      See Also:
    • shorten

      static ServiceNaming shorten()
      Returns the ServiceNaming that returns the shortened service name from the full name of an RPC stub class or the innermost class from the given service. It follows Logback's abbreviation algorithm. Please note that the rightmost segment in a service name is only left and other segments are abbreviated to a letter. For instance, com.foo.bar.HelloService is able to be shorten to c.f.b.HelloService.
      See Also:
    • serviceName

      Converts the specified serviceName into another service name which is used as a meter tag or distributed trace's span name.

      If null is returned, one of the following values will be used instead:

      • gRPC - a service name (e.g, com.foo.GrpcService)
      • Thrift - a service type (e.g, com.foo.ThriftService$AsyncIface or com.foo.ThriftService$Iface)
      • HttpService and annotated service - an innermost class name

      A naming rule can be set by either ServerBuilder.defaultServiceNaming(ServiceNaming) or ServiceBindingBuilder.defaultServiceNaming(ServiceNaming). One of pre-defined naming rules is able to be used as follows.

      Example

      
       Server server = Server.builder()
                             .service(...)
                             .defaultServiceNaming(ServiceNaming.simpleTypeName())
                             .build()
       

      Example 2

      
       Server server = Server.builder()
                             .route().path("/")
                             .defaultServiceNaming(ServiceNaming.fullTypeName())
                             ...
                             .build()
       

      If customizing is needed out of given rules, a lambda expression would be applied as follows.

      
       Server server = Server.builder()
                             .service(...)
                             .defaultServiceNaming(ctx -> {
                                 final ServiceConfig config = ctx.config();
                                 return config.server().defaultHostname() + config.route().patternString();
                             })
                             .build()