本文整理了Java中org.eclipse.ditto.model.base.headers.WithDittoHeaders
类的一些代码示例,展示了WithDittoHeaders
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。WithDittoHeaders
类的具体详情如下:
包路径:org.eclipse.ditto.model.base.headers.WithDittoHeaders
类名称:WithDittoHeaders
[英]Common interface for all classes which have DittoHeaders available.
[中]所有具有DittoHeader可用的类的公共接口。
代码示例来源:origin: eclipse/ditto
private static DittoHeaders getDittoHeadersOrEmpty(final Object object) {
if (object instanceof WithDittoHeaders) {
@Nullable final DittoHeaders dittoHeaders = ((WithDittoHeaders) object).getDittoHeaders();
if (null != dittoHeaders) {
return dittoHeaders;
}
LOG.warn("Object <{}> did not contain DittoHeaders although it should! Using empty DittoHeaders instead.",
object);
}
return DittoHeaders.empty();
}
代码示例来源:origin: eclipse/ditto
private WithDittoHeaders appendETagHeader(final C command, final WithDittoHeaders response) {
final DittoHeaders dittoHeaders = response.getDittoHeaders();
final Optional<EntityTag> entityTagOpt = determineETagEntity(command)
.flatMap(EntityTag::fromEntity);
if (entityTagOpt.isPresent()) {
final DittoHeaders newDittoHeaders = dittoHeaders.toBuilder().eTag(entityTagOpt.get()).build();
return response.setDittoHeaders(newDittoHeaders);
}
return response;
}
代码示例来源:origin: eclipse/ditto
replyToSender(withDittoHeaders.setDittoHeaders(retrieveThing.getDittoHeaders()), sender);
} else if (isAskTimeoutException(response, error)) {
reportThingUnavailable(retrieveThing.getThingId(), retrieveThing.getDittoHeaders(), sender);
代码示例来源:origin: org.eclipse.ditto/ditto-services-utils-akka
/**
* Enhances the MDC around the passed SLF4J {@code Logger} with the {@code correlation-id} extracted from the passed
* {@code withDittoHeaders}. Invokes the passed in {@code logConsumer} around the MDC setting/removing.
*
* @param slf4jLogger the SLF4J logger to log with.
* @param withDittoHeaders where to extract a possible correlationId from.
* @param logConsumer the consumer with which the caller must log.
*/
public static void logWithCorrelationId(final Logger slf4jLogger, final WithDittoHeaders<?> withDittoHeaders,
final Consumer<Logger> logConsumer) {
logWithCorrelationId(slf4jLogger, withDittoHeaders.getDittoHeaders(), logConsumer);
}
代码示例来源:origin: org.eclipse.ditto/ditto-services-policies-persistence
private WithDittoHeaders appendETagHeader(final C command, final WithDittoHeaders response) {
final DittoHeaders dittoHeaders = response.getDittoHeaders();
final Optional<EntityTag> entityTagOpt = determineETagEntity(command)
.flatMap(EntityTag::fromEntity);
if (entityTagOpt.isPresent()) {
final DittoHeaders newDittoHeaders = dittoHeaders.toBuilder().eTag(entityTagOpt.get()).build();
return response.setDittoHeaders(newDittoHeaders);
}
return response;
}
代码示例来源:origin: org.eclipse.ditto/ditto-services-utils-cluster
private static DittoHeaders getDittoHeadersOrEmpty(final Object object) {
if (object instanceof WithDittoHeaders) {
@Nullable final DittoHeaders dittoHeaders = ((WithDittoHeaders) object).getDittoHeaders();
if (null != dittoHeaders) {
return dittoHeaders;
}
LOG.warn("Object <{}> did not contain DittoHeaders although it should! Using empty DittoHeaders instead.",
object);
}
return DittoHeaders.empty();
}
代码示例来源:origin: eclipse/ditto
private static <C extends Command, E> WithDittoHeaders appendETagHeaderIfProvided(final C command,
final WithDittoHeaders withDittoHeaders, @Nullable final Thing thing,
@Nullable final ETagEntityProvider<C, E> eTagProvider) {
if (eTagProvider == null) {
return withDittoHeaders;
}
final Optional<E> eTagEntityOpt = eTagProvider.determineETagEntity(command, thing);
if (eTagEntityOpt.isPresent()) {
final Optional<EntityTag> entityTagOpt = EntityTag.fromEntity(eTagEntityOpt.get());
if (entityTagOpt.isPresent()) {
final EntityTag entityTag = entityTagOpt.get();
final DittoHeaders newDittoHeaders = withDittoHeaders.getDittoHeaders().toBuilder()
.eTag(entityTag)
.build();
return withDittoHeaders.setDittoHeaders(newDittoHeaders);
}
}
return withDittoHeaders;
}
代码示例来源:origin: eclipse/ditto
/**
* Enhances the MDC around the passed SLF4J {@code Logger} with the {@code correlation-id} extracted from the passed
* {@code withDittoHeaders}. Invokes the passed in {@code logConsumer} around the MDC setting/removing.
*
* @param slf4jLogger the SLF4J logger to log with.
* @param withDittoHeaders where to extract a possible correlationId from.
* @param additionalMdcFields additional fields which should bet set to the MDC.
* @param logConsumer the consumer with which the caller must log.
*/
public static void logWithCorrelationId(final Logger slf4jLogger, final WithDittoHeaders<?> withDittoHeaders,
final Map<String, String> additionalMdcFields, final Consumer<Logger> logConsumer) {
logWithCorrelationId(slf4jLogger, withDittoHeaders.getDittoHeaders(), additionalMdcFields, logConsumer);
}
代码示例来源:origin: org.eclipse.ditto/ditto-services-things-persistence
private static <C extends Command, E> WithDittoHeaders appendETagHeaderIfProvided(final C command,
final WithDittoHeaders withDittoHeaders, @Nullable final Thing thing,
@Nullable final ETagEntityProvider<C, E> eTagProvider) {
if (eTagProvider == null) {
return withDittoHeaders;
}
final Optional<E> eTagEntityOpt = eTagProvider.determineETagEntity(command, thing);
if (eTagEntityOpt.isPresent()) {
final Optional<EntityTag> entityTagOpt = EntityTag.fromEntity(eTagEntityOpt.get());
if (entityTagOpt.isPresent()) {
final EntityTag entityTag = entityTagOpt.get();
final DittoHeaders newDittoHeaders = withDittoHeaders.getDittoHeaders().toBuilder()
.eTag(entityTag)
.build();
return withDittoHeaders.setDittoHeaders(newDittoHeaders);
}
}
return withDittoHeaders;
}
代码示例来源:origin: eclipse/ditto
private Jsonifiable.WithPredicate<JsonObject, JsonField> publishResponsePublishedEvent(
final Jsonifiable.WithPredicate<JsonObject, JsonField> jsonifiable) {
if (jsonifiable instanceof CommandResponse) {
// only create ResponsePublished for CommandResponses, not for Events with the same correlationId
((WithDittoHeaders) jsonifiable).getDittoHeaders()
.getCorrelationId()
.map(ResponsePublished::new)
.ifPresent(eventStream::publish);
}
return jsonifiable;
}
代码示例来源:origin: eclipse/ditto
/**
* @param withPotentialDittoHeaders the object which potentially contains DittoHeaders from which a
* {@code correlation-id} can be extracted in order to enhance the returned DiagnosticLoggingAdapter
* @return the diagnostic logging adapter.
*/
protected DiagnosticLoggingAdapter log(final Object withPotentialDittoHeaders) {
if (withPotentialDittoHeaders instanceof WithDittoHeaders) {
return log(((WithDittoHeaders<?>) withPotentialDittoHeaders).getDittoHeaders());
}
return context.log;
}
代码示例来源:origin: eclipse/ditto
/**
* Enhances the default slf4j {@link org.slf4j.MDC} with a {@code correlationId} of the passed
* {@code withDittoHeaders} (if present), else a random correlation id.
*
* @param withDittoHeaders where to extract a possible correlationId from.
*/
public static void enhanceLogWithCorrelationIdOrRandom(final WithDittoHeaders<?> withDittoHeaders) {
LogUtil.enhanceLogWithCorrelationIdOrRandom(withDittoHeaders.getDittoHeaders());
}
代码示例来源:origin: eclipse/ditto
/**
* Enhances the MDC around the passed SLF4J {@code Logger} with the {@code correlation-id} extracted from the passed
* {@code withDittoHeaders}. Invokes the passed in {@code logConsumer} around the MDC setting/removing.
*
* @param slf4jLogger the SLF4J logger to log with.
* @param withDittoHeaders where to extract a possible correlationId from.
* @param logConsumer the consumer with which the caller must log.
*/
public static void logWithCorrelationId(final Logger slf4jLogger, final WithDittoHeaders<?> withDittoHeaders,
final Consumer<Logger> logConsumer) {
logWithCorrelationId(slf4jLogger, withDittoHeaders.getDittoHeaders(), logConsumer);
}
代码示例来源:origin: eclipse/ditto
/**
* Enhances the default slf4j {@link org.slf4j.MDC} with a {@code correlationId} of the passed
* {@code withDittoHeaders} (if present).
*
* @param withDittoHeaders where to extract a possible correlationId from.
*/
public static void enhanceLogWithCorrelationId(final WithDittoHeaders<?> withDittoHeaders) {
withDittoHeaders.getDittoHeaders()
.getCorrelationId()
.ifPresent(LogUtil::enhanceLogWithCorrelationId);
}
代码示例来源:origin: org.eclipse.ditto/ditto-services-utils-akka
/**
* Enhances the MDC around the passed SLF4J {@code Logger} with the {@code correlation-id} extracted from the passed
* {@code withDittoHeaders}. Invokes the passed in {@code logConsumer} around the MDC setting/removing.
*
* @param slf4jLogger the SLF4J logger to log with.
* @param withDittoHeaders where to extract a possible correlationId from.
* @param additionalMdcFields additional fields which should bet set to the MDC.
* @param logConsumer the consumer with which the caller must log.
*/
public static void logWithCorrelationId(final Logger slf4jLogger, final WithDittoHeaders<?> withDittoHeaders,
final Map<String, String> additionalMdcFields, final Consumer<Logger> logConsumer) {
logWithCorrelationId(slf4jLogger, withDittoHeaders.getDittoHeaders(), additionalMdcFields, logConsumer);
}
代码示例来源:origin: eclipse/ditto
/**
* Substitutes all placeholders contained in the {@code input} based on the {@link DittoHeaders} contained in
* {@code withDittoHeaders}.
*
* @param input the input.
* @param withDittoHeaders the instance of {@link WithDittoHeaders}, from which the headers are extracted
* (normally a command).
* @return the replaced input, if the input contains placeholders; the (same) input object, if no placeholders
* were contained in the input.
*/
public String substitute(final String input, final WithDittoHeaders withDittoHeaders) {
requireNonNull(input);
requireNonNull(withDittoHeaders);
return substitute(input, withDittoHeaders.getDittoHeaders());
}
代码示例来源:origin: org.eclipse.ditto/ditto-services-connectivity-messaging
private void finishTrace(final WithDittoHeaders<? extends Signal> response, @Nullable final Throwable cause) {
response.getDittoHeaders().getCorrelationId().ifPresent(correlationId -> {
try {
finishTrace(correlationId, cause);
} catch (final IllegalArgumentException e) {
log.debug("Trace missing for response: '{}'", response);
}
});
}
代码示例来源:origin: eclipse/ditto
private void finishTrace(final WithDittoHeaders<? extends Signal> response, @Nullable final Throwable cause) {
response.getDittoHeaders().getCorrelationId().ifPresent(correlationId -> {
try {
finishTrace(correlationId, cause);
} catch (final IllegalArgumentException e) {
log.debug("Trace missing for response: '{}'", response);
}
});
}
代码示例来源:origin: org.eclipse.ditto/ditto-services-things-persistence
@Override
protected void doApply(final Object message) {
log.debug("Unexpected message after initialization of actor received: {} - "
+ "Terminating this actor and sending <{}> to requester ...", message,
ThingNotAccessibleException.class.getName());
final ThingNotAccessibleException.Builder builder = ThingNotAccessibleException.newBuilder(thingId);
if (message instanceof WithDittoHeaders) {
builder.dittoHeaders(((WithDittoHeaders) message).getDittoHeaders());
}
notifySender(builder.build());
scheduleCheckForThingActivity(activityCheckInterval.getSeconds());
}
代码示例来源:origin: eclipse/ditto
@Override
protected void doApply(final Object message) {
log.debug("Unexpected message after initialization of actor received: {} - "
+ "Terminating this actor and sending <{}> to requester ...", message,
ThingNotAccessibleException.class.getName());
final ThingNotAccessibleException.Builder builder = ThingNotAccessibleException.newBuilder(thingId);
if (message instanceof WithDittoHeaders) {
builder.dittoHeaders(((WithDittoHeaders) message).getDittoHeaders());
}
notifySender(builder.build());
scheduleCheckForThingActivity(activityCheckInterval.getSeconds());
}
内容来源于网络,如有侵权,请联系作者删除!