Interface ServiceCallContext


  • public interface ServiceCallContext
    Service call context.

    This context is implicitly passed to the service and can be retrieved inside the service using ServiceContext.currentCallContext(). It is accessible only from the local thread during the execution of a service method.

    Use builder() to create the context builder.

    Note: passing the context to the service may lead to performance overhead, so it should only be used for "middleware" tasks.

    Usage example:

    
     // Service implementation.
     class HelloServiceImpl implements HelloService {
         @ServiceContextResource
         ServiceContext ctx;
    
         public String call(Strig msg) {
             return msg + ctx.currentCallContext().attribute("user");
         }
         ...
     }
     ...
    
     // Call this service with context.
     ServiceCallContext callCtx = ServiceCallContext.builder().put("user", "John").build();
     HelloService helloSvc = ignite.services().serviceProxy("hello-service", HelloService.class, false, callCtx, 0);
     // Print "Hello John".
     System.out.println( helloSvc.call("Hello ") );
     
    See Also:
    ServiceContext, ServiceCallContextBuilder, ServiceCallInterceptor
    • Method Detail

      • attribute

        String attribute​(String name)
        Get the string attribute.
        Parameters:
        name - Attribute name.
        Returns:
        String attribute value.
      • binaryAttribute

        byte[] binaryAttribute​(String name)
        Get the binary attribute.
        Parameters:
        name - Attribute name.
        Returns:
        Binary attribute value.