Skip to content

Add method Observation.observe(Function<C extends Observation.Context, T> function) #3537

@artembilan

Description

@artembilan

I have a use-case where I need to do ResponseContext.setResponse() after performing request-reply and withing an Observation scope.
So, to achieve that I have to do something like this:

		RequestReplyReceiverContext context = new MyCtx();

		return ObservationDoc.PROCESS.observation(this.observationConvention,
						DefaultConvention.INSTANCE,
						() -> context, this.observationRegistry)
				.observe(() -> {
					Message<?> reply = requestReply();
					context.setResponse(reply);
					return reply;
				});

This way I have to be sure about an ObservationRegistry.NOOP before calling this code.
With an Observation.observe(Function<C extends Observation.Context, T> function) API it would look like this:

		return ObservationDoc.PROCESS.observation(this.observationConvention,
						DefaultConvention.INSTANCE,
						() -> new MyCtx(), this.observationRegistry)
				.observe((context) -> {
					Message<?> reply = requestReply();
					context.setResponse(reply);
					return reply;
				});

and no any extra if...else around!

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy