
com.shedhack.thread.context.handler.SimpleThreadContextHandler Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of thread-context-handler Show documentation
Show all versions of thread-context-handler Show documentation
Context enabler, for helping with debugging/logging
The newest version!
package com.shedhack.thread.context.handler;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
/**
* The most basic handler stores simple strings.
* The client is responsible for managing the input and output strings.
*
* @author imamchishty
*/
public class SimpleThreadContextHandler implements ThreadContextHandler {
public SimpleThreadContextHandler() {
this.afterSetHandlers = Collections.EMPTY_LIST;
}
public SimpleThreadContextHandler(List afterSetHandlers) {
this.afterSetHandlers = afterSetHandlers;
}
private final List afterSetHandlers;
/**
* {@inheritDoc}
*/
public void setThreadContext(String value) {
if(value !=null && !value.isEmpty()) {
Thread.currentThread().setName(value);
// call the after setting handler
this.afterSettingThreadContext(value, afterSetHandlers);
}
}
/**
* {@inheritDoc}
*/
public Optional getThreadContext() {
return convertFromString(Thread.currentThread().getName());
}
@Override
public Optional convertFromString(String original) {
return Optional.ofNullable(original);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy