Browse Source

Remove a few more readFroms

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

Relates to #17085
Nik Everett 9 years ago
parent
commit
1f5fd3094f

+ 4 - 20
core/src/main/java/org/elasticsearch/common/util/concurrent/ThreadContext.java

@@ -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;

+ 0 - 5
core/src/test/java/org/elasticsearch/common/io/stream/BytesStreamsTests.java

@@ -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 {