Interface Policy

    • Method Detail

      • id

        String id()
        The id of the policy (usually the same id as defined in the policy manifest)
        Returns:
        the id of the policy.
      • onRequest

        default io.reactivex.Completable onRequest​(RequestExecutionContext ctx)
        Define the actions to perform during the ExecutionPhase.REQUEST phase. The onRequest(RequestExecutionContext) method will be called during the policy chain construction. Once built, the subscription occurs and the execution is triggered. It is important that nothing must be executed before the subscription occurs as it could lead to important side effects.

        GOOD, the header is added during the execution, at subscription time.
             Completable onRequest(final RequestExecutionContext ctx) {
                 return Completable.fromRunnable(() -> request.headers().set("X-DummyHeader", "dummy"));
             }
         
        BAD, the header is added during the build of the policy chain.
             Completable onRequest(final RequestExecutionContext ctx) {
                 request.headers().set("X-DummyHeader", "dummy");
                 return Completable.complete();
             }
         
        Parameters:
        ctx - the current request execution context allowing to access the request, response and attributes.
        Returns:
        a Completable that must complete when all the actions have been performed.
      • onResponse

        default io.reactivex.Completable onResponse​(RequestExecutionContext ctx)
        Define the actions to perform during the ExecutionPhase.RESPONSE phase. The onResponse(RequestExecutionContext) method will be called during the policy chain construction. Once built, the subscription occurs and the execution is triggered. It is important that nothing must be executed before the subscription occurs as it could lead to important side effects.

        GOOD, the header is added during the execution, at subscription time.
             Completable onResponse(final RequestExecutionContext ctx) {
                 return Completable.fromRunnable(() -> response.headers().set("X-DummyHeader", "dummy"));
             }
         
        BAD, the header is added during the build of the policy chain.
             Completable onResponse(final RequestExecutionContext ctx) {
                 response.headers().set("X-DummyHeader", "dummy");
                 return Completable.complete();
             }
         
        Parameters:
        ctx - the current request execution context allowing to access the request, response and attributes.
        Returns:
        a Completable that must complete when all the actions have been performed.
      • onMessage

        default io.reactivex.Maybe<Message> onMessage​(ExecutionContext ctx,
                                                      Message message)
        Defines the actions to perform during on each incoming Message.
        Parameters:
        ctx - the current execution context allowing to access context attributes.
        Returns:
        a Maybe that must complete when all the actions have been performed on the message. The message can be simply dropped by returning Maybe.empty().
      • onMessageFlow

        default io.reactivex.Flowable<Message> onMessageFlow​(ExecutionContext ctx,
                                                             io.reactivex.Flowable<Message> messageFlow)
        Defines the actions to perform on the message flow itself.
        Parameters:
        ctx - the current execution context allowing to access context attributes.
        Returns:
        a Flowable of Message.