Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

New entities:

  • ServiceCallContext -  immutable map of custom parameters to user parameter map that will be implicitly passed to the service (and interceptor) on every method call.

    Code Block
    languagejava
    themeRDark
    titleServiceCallContext.java
    linenumberstrue
    collapsetrue
    public interface ServiceCallContext {
        public String attribute(String name);
    
        public byte[] binaryAttribute(String name);
    }


  • ServiceCallInterceptor  - intercepts service method calls.

    Code Block
    languagejava
    themeRDark
    titleServiceCallInterceptor.java
    linenumberstrue
    collapsetrue
    public interface ServiceCallInterceptor extends Serializable {
        public default void onInvoke(ServiceInterceptorContext ctx) throws ServiceInterceptException {
            // No-op.
        }
    
        public default void onComplete(@Nullable Object res, ServiceInterceptorContext ctx) throws ServiceInterceptException {
            // No-op.
        }
    
        public default void onError(Throwable err, ServiceInterceptorContext ctx) {
            // No-op.
        }
    }


  • ServiceInterceptorContext -  extended mutable version of caller context (interceptor obtains method call parameters from it and can use it to update the caller context).

    Code Block
    languagejava
    themeRDark
    titleServiceInterceptorContext.java
    linenumberstrue
    collapsetrue
    public interface ServiceInterceptorContext extends ServiceCallContext {
        public String method();
    
        public @Nullable Object[] arguments();
    
        public void attribute(String name, String val);
    
        public void binaryAttribute(String name, byte[] val);
    }


  • ServiceInterceptException - unchecked exception that is used to highlight the exception that occurred during method interception (not execution).

...

Interceptor only applies to user-defined business methods and does not apply to service lifecycle methods - init, execute andcancel,

Call context

Interceptor can modify ServiceCallContext, but Service methods can only read it.

If an interceptor has been specified, but the user has not passed the caller context through the proxy, it will be created dynamically.

Deployment

One service can have several interceptors. They are defined using the service configuration and deployed with the service.

To add/remove interceptor - service should be redeployed.

Interceptor is located and executed where the service is implemented (for Java service - on Java side, for .NET-service on .NET side). Its execution should not cause additional serialization.To add/remove interceptor - service should be redeployed.

Resource injection and lifecycle

...

(question) Interceptor should support LifeCycleAware

Service call context

The user can create this context and bind it to the service proxy. After that, each call to the proxy method will also implicitly pass context parameters to the service.

Service method can read current context using ServiceContext#currentCallContext method. It is only accessible from the current thread during the execution of a service method.

Interceptor can read and update this parameters using ServiceInterceptorContext.

If an interceptor has been specified, but the user has not passed the caller context through the proxy, then for each call to the service method, an empty context will be dynamically created.

Exception handling

Interceptor can only throw unchecked exceptions.

...