com.spt.development.cid.CorrelationId Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of spt-development-cid Show documentation
Show all versions of spt-development-cid Show documentation
A very simple library for getting/setting the current correlation ID, utilising ThreadLocal.
package com.spt.development.cid;
/**
* Simple utility class for using {@link ThreadLocal} for storing the current correlation ID.
*/
public final class CorrelationId {
static final String DEFAULT = "no-cid";
private static final ThreadLocal VALUE = ThreadLocal.withInitial(() -> DEFAULT);
private CorrelationId() {}
/**
* Gets the correlation ID associated with the current thread.
*
* @return the correlation ID.
*/
public static String get() {
return VALUE.get();
}
/**
* Resets the current correlation ID associated with the current thread to the default (unset) value.
*/
public static void reset() {
set(DEFAULT);
}
/**
* Sets the current correlation ID associated with the current thread.
*
* @param correlationId the correlation ID associated with the current thread.
*/
public static void set(String correlationId) {
VALUE.set(correlationId);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy