Versions Compared

Key

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

...

  1. Ability to pass custom context from caller to service (similar to HTTP request headers).
  2. Ability to define custom interceptors for service calls.

Suggested design

...

Entities

  1. RequestContext - shareable map with service method call implicit parameters.
  2. Interceptor - executes before call service method.
  3. Listener - called after service method

API (draft)

Code Block
languagejava
themeConfluence
titleInterceptor
linenumberstrue
/**
 * Service method call interceptor.
 */
public interface ServiceCallInterceptor {
    /**
     * Invokes before service method invocation.
     *
     * @param mtdName Method name.
     * @param args Method arguments.
     * @param ctx Service request context.
     * @return Listener of the call result or {@code null}.
     */
    public @Nullable ServiceCallListener intercept(String mtdName, Object[] args, Map<String, Object>ServiceRequestContext ctx);
}


Code Block
languagejava
themeConfluence
titleListener
linenumberstrue
/**
 * Listener of the service method invocation.
 */
public interface ServiceCallListener {
    /**
     *
     * @param res Service method call result, if any.
     * @param t Error, if any.
     */
    public void onComplete(@Nullable Object res, @Nullable Throwable t);
}

Implementation requirements/limitations

  • All specified interceptors are guaranteed to be executed before calling the service method.
  • Listeners are notified asynchronously.
  • The server interceptor binds to the service itself (it must be executed where the service is implemented, if on Java then in Java, if on Net then in Net).
  • The client interceptor binds to the proxy invocation handler. In fact, the main task of the client interceptor is to transfer the parameters of the caller to the service instance (using the RequestContext).
  • If the interceptor throws an exception, the service method is not executed, but the rest of the interceptors this exception is passed to the user and to the listeners.
  • Any interceptor can change the RequestContext.
  • RequestContext must be accessible inside the service(?).

Risks and Assumptions

// Describe project risks, such as API or binary compatibility issues, major protocol changes, etc.

...