reduce ThreadContext's inner classes visibility

This commit is contained in:
javanna 2016-08-10 18:01:52 +02:00 committed by Luca Cavanna
parent 4ed7c2bd35
commit ea6b7b46c9
1 changed files with 8 additions and 14 deletions

View File

@ -100,9 +100,7 @@ public final class ThreadContext implements Closeable, Writeable {
public StoredContext stashContext() { public StoredContext stashContext() {
final ThreadContextStruct context = threadLocal.get(); final ThreadContextStruct context = threadLocal.get();
threadLocal.set(null); threadLocal.set(null);
return () -> { return () -> threadLocal.set(context);
threadLocal.set(context);
};
} }
/** /**
@ -114,9 +112,7 @@ public final class ThreadContext implements Closeable, Writeable {
Map<String, String> newHeader = new HashMap<>(headers); Map<String, String> newHeader = new HashMap<>(headers);
newHeader.putAll(context.requestHeaders); newHeader.putAll(context.requestHeaders);
threadLocal.set(DEFAULT_CONTEXT.putHeaders(newHeader)); threadLocal.set(DEFAULT_CONTEXT.putHeaders(newHeader));
return () -> { return () -> threadLocal.set(context);
threadLocal.set(context);
};
} }
/** /**
@ -124,9 +120,7 @@ public final class ThreadContext implements Closeable, Writeable {
*/ */
public StoredContext newStoredContext() { public StoredContext newStoredContext() {
final ThreadContextStruct context = threadLocal.get(); final ThreadContextStruct context = threadLocal.get();
return () -> { return () -> threadLocal.set(context);
threadLocal.set(context);
};
} }
@Override @Override
@ -252,6 +246,7 @@ public final class ThreadContext implements Closeable, Writeable {
return command; return command;
} }
@FunctionalInterface
public interface StoredContext extends AutoCloseable { public interface StoredContext extends AutoCloseable {
@Override @Override
void close(); void close();
@ -261,7 +256,7 @@ public final class ThreadContext implements Closeable, Writeable {
} }
} }
static final class ThreadContextStruct { private static final class ThreadContextStruct {
private final Map<String, String> requestHeaders; private final Map<String, String> requestHeaders;
private final Map<String, Object> transientHeaders; private final Map<String, Object> transientHeaders;
private final Map<String, List<String>> responseHeaders; private final Map<String, List<String>> responseHeaders;
@ -377,7 +372,6 @@ public final class ThreadContext implements Closeable, Writeable {
out.writeMapOfLists(responseHeaders); out.writeMapOfLists(responseHeaders);
} }
} }
private static class ContextThreadLocal extends CloseableThreadLocal<ThreadContextStruct> { private static class ContextThreadLocal extends CloseableThreadLocal<ThreadContextStruct> {
@ -432,11 +426,11 @@ public final class ThreadContext implements Closeable, Writeable {
/** /**
* Wraps a Runnable to preserve the thread context. * Wraps a Runnable to preserve the thread context.
*/ */
class ContextPreservingRunnable implements Runnable { private class ContextPreservingRunnable implements Runnable {
private final Runnable in; private final Runnable in;
private final ThreadContext.StoredContext ctx; private final ThreadContext.StoredContext ctx;
ContextPreservingRunnable(Runnable in) { private ContextPreservingRunnable(Runnable in) {
ctx = newStoredContext(); ctx = newStoredContext();
this.in = in; this.in = in;
} }
@ -472,7 +466,7 @@ public final class ThreadContext implements Closeable, Writeable {
/** /**
* Wraps an AbstractRunnable to preserve the thread context. * Wraps an AbstractRunnable to preserve the thread context.
*/ */
public class ContextPreservingAbstractRunnable extends AbstractRunnable { private class ContextPreservingAbstractRunnable extends AbstractRunnable {
private final AbstractRunnable in; private final AbstractRunnable in;
private final ThreadContext.StoredContext ctx; private final ThreadContext.StoredContext ctx;