1313import org .elasticsearch .TransportVersion ;
1414import org .elasticsearch .TransportVersions ;
1515import org .elasticsearch .common .bytes .BytesReference ;
16- import org .elasticsearch .common .compress .CompressorFactory ;
1716import org .elasticsearch .common .io .stream .StreamInput ;
1817import org .elasticsearch .common .util .concurrent .ThreadContext ;
1918import org .elasticsearch .core .IOUtils ;
@@ -30,7 +29,7 @@ static void logInboundMessage(TcpChannel channel, BytesReference message) {
3029 try {
3130 String logMessage = format (channel , message , "READ" );
3231 logger .trace (logMessage );
33- } catch (IOException e ) {
32+ } catch (Exception e ) {
3433 logger .warn ("an exception occurred formatting a READ trace message" , e );
3534 }
3635 }
@@ -41,7 +40,7 @@ static void logInboundMessage(TcpChannel channel, InboundMessage message) {
4140 try {
4241 String logMessage = format (channel , message , "READ" );
4342 logger .trace (logMessage );
44- } catch (IOException e ) {
43+ } catch (Exception e ) {
4544 logger .warn ("an exception occurred formatting a READ trace message" , e );
4645 }
4746 }
@@ -57,7 +56,7 @@ static void logOutboundMessage(TcpChannel channel, BytesReference message) {
5756 BytesReference withoutHeader = message .slice (HEADER_SIZE , message .length () - HEADER_SIZE );
5857 String logMessage = format (channel , withoutHeader , "WRITE" );
5958 logger .trace (logMessage );
60- } catch (IOException e ) {
59+ } catch (Exception e ) {
6160 logger .warn ("an exception occurred formatting a WRITE trace message" , e );
6261 }
6362 }
@@ -111,55 +110,32 @@ private static String format(TcpChannel channel, BytesReference message, String
111110 return sb .toString ();
112111 }
113112
114- private static String format (TcpChannel channel , InboundMessage message , String event ) throws IOException {
113+ private static String format (TcpChannel channel , InboundMessage message , String event ) {
115114 final StringBuilder sb = new StringBuilder ();
116115 sb .append (channel );
117116
118117 if (message .isPing ()) {
119118 sb .append (" [ping]" ).append (' ' ).append (event ).append (": " ).append (6 ).append ('B' );
120119 } else {
121- boolean success = false ;
122120 Header header = message .getHeader ();
123121 int networkMessageSize = header .getNetworkMessageSize ();
124122 int messageLengthWithHeader = HEADER_SIZE + networkMessageSize ;
125- StreamInput streamInput = message .openOrGetStreamInput ();
126- try {
127- final long requestId = header .getRequestId ();
128- final boolean isRequest = header .isRequest ();
129- final String type = isRequest ? "request" : "response" ;
130- final String version = header .getVersion ().toString ();
131- sb .append (" [length: " ).append (messageLengthWithHeader );
132- sb .append (", request id: " ).append (requestId );
133- sb .append (", type: " ).append (type );
134- sb .append (", version: " ).append (version );
123+ final long requestId = header .getRequestId ();
124+ final boolean isRequest = header .isRequest ();
125+ final String type = isRequest ? "request" : "response" ;
126+ final String version = header .getVersion ().toString ();
127+ sb .append (" [length: " ).append (messageLengthWithHeader );
128+ sb .append (", request id: " ).append (requestId );
129+ sb .append (", type: " ).append (type );
130+ sb .append (", version: " ).append (version );
135131
136- // TODO: Maybe Fix for BWC
137- if (header .needsToReadVariableHeader () == false && isRequest ) {
138- sb .append (", action: " ).append (header .getActionName ());
139- }
140- sb .append (']' );
141- sb .append (' ' ).append (event ).append (": " ).append (messageLengthWithHeader ).append ('B' );
142- success = true ;
143- } finally {
144- if (success ) {
145- IOUtils .close (streamInput );
146- } else {
147- IOUtils .closeWhileHandlingException (streamInput );
148- }
132+ // TODO: Maybe Fix for BWC
133+ if (header .needsToReadVariableHeader () == false && isRequest ) {
134+ sb .append (", action: " ).append (header .getActionName ());
149135 }
136+ sb .append (']' );
137+ sb .append (' ' ).append (event ).append (": " ).append (messageLengthWithHeader ).append ('B' );
150138 }
151139 return sb .toString ();
152140 }
153-
154- private static StreamInput decompressingStream (byte status , StreamInput streamInput ) throws IOException {
155- if (TransportStatus .isCompress (status ) && streamInput .available () > 0 ) {
156- try {
157- return CompressorFactory .COMPRESSOR .threadLocalStreamInput (streamInput );
158- } catch (IllegalArgumentException e ) {
159- throw new IllegalStateException ("stream marked as compressed, but is missing deflate header" );
160- }
161- } else {
162- return streamInput ;
163- }
164- }
165141}
0 commit comments