Skip to content

Commit f05a200

Browse files
committed
Remove the deprecated constructors in SslHandler
1 parent 53110a8 commit f05a200

File tree

2 files changed

+12
-107
lines changed

2 files changed

+12
-107
lines changed

handler/src/main/java/io/netty/handler/ssl/SslHandler.java

Lines changed: 6 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
import io.netty.util.concurrent.EventExecutor;
3232
import io.netty.util.concurrent.Future;
3333
import io.netty.util.concurrent.GenericFutureListener;
34-
import io.netty.util.concurrent.ImmediateExecutor;
3534
import io.netty.util.internal.EmptyArrays;
3635
import io.netty.util.internal.PendingWrite;
3736
import io.netty.util.internal.PlatformDependent;
@@ -51,11 +50,8 @@
5150
import java.nio.channels.DatagramChannel;
5251
import java.nio.channels.SocketChannel;
5352
import java.util.ArrayDeque;
54-
import java.util.ArrayList;
5553
import java.util.Deque;
5654
import java.util.List;
57-
import java.util.concurrent.CountDownLatch;
58-
import java.util.concurrent.Executor;
5955
import java.util.concurrent.ScheduledFuture;
6056
import java.util.concurrent.TimeUnit;
6157
import java.util.regex.Pattern;
@@ -179,7 +175,6 @@ public class SslHandler extends ByteToMessageDecoder {
179175
private volatile ChannelHandlerContext ctx;
180176
private final SSLEngine engine;
181177
private final int maxPacketBufferSize;
182-
private final Executor delegatedTaskExecutor;
183178

184179
private final boolean startTls;
185180
private boolean sentFirstMessage;
@@ -216,32 +211,11 @@ public SslHandler(SSLEngine engine) {
216211
* @param startTls {@code true} if the first write request shouldn't be
217212
* encrypted by the {@link SSLEngine}
218213
*/
219-
@SuppressWarnings("deprecation")
220214
public SslHandler(SSLEngine engine, boolean startTls) {
221-
this(engine, startTls, ImmediateExecutor.INSTANCE);
222-
}
223-
224-
/**
225-
* @deprecated Use {@link #SslHandler(SSLEngine)} instead.
226-
*/
227-
@Deprecated
228-
public SslHandler(SSLEngine engine, Executor delegatedTaskExecutor) {
229-
this(engine, false, delegatedTaskExecutor);
230-
}
231-
232-
/**
233-
* @deprecated Use {@link #SslHandler(SSLEngine, boolean)} instead.
234-
*/
235-
@Deprecated
236-
public SslHandler(SSLEngine engine, boolean startTls, Executor delegatedTaskExecutor) {
237215
if (engine == null) {
238216
throw new NullPointerException("engine");
239217
}
240-
if (delegatedTaskExecutor == null) {
241-
throw new NullPointerException("delegatedTaskExecutor");
242-
}
243218
this.engine = engine;
244-
this.delegatedTaskExecutor = delegatedTaskExecutor;
245219
this.startTls = startTls;
246220
maxPacketBufferSize = engine.getSession().getPacketBufferSize();
247221
}
@@ -938,65 +912,16 @@ private static SSLEngineResult unwrap(SSLEngine engine, ByteBuffer in, ByteBuf o
938912
}
939913

940914
/**
941-
* Fetches all delegated tasks from the {@link SSLEngine} and runs them via the {@link #delegatedTaskExecutor}.
942-
* If the {@link #delegatedTaskExecutor} is {@link ImmediateExecutor}, just call {@link Runnable#run()} directly
943-
* instead of using {@link Executor#execute(Runnable)}. Otherwise, run the tasks via
944-
* the {@link #delegatedTaskExecutor} and wait until the tasks are finished.
915+
* Fetches all delegated tasks from the {@link SSLEngine} and runs them by invoking them directly.
945916
*/
946917
private void runDelegatedTasks() {
947-
if (delegatedTaskExecutor == ImmediateExecutor.INSTANCE) {
948-
for (;;) {
949-
Runnable task = engine.getDelegatedTask();
950-
if (task == null) {
951-
break;
952-
}
953-
954-
task.run();
955-
}
956-
} else {
957-
final List<Runnable> tasks = new ArrayList<Runnable>(2);
958-
for (;;) {
959-
final Runnable task = engine.getDelegatedTask();
960-
if (task == null) {
961-
break;
962-
}
963-
964-
tasks.add(task);
965-
}
966-
967-
if (tasks.isEmpty()) {
968-
return;
969-
}
970-
971-
final CountDownLatch latch = new CountDownLatch(1);
972-
delegatedTaskExecutor.execute(new Runnable() {
973-
@Override
974-
public void run() {
975-
try {
976-
for (Runnable task: tasks) {
977-
task.run();
978-
}
979-
} catch (Exception e) {
980-
ctx.fireExceptionCaught(e);
981-
} finally {
982-
latch.countDown();
983-
}
984-
}
985-
});
986-
987-
boolean interrupted = false;
988-
while (latch.getCount() != 0) {
989-
try {
990-
latch.await();
991-
} catch (InterruptedException e) {
992-
// Interrupt later.
993-
interrupted = true;
994-
}
918+
for (;;) {
919+
Runnable task = engine.getDelegatedTask();
920+
if (task == null) {
921+
break;
995922
}
996923

997-
if (interrupted) {
998-
Thread.currentThread().interrupt();
999-
}
924+
task.run();
1000925
}
1001926
}
1002927

testsuite/src/test/java/io/netty/testsuite/transport/socket/SocketSslEchoTest.java

Lines changed: 6 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@
4040
import java.util.Collection;
4141
import java.util.List;
4242
import java.util.Random;
43-
import java.util.concurrent.ExecutorService;
44-
import java.util.concurrent.Executors;
4543
import java.util.concurrent.atomic.AtomicBoolean;
4644
import java.util.concurrent.atomic.AtomicReference;
4745

@@ -58,29 +56,21 @@ public class SocketSslEchoTest extends AbstractSocketTest {
5856
random.nextBytes(data);
5957
}
6058

61-
@Parameters(name = "{index}: " +
62-
"serverUsesDelegatedTaskExecutor = {0}, clientUsesDelegatedTaskExecutor = {1}, " +
63-
"useChunkedWriteHandler = {2}, useCompositeByteBuf = {3}")
59+
@Parameters(name = "{index}: useChunkedWriteHandler = {0}, useCompositeByteBuf = {1}")
6460
public static Collection<Object[]> data() {
6561
List<Object[]> params = new ArrayList<Object[]>();
66-
for (int i = 0; i < 16; i ++) {
62+
for (int i = 0; i < 4; i ++) {
6763
params.add(new Object[] {
68-
(i & 8) != 0, (i & 4) != 0, (i & 2) != 0, (i & 1) != 0
64+
(i & 2) != 0, (i & 1) != 0
6965
});
7066
}
7167
return params;
7268
}
7369

74-
private final boolean serverUsesDelegatedTaskExecutor;
75-
private final boolean clientUsesDelegatedTaskExecutor;
7670
private final boolean useChunkedWriteHandler;
7771
private final boolean useCompositeByteBuf;
7872

79-
public SocketSslEchoTest(
80-
boolean serverUsesDelegatedTaskExecutor, boolean clientUsesDelegatedTaskExecutor,
81-
boolean useChunkedWriteHandler, boolean useCompositeByteBuf) {
82-
this.serverUsesDelegatedTaskExecutor = serverUsesDelegatedTaskExecutor;
83-
this.clientUsesDelegatedTaskExecutor = clientUsesDelegatedTaskExecutor;
73+
public SocketSslEchoTest(boolean useChunkedWriteHandler, boolean useCompositeByteBuf) {
8474
this.useChunkedWriteHandler = useChunkedWriteHandler;
8575
this.useCompositeByteBuf = useCompositeByteBuf;
8676
}
@@ -91,7 +81,6 @@ public void testSslEcho() throws Throwable {
9181
}
9282

9383
public void testSslEcho(ServerBootstrap sb, Bootstrap cb) throws Throwable {
94-
final ExecutorService delegatedTaskExecutor = Executors.newCachedThreadPool();
9584
final EchoHandler sh = new EchoHandler(true, useCompositeByteBuf);
9685
final EchoHandler ch = new EchoHandler(false, useCompositeByteBuf);
9786

@@ -104,11 +93,7 @@ public void testSslEcho(ServerBootstrap sb, Bootstrap cb) throws Throwable {
10493
@Override
10594
@SuppressWarnings("deprecation")
10695
public void initChannel(SocketChannel sch) throws Exception {
107-
if (serverUsesDelegatedTaskExecutor) {
108-
sch.pipeline().addFirst("ssl", new SslHandler(sse, delegatedTaskExecutor));
109-
} else {
110-
sch.pipeline().addFirst("ssl", new SslHandler(sse));
111-
}
96+
sch.pipeline().addFirst("ssl", new SslHandler(sse));
11297
if (useChunkedWriteHandler) {
11398
sch.pipeline().addLast(new ChunkedWriteHandler());
11499
}
@@ -120,11 +105,7 @@ public void initChannel(SocketChannel sch) throws Exception {
120105
@Override
121106
@SuppressWarnings("deprecation")
122107
public void initChannel(SocketChannel sch) throws Exception {
123-
if (clientUsesDelegatedTaskExecutor) {
124-
sch.pipeline().addFirst("ssl", new SslHandler(cse, delegatedTaskExecutor));
125-
} else {
126-
sch.pipeline().addFirst("ssl", new SslHandler(cse));
127-
}
108+
sch.pipeline().addFirst("ssl", new SslHandler(cse));
128109
if (useChunkedWriteHandler) {
129110
sch.pipeline().addLast(new ChunkedWriteHandler());
130111
}
@@ -186,7 +167,6 @@ public void initChannel(SocketChannel sch) throws Exception {
186167
sh.channel.close().awaitUninterruptibly();
187168
ch.channel.close().awaitUninterruptibly();
188169
sc.close().awaitUninterruptibly();
189-
delegatedTaskExecutor.shutdown();
190170

191171
if (sh.exception.get() != null && !(sh.exception.get() instanceof IOException)) {
192172
throw sh.exception.get();

0 commit comments

Comments
 (0)