@@ -649,12 +649,7 @@ public void closeOutbound(final Promise<Void> promise) { |
649 | 649 | if (ctx.executor().inEventLoop()) { |
650 | 650 | closeOutbound0(promise); |
651 | 651 | } else { |
652 | | - ctx.executor().execute(new Runnable() { |
653 | | - @Override |
654 | | - public void run() { |
655 | | - closeOutbound0(promise); |
656 | | - } |
657 | | - }); |
| 652 | + ctx.executor().execute(() -> closeOutbound0(promise)); |
658 | 653 | } |
659 | 654 | } |
660 | 655 |
|
@@ -1017,12 +1012,6 @@ private boolean wrapNonAppData(final ChannelHandlerContext ctx, boolean inUnwrap |
1017 | 1012 | if (result.bytesProduced() == 0 && status != HandshakeStatus.NEED_TASK) { |
1018 | 1013 | break; |
1019 | 1014 | } |
1020 | | - |
1021 | | - // It should not consume empty buffers when it is not handshaking |
1022 | | - // Fix for Android, where it was encrypting empty buffers even when not handshaking |
1023 | | - if (result.bytesConsumed() == 0 && result.getHandshakeStatus() == HandshakeStatus.NOT_HANDSHAKING) { |
1024 | | - break; |
1025 | | - } |
1026 | 1015 | } |
1027 | 1016 | } finally { |
1028 | 1017 | if (out != null) { |
@@ -1589,25 +1578,15 @@ private boolean setHandshakeSuccessUnwrapMarkReentry() throws SSLException { |
1589 | 1578 |
|
1590 | 1579 | private void executeNotifyClosePromise(final ChannelHandlerContext ctx) { |
1591 | 1580 | try { |
1592 | | - ctx.executor().execute(new Runnable() { |
1593 | | - @Override |
1594 | | - public void run() { |
1595 | | - notifyClosePromise(null); |
1596 | | - } |
1597 | | - }); |
| 1581 | + ctx.executor().execute(() -> notifyClosePromise(null)); |
1598 | 1582 | } catch (RejectedExecutionException e) { |
1599 | 1583 | notifyClosePromise(e); |
1600 | 1584 | } |
1601 | 1585 | } |
1602 | 1586 |
|
1603 | 1587 | private void executeChannelRead(final ChannelHandlerContext ctx, final ByteBuf decodedOut) { |
1604 | 1588 | try { |
1605 | | - ctx.executor().execute(new Runnable() { |
1606 | | - @Override |
1607 | | - public void run() { |
1608 | | - ctx.fireChannelRead(decodedOut); |
1609 | | - } |
1610 | | - }); |
| 1589 | + ctx.executor().execute(() -> ctx.fireChannelRead(decodedOut)); |
1611 | 1590 | } catch (RejectedExecutionException e) { |
1612 | 1591 | decodedOut.release(); |
1613 | 1592 | throw e; |
@@ -1722,12 +1701,7 @@ boolean resumeLater() { |
1722 | 1701 | */ |
1723 | 1702 | private final class SslTasksRunner implements Runnable { |
1724 | 1703 | private final boolean inUnwrap; |
1725 | | - private final Runnable runCompleteTask = new Runnable() { |
1726 | | - @Override |
1727 | | - public void run() { |
1728 | | - runComplete(); |
1729 | | - } |
1730 | | - }; |
| 1704 | + private final Runnable runCompleteTask = this::runComplete; |
1731 | 1705 |
|
1732 | 1706 | SslTasksRunner(boolean inUnwrap) { |
1733 | 1707 | this.inUnwrap = inUnwrap; |
@@ -1882,12 +1856,7 @@ void runComplete() { |
1882 | 1856 | // decoding. |
1883 | 1857 | // |
1884 | 1858 | // See https://github.com/netty/netty-tcnative/issues/680 |
1885 | | - executor.execute(new Runnable() { |
1886 | | - @Override |
1887 | | - public void run() { |
1888 | | - resumeOnEventExecutor(); |
1889 | | - } |
1890 | | - }); |
| 1859 | + executor.execute(this::resumeOnEventExecutor); |
1891 | 1860 | } |
1892 | 1861 |
|
1893 | 1862 | @Override |
@@ -1917,12 +1886,9 @@ private void handleException(final Throwable cause) { |
1917 | 1886 | safeExceptionCaught(cause); |
1918 | 1887 | } else { |
1919 | 1888 | try { |
1920 | | - executor.execute(new Runnable() { |
1921 | | - @Override |
1922 | | - public void run() { |
1923 | | - clearState(STATE_PROCESS_TASK); |
1924 | | - safeExceptionCaught(cause); |
1925 | | - } |
| 1889 | + executor.execute(() -> { |
| 1890 | + clearState(STATE_PROCESS_TASK); |
| 1891 | + safeExceptionCaught(cause); |
1926 | 1892 | }); |
1927 | 1893 | } catch (RejectedExecutionException ignore) { |
1928 | 1894 | clearState(STATE_PROCESS_TASK); |
@@ -2152,7 +2118,7 @@ public Future<Channel> renegotiate() { |
2152 | 2118 | throw new IllegalStateException(); |
2153 | 2119 | } |
2154 | 2120 |
|
2155 | | - return renegotiate(ctx.executor().<Channel>newPromise()); |
| 2121 | + return renegotiate(ctx.executor().newPromise()); |
2156 | 2122 | } |
2157 | 2123 |
|
2158 | 2124 | /** |
@@ -2168,12 +2134,7 @@ public Future<Channel> renegotiate(final Promise<Channel> promise) { |
2168 | 2134 |
|
2169 | 2135 | EventExecutor executor = ctx.executor(); |
2170 | 2136 | if (!executor.inEventLoop()) { |
2171 | | - executor.execute(new Runnable() { |
2172 | | - @Override |
2173 | | - public void run() { |
2174 | | - renegotiateOnEventLoop(promise); |
2175 | | - } |
2176 | | - }); |
| 2137 | + executor.execute(() -> renegotiateOnEventLoop(promise)); |
2177 | 2138 | return promise; |
2178 | 2139 | } |
2179 | 2140 |
|
@@ -2238,21 +2199,18 @@ private void applyHandshakeTimeout() { |
2238 | 2199 | return; |
2239 | 2200 | } |
2240 | 2201 |
|
2241 | | - final Future<?> timeoutFuture = ctx.executor().schedule(new Runnable() { |
2242 | | - @Override |
2243 | | - public void run() { |
2244 | | - if (localHandshakePromise.isDone()) { |
2245 | | - return; |
2246 | | - } |
2247 | | - SSLException exception = |
2248 | | - new SslHandshakeTimeoutException("handshake timed out after " + handshakeTimeoutMillis + "ms"); |
2249 | | - try { |
2250 | | - if (localHandshakePromise.tryFailure(exception)) { |
2251 | | - SslUtils.handleHandshakeFailure(ctx, exception, true); |
2252 | | - } |
2253 | | - } finally { |
2254 | | - releaseAndFailAll(ctx, exception); |
| 2202 | + final Future<?> timeoutFuture = ctx.executor().schedule(() -> { |
| 2203 | + if (localHandshakePromise.isDone()) { |
| 2204 | + return; |
| 2205 | + } |
| 2206 | + SSLException exception = |
| 2207 | + new SslHandshakeTimeoutException("handshake timed out after " + handshakeTimeoutMillis + "ms"); |
| 2208 | + try { |
| 2209 | + if (localHandshakePromise.tryFailure(exception)) { |
| 2210 | + SslUtils.handleHandshakeFailure(ctx, exception, true); |
2255 | 2211 | } |
| 2212 | + } finally { |
| 2213 | + releaseAndFailAll(ctx, exception); |
2256 | 2214 | } |
2257 | 2215 | }, handshakeTimeoutMillis, TimeUnit.MILLISECONDS); |
2258 | 2216 |
|
@@ -2296,15 +2254,12 @@ private void safeClose( |
2296 | 2254 | long closeNotifyTimeout = closeNotifyFlushTimeoutMillis; |
2297 | 2255 | if (closeNotifyTimeout > 0) { |
2298 | 2256 | // Force-close the connection if close_notify is not fully sent in time. |
2299 | | - timeoutFuture = ctx.executor().schedule(new Runnable() { |
2300 | | - @Override |
2301 | | - public void run() { |
2302 | | - // May be done in the meantime as cancel(...) is only best effort. |
2303 | | - if (!flushFuture.isDone()) { |
2304 | | - logger.warn("{} Last write attempt timed out; force-closing the connection.", |
2305 | | - ctx.channel()); |
| 2257 | + timeoutFuture = ctx.executor().schedule(() -> { |
| 2258 | + // May be done in the meantime as cancel(...) is only best effort. |
| 2259 | + if (!flushFuture.isDone()) { |
| 2260 | + logger.warn("{} Last write attempt timed out; force-closing the connection.", |
| 2261 | + ctx.channel()); |
2306 | 2262 | addCloseListener(ctx.close(), promise); |
2307 | | - } |
2308 | 2263 | } |
2309 | 2264 | }, closeNotifyTimeout, TimeUnit.MILLISECONDS); |
2310 | 2265 | } else { |
@@ -2328,17 +2283,14 @@ public void run() { |
2328 | 2283 | final Future<?> closeNotifyReadTimeoutFuture; |
2329 | 2284 |
|
2330 | 2285 | if (!sslClosePromise.isDone()) { |
2331 | | - closeNotifyReadTimeoutFuture = ctx.executor().schedule(new Runnable() { |
2332 | | - @Override |
2333 | | - public void run() { |
2334 | | - if (!sslClosePromise.isDone()) { |
2335 | | - logger.debug( |
2336 | | - "{} did not receive close_notify in {}ms; force-closing the connection.", |
2337 | | - ctx.channel(), closeNotifyReadTimeout); |
2338 | | - |
2339 | | - // Do the close now... |
| 2286 | + closeNotifyReadTimeoutFuture = ctx.executor().schedule(() -> { |
| 2287 | + if (!sslClosePromise.isDone()) { |
| 2288 | + logger.debug( |
| 2289 | + "{} did not receive close_notify in {}ms; force-closing the connection.", |
| 2290 | + ctx.channel(), closeNotifyReadTimeout); |
| 2291 | + |
| 2292 | + // Do the close now... |
2340 | 2293 | addCloseListener(ctx.close(), promise); |
2341 | | - } |
2342 | 2294 | } |
2343 | 2295 | }, closeNotifyReadTimeout, TimeUnit.MILLISECONDS); |
2344 | 2296 | } else { |
|