org.eclipse.ditto.model.base.headers.WithDittoHeaders类的使用及代码示例

x33g5p2x  于2022-02-03 转载在 其他  
字(11.0k)|赞(0)|评价(0)|浏览(169)

本文整理了Java中org.eclipse.ditto.model.base.headers.WithDittoHeaders类的一些代码示例,展示了WithDittoHeaders类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。WithDittoHeaders类的具体详情如下:
包路径:org.eclipse.ditto.model.base.headers.WithDittoHeaders
类名称:WithDittoHeaders

WithDittoHeaders介绍

[英]Common interface for all classes which have DittoHeaders available.
[中]所有具有DittoHeader可用的类的公共接口。

代码示例

代码示例来源:origin: eclipse/ditto

  1. private static DittoHeaders getDittoHeadersOrEmpty(final Object object) {
  2. if (object instanceof WithDittoHeaders) {
  3. @Nullable final DittoHeaders dittoHeaders = ((WithDittoHeaders) object).getDittoHeaders();
  4. if (null != dittoHeaders) {
  5. return dittoHeaders;
  6. }
  7. LOG.warn("Object <{}> did not contain DittoHeaders although it should! Using empty DittoHeaders instead.",
  8. object);
  9. }
  10. return DittoHeaders.empty();
  11. }

代码示例来源:origin: eclipse/ditto

  1. private WithDittoHeaders appendETagHeader(final C command, final WithDittoHeaders response) {
  2. final DittoHeaders dittoHeaders = response.getDittoHeaders();
  3. final Optional<EntityTag> entityTagOpt = determineETagEntity(command)
  4. .flatMap(EntityTag::fromEntity);
  5. if (entityTagOpt.isPresent()) {
  6. final DittoHeaders newDittoHeaders = dittoHeaders.toBuilder().eTag(entityTagOpt.get()).build();
  7. return response.setDittoHeaders(newDittoHeaders);
  8. }
  9. return response;
  10. }

代码示例来源:origin: eclipse/ditto

  1. replyToSender(withDittoHeaders.setDittoHeaders(retrieveThing.getDittoHeaders()), sender);
  2. } else if (isAskTimeoutException(response, error)) {
  3. reportThingUnavailable(retrieveThing.getThingId(), retrieveThing.getDittoHeaders(), sender);

代码示例来源:origin: org.eclipse.ditto/ditto-services-utils-akka

  1. /**
  2. * Enhances the MDC around the passed SLF4J {@code Logger} with the {@code correlation-id} extracted from the passed
  3. * {@code withDittoHeaders}. Invokes the passed in {@code logConsumer} around the MDC setting/removing.
  4. *
  5. * @param slf4jLogger the SLF4J logger to log with.
  6. * @param withDittoHeaders where to extract a possible correlationId from.
  7. * @param logConsumer the consumer with which the caller must log.
  8. */
  9. public static void logWithCorrelationId(final Logger slf4jLogger, final WithDittoHeaders<?> withDittoHeaders,
  10. final Consumer<Logger> logConsumer) {
  11. logWithCorrelationId(slf4jLogger, withDittoHeaders.getDittoHeaders(), logConsumer);
  12. }

代码示例来源:origin: org.eclipse.ditto/ditto-services-policies-persistence

  1. private WithDittoHeaders appendETagHeader(final C command, final WithDittoHeaders response) {
  2. final DittoHeaders dittoHeaders = response.getDittoHeaders();
  3. final Optional<EntityTag> entityTagOpt = determineETagEntity(command)
  4. .flatMap(EntityTag::fromEntity);
  5. if (entityTagOpt.isPresent()) {
  6. final DittoHeaders newDittoHeaders = dittoHeaders.toBuilder().eTag(entityTagOpt.get()).build();
  7. return response.setDittoHeaders(newDittoHeaders);
  8. }
  9. return response;
  10. }

代码示例来源:origin: org.eclipse.ditto/ditto-services-utils-cluster

  1. private static DittoHeaders getDittoHeadersOrEmpty(final Object object) {
  2. if (object instanceof WithDittoHeaders) {
  3. @Nullable final DittoHeaders dittoHeaders = ((WithDittoHeaders) object).getDittoHeaders();
  4. if (null != dittoHeaders) {
  5. return dittoHeaders;
  6. }
  7. LOG.warn("Object <{}> did not contain DittoHeaders although it should! Using empty DittoHeaders instead.",
  8. object);
  9. }
  10. return DittoHeaders.empty();
  11. }

代码示例来源:origin: eclipse/ditto

  1. private static <C extends Command, E> WithDittoHeaders appendETagHeaderIfProvided(final C command,
  2. final WithDittoHeaders withDittoHeaders, @Nullable final Thing thing,
  3. @Nullable final ETagEntityProvider<C, E> eTagProvider) {
  4. if (eTagProvider == null) {
  5. return withDittoHeaders;
  6. }
  7. final Optional<E> eTagEntityOpt = eTagProvider.determineETagEntity(command, thing);
  8. if (eTagEntityOpt.isPresent()) {
  9. final Optional<EntityTag> entityTagOpt = EntityTag.fromEntity(eTagEntityOpt.get());
  10. if (entityTagOpt.isPresent()) {
  11. final EntityTag entityTag = entityTagOpt.get();
  12. final DittoHeaders newDittoHeaders = withDittoHeaders.getDittoHeaders().toBuilder()
  13. .eTag(entityTag)
  14. .build();
  15. return withDittoHeaders.setDittoHeaders(newDittoHeaders);
  16. }
  17. }
  18. return withDittoHeaders;
  19. }

代码示例来源:origin: eclipse/ditto

  1. /**
  2. * Enhances the MDC around the passed SLF4J {@code Logger} with the {@code correlation-id} extracted from the passed
  3. * {@code withDittoHeaders}. Invokes the passed in {@code logConsumer} around the MDC setting/removing.
  4. *
  5. * @param slf4jLogger the SLF4J logger to log with.
  6. * @param withDittoHeaders where to extract a possible correlationId from.
  7. * @param additionalMdcFields additional fields which should bet set to the MDC.
  8. * @param logConsumer the consumer with which the caller must log.
  9. */
  10. public static void logWithCorrelationId(final Logger slf4jLogger, final WithDittoHeaders<?> withDittoHeaders,
  11. final Map<String, String> additionalMdcFields, final Consumer<Logger> logConsumer) {
  12. logWithCorrelationId(slf4jLogger, withDittoHeaders.getDittoHeaders(), additionalMdcFields, logConsumer);
  13. }

代码示例来源:origin: org.eclipse.ditto/ditto-services-things-persistence

  1. private static <C extends Command, E> WithDittoHeaders appendETagHeaderIfProvided(final C command,
  2. final WithDittoHeaders withDittoHeaders, @Nullable final Thing thing,
  3. @Nullable final ETagEntityProvider<C, E> eTagProvider) {
  4. if (eTagProvider == null) {
  5. return withDittoHeaders;
  6. }
  7. final Optional<E> eTagEntityOpt = eTagProvider.determineETagEntity(command, thing);
  8. if (eTagEntityOpt.isPresent()) {
  9. final Optional<EntityTag> entityTagOpt = EntityTag.fromEntity(eTagEntityOpt.get());
  10. if (entityTagOpt.isPresent()) {
  11. final EntityTag entityTag = entityTagOpt.get();
  12. final DittoHeaders newDittoHeaders = withDittoHeaders.getDittoHeaders().toBuilder()
  13. .eTag(entityTag)
  14. .build();
  15. return withDittoHeaders.setDittoHeaders(newDittoHeaders);
  16. }
  17. }
  18. return withDittoHeaders;
  19. }

代码示例来源:origin: eclipse/ditto

  1. private Jsonifiable.WithPredicate<JsonObject, JsonField> publishResponsePublishedEvent(
  2. final Jsonifiable.WithPredicate<JsonObject, JsonField> jsonifiable) {
  3. if (jsonifiable instanceof CommandResponse) {
  4. // only create ResponsePublished for CommandResponses, not for Events with the same correlationId
  5. ((WithDittoHeaders) jsonifiable).getDittoHeaders()
  6. .getCorrelationId()
  7. .map(ResponsePublished::new)
  8. .ifPresent(eventStream::publish);
  9. }
  10. return jsonifiable;
  11. }

代码示例来源:origin: eclipse/ditto

  1. /**
  2. * @param withPotentialDittoHeaders the object which potentially contains DittoHeaders from which a
  3. * {@code correlation-id} can be extracted in order to enhance the returned DiagnosticLoggingAdapter
  4. * @return the diagnostic logging adapter.
  5. */
  6. protected DiagnosticLoggingAdapter log(final Object withPotentialDittoHeaders) {
  7. if (withPotentialDittoHeaders instanceof WithDittoHeaders) {
  8. return log(((WithDittoHeaders<?>) withPotentialDittoHeaders).getDittoHeaders());
  9. }
  10. return context.log;
  11. }

代码示例来源:origin: eclipse/ditto

  1. /**
  2. * Enhances the default slf4j {@link org.slf4j.MDC} with a {@code correlationId} of the passed
  3. * {@code withDittoHeaders} (if present), else a random correlation id.
  4. *
  5. * @param withDittoHeaders where to extract a possible correlationId from.
  6. */
  7. public static void enhanceLogWithCorrelationIdOrRandom(final WithDittoHeaders<?> withDittoHeaders) {
  8. LogUtil.enhanceLogWithCorrelationIdOrRandom(withDittoHeaders.getDittoHeaders());
  9. }

代码示例来源:origin: eclipse/ditto

  1. /**
  2. * Enhances the MDC around the passed SLF4J {@code Logger} with the {@code correlation-id} extracted from the passed
  3. * {@code withDittoHeaders}. Invokes the passed in {@code logConsumer} around the MDC setting/removing.
  4. *
  5. * @param slf4jLogger the SLF4J logger to log with.
  6. * @param withDittoHeaders where to extract a possible correlationId from.
  7. * @param logConsumer the consumer with which the caller must log.
  8. */
  9. public static void logWithCorrelationId(final Logger slf4jLogger, final WithDittoHeaders<?> withDittoHeaders,
  10. final Consumer<Logger> logConsumer) {
  11. logWithCorrelationId(slf4jLogger, withDittoHeaders.getDittoHeaders(), logConsumer);
  12. }

代码示例来源:origin: eclipse/ditto

  1. /**
  2. * Enhances the default slf4j {@link org.slf4j.MDC} with a {@code correlationId} of the passed
  3. * {@code withDittoHeaders} (if present).
  4. *
  5. * @param withDittoHeaders where to extract a possible correlationId from.
  6. */
  7. public static void enhanceLogWithCorrelationId(final WithDittoHeaders<?> withDittoHeaders) {
  8. withDittoHeaders.getDittoHeaders()
  9. .getCorrelationId()
  10. .ifPresent(LogUtil::enhanceLogWithCorrelationId);
  11. }

代码示例来源:origin: org.eclipse.ditto/ditto-services-utils-akka

  1. /**
  2. * Enhances the MDC around the passed SLF4J {@code Logger} with the {@code correlation-id} extracted from the passed
  3. * {@code withDittoHeaders}. Invokes the passed in {@code logConsumer} around the MDC setting/removing.
  4. *
  5. * @param slf4jLogger the SLF4J logger to log with.
  6. * @param withDittoHeaders where to extract a possible correlationId from.
  7. * @param additionalMdcFields additional fields which should bet set to the MDC.
  8. * @param logConsumer the consumer with which the caller must log.
  9. */
  10. public static void logWithCorrelationId(final Logger slf4jLogger, final WithDittoHeaders<?> withDittoHeaders,
  11. final Map<String, String> additionalMdcFields, final Consumer<Logger> logConsumer) {
  12. logWithCorrelationId(slf4jLogger, withDittoHeaders.getDittoHeaders(), additionalMdcFields, logConsumer);
  13. }

代码示例来源:origin: eclipse/ditto

  1. /**
  2. * Substitutes all placeholders contained in the {@code input} based on the {@link DittoHeaders} contained in
  3. * {@code withDittoHeaders}.
  4. *
  5. * @param input the input.
  6. * @param withDittoHeaders the instance of {@link WithDittoHeaders}, from which the headers are extracted
  7. * (normally a command).
  8. * @return the replaced input, if the input contains placeholders; the (same) input object, if no placeholders
  9. * were contained in the input.
  10. */
  11. public String substitute(final String input, final WithDittoHeaders withDittoHeaders) {
  12. requireNonNull(input);
  13. requireNonNull(withDittoHeaders);
  14. return substitute(input, withDittoHeaders.getDittoHeaders());
  15. }

代码示例来源:origin: org.eclipse.ditto/ditto-services-connectivity-messaging

  1. private void finishTrace(final WithDittoHeaders<? extends Signal> response, @Nullable final Throwable cause) {
  2. response.getDittoHeaders().getCorrelationId().ifPresent(correlationId -> {
  3. try {
  4. finishTrace(correlationId, cause);
  5. } catch (final IllegalArgumentException e) {
  6. log.debug("Trace missing for response: '{}'", response);
  7. }
  8. });
  9. }

代码示例来源:origin: eclipse/ditto

  1. private void finishTrace(final WithDittoHeaders<? extends Signal> response, @Nullable final Throwable cause) {
  2. response.getDittoHeaders().getCorrelationId().ifPresent(correlationId -> {
  3. try {
  4. finishTrace(correlationId, cause);
  5. } catch (final IllegalArgumentException e) {
  6. log.debug("Trace missing for response: '{}'", response);
  7. }
  8. });
  9. }

代码示例来源:origin: org.eclipse.ditto/ditto-services-things-persistence

  1. @Override
  2. protected void doApply(final Object message) {
  3. log.debug("Unexpected message after initialization of actor received: {} - "
  4. + "Terminating this actor and sending <{}> to requester ...", message,
  5. ThingNotAccessibleException.class.getName());
  6. final ThingNotAccessibleException.Builder builder = ThingNotAccessibleException.newBuilder(thingId);
  7. if (message instanceof WithDittoHeaders) {
  8. builder.dittoHeaders(((WithDittoHeaders) message).getDittoHeaders());
  9. }
  10. notifySender(builder.build());
  11. scheduleCheckForThingActivity(activityCheckInterval.getSeconds());
  12. }

代码示例来源:origin: eclipse/ditto

  1. @Override
  2. protected void doApply(final Object message) {
  3. log.debug("Unexpected message after initialization of actor received: {} - "
  4. + "Terminating this actor and sending <{}> to requester ...", message,
  5. ThingNotAccessibleException.class.getName());
  6. final ThingNotAccessibleException.Builder builder = ThingNotAccessibleException.newBuilder(thingId);
  7. if (message instanceof WithDittoHeaders) {
  8. builder.dittoHeaders(((WithDittoHeaders) message).getDittoHeaders());
  9. }
  10. notifySender(builder.build());
  11. scheduleCheckForThingActivity(activityCheckInterval.getSeconds());
  12. }

相关文章