diff --git a/testsuite/src/test/java/io/netty/testsuite/transport/socket/SocketTestPermutation.java b/testsuite/src/test/java/io/netty/testsuite/transport/socket/SocketTestPermutation.java index 2eabc7a89c..af6cd01976 100644 --- a/testsuite/src/test/java/io/netty/testsuite/transport/socket/SocketTestPermutation.java +++ b/testsuite/src/test/java/io/netty/testsuite/transport/socket/SocketTestPermutation.java @@ -35,8 +35,10 @@ import io.netty.channel.socket.oio.OioServerSocketChannel; import io.netty.channel.socket.oio.OioSctpServerChannel; import io.netty.channel.socket.oio.OioSocketChannel; import io.netty.channel.socket.oio.OioSctpChannel; +import io.netty.testsuite.util.TestUtils; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.Map.Entry; @@ -239,8 +241,11 @@ final class SocketTestPermutation { } static List> sctpServerChannel() { - List> list = new ArrayList>(); + if (!TestUtils.isSctpSupported()) { + return Collections.emptyList(); + } + List> list = new ArrayList>(); // Make the list of ServerBootstrap factories. list.add(new Factory() { @Override @@ -250,6 +255,8 @@ final class SocketTestPermutation { channel(NioSctpServerChannel.class); } }); + /* + * Comment out till #632 is fixes list.add(new Factory() { @Override public ServerBootstrap newInstance() { @@ -258,11 +265,16 @@ final class SocketTestPermutation { channel(OioSctpServerChannel.class); } }); + */ return list; } static List> sctpClientChannel() { + if (!TestUtils.isSctpSupported()) { + return Collections.emptyList(); + } + List> list = new ArrayList>(); list.add(new Factory() { @Override @@ -270,12 +282,15 @@ final class SocketTestPermutation { return new Bootstrap().group(new NioEventLoopGroup()).channel(NioSctpChannel.class); } }); - list.add(new Factory() { + /* + * Comment out till #632 is fixes + * list.add(new Factory() { @Override public Bootstrap newInstance() { return new Bootstrap().group(new OioEventLoopGroup()).channel(OioSctpChannel.class); } }); + */ return list; } diff --git a/transport/src/main/java/io/netty/channel/socket/aio/MethodHandleAioChannelFinder.java b/transport/src/main/java/io/netty/channel/socket/aio/MethodHandleAioChannelFinder.java deleted file mode 100644 index b4d8b593be..0000000000 --- a/transport/src/main/java/io/netty/channel/socket/aio/MethodHandleAioChannelFinder.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Copyright 2012 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package io.netty.channel.socket.aio; - -import java.lang.invoke.MethodHandle; -import java.lang.invoke.MethodHandles; -import java.lang.reflect.Field; -import java.util.HashMap; -import java.util.Map; - -public class MethodHandleAioChannelFinder implements AioChannelFinder { - private static volatile Map, MethodHandle> handleCache = new HashMap, MethodHandle>(); - - @Override - public AbstractAioChannel findChannel(Runnable command) throws Exception { - MethodHandle handle; - for (;;) { - handle = findHandle(command); - if (handle == null) { - return null; - } - Object next; - try { - next = handle.invokeExact(); - } catch (Throwable e) { - e.printStackTrace(); - throw new Exception("Unable to invoke handle " + handle, e); - } - if (next instanceof AbstractAioChannel) { - return (AbstractAioChannel) next; - } - command = (Runnable) next; - } - } - - private static MethodHandle findHandle(Object command) throws Exception { - Map, MethodHandle> handleCache = MethodHandleAioChannelFinder.handleCache; - Class commandType = command.getClass(); - MethodHandle res = handleCache.get(commandType); - if (res != null) { - return res; - } - - for (Field f: commandType.getDeclaredFields()) { - if (f.getType() == Runnable.class) { - return put(handleCache, commandType, f); - } - - // Check against the actual class as this is what will be used by the jdk - // if you use a final variable and pass it to a Runnable - if (f.getType().isAssignableFrom(AbstractAioChannel.class) - || f.getType() == Object.class) { - f.setAccessible(true); - Object candidate = f.get(command); - if (candidate instanceof AbstractAioChannel) { - return put(handleCache, commandType, f); - } - } - } - return null; - } - - private static MethodHandle put(Map, MethodHandle> oldCache, Class key, Field value) throws Exception { - MethodHandle handle = MethodHandles.lookup().findGetter(key, value.getName(), value.getType()); - Map, MethodHandle> newCache = new HashMap, MethodHandle>(oldCache.size()); - newCache.putAll(oldCache); - newCache.put(key, handle); - handleCache = newCache; - return handle; - } -}