Remove a few more readFroms

ThreadContext had a very odd relationship with the Writeable interface.
This makes it conform.

Relates to #17085
This commit is contained in:
Nik Everett 2016-04-20 11:42:09 -04:00
parent 693c80037e
commit 1f5fd3094f
2 changed files with 4 additions and 25 deletions

View File

@ -60,7 +60,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
* </pre>
*
*/
public final class ThreadContext implements Closeable, Writeable<ThreadContext.ThreadContextStruct>{
public final class ThreadContext implements Closeable, Writeable<ThreadContext> {
public static final String PREFIX = "request.headers";
public static final Setting<Settings> DEFAULT_HEADERS_SETTING = Setting.groupSetting(PREFIX + ".", Property.NodeScope);
@ -132,19 +132,13 @@ public final class ThreadContext implements Closeable, Writeable<ThreadContext.T
threadLocal.get().writeTo(out, defaultHeader);
}
@Override
public ThreadContextStruct readFrom(StreamInput in) throws IOException {
return DEFAULT_CONTEXT.readFrom(in);
}
/**
* Reads the headers from the stream into the current context
*/
public void readHeaders(StreamInput in) throws IOException {
threadLocal.set(readFrom(in));
threadLocal.set(new ThreadContext.ThreadContextStruct(in));
}
/**
* Returns the header for the given key or <code>null</code> if not present
*/
@ -239,7 +233,7 @@ public final class ThreadContext implements Closeable, Writeable<ThreadContext.T
}
}
static final class ThreadContextStruct implements Writeable<ThreadContextStruct> {
static final class ThreadContextStruct {
private final Map<String,String> headers;
private final Map<String, Object> transientHeaders;
@ -309,17 +303,7 @@ public final class ThreadContext implements Closeable, Writeable<ThreadContext.T
return putHeaders(newHeaders);
}
@Override
public ThreadContextStruct readFrom(StreamInput in) throws IOException {
return new ThreadContextStruct(in);
}
@Override
public void writeTo(StreamOutput out) throws IOException {
throw new UnsupportedOperationException("use the other write to");
}
public void writeTo(StreamOutput out, Map<String, String> defaultHeaders) throws IOException {
private void writeTo(StreamOutput out, Map<String, String> defaultHeaders) throws IOException {
final Map<String, String> headers;
if (defaultHeaders.isEmpty()) {
headers = this.headers;

View File

@ -367,11 +367,6 @@ public class BytesStreamsTests extends ESTestCase {
@Override
public void writeTo(StreamOutput out) throws IOException {
}
@Override
public Object readFrom(StreamInput in) throws IOException {
return null;
}
});
StreamInput in = new NamedWriteableAwareStreamInput(StreamInput.wrap(out.bytes().toBytes()), namedWriteableRegistry);
try {