Example usage for io.netty.util.internal PlatformDependent getClassLoader

List of usage examples for io.netty.util.internal PlatformDependent getClassLoader

Introduction

In this page you can find the example usage for io.netty.util.internal PlatformDependent getClassLoader.

Prototype

public static ClassLoader getClassLoader(final Class<?> clazz) 

Source Link

Document

Return the ClassLoader for the given Class .

Usage

From source file:divconq.net.ssl.SslHandler.java

License:Apache License

private boolean ignoreException(Throwable t) {
    if (!(t instanceof SSLException) && t instanceof IOException && sslCloseFuture.isDone()) {
        String message = String.valueOf(t.getMessage()).toLowerCase();

        // first try to match connection reset / broke peer based on the regex. This is the fastest way
        // but may fail on different jdk impls or OS's
        if (IGNORABLE_ERROR_MESSAGE.matcher(message).matches()) {
            return true;
        }//from  www  .j av  a2 s  .c  o  m

        // Inspect the StackTraceElements to see if it was a connection reset / broken pipe or not
        StackTraceElement[] elements = t.getStackTrace();
        for (StackTraceElement element : elements) {
            String classname = element.getClassName();
            String methodname = element.getMethodName();

            // skip all classes that belong to the io.netty package
            if (classname.startsWith("io.netty.")) {
                continue;
            }

            // check if the method name is read if not skip it
            if (!"read".equals(methodname)) {
                continue;
            }

            // This will also match against SocketInputStream which is used by openjdk 7 and maybe
            // also others
            if (IGNORABLE_CLASS_IN_STACK.matcher(classname).matches()) {
                return true;
            }

            try {
                // No match by now.. Try to load the class via classloader and inspect it.
                // This is mainly done as other JDK implementations may differ in name of
                // the impl.
                Class<?> clazz = PlatformDependent.getClassLoader(getClass()).loadClass(classname);

                if (SocketChannel.class.isAssignableFrom(clazz)
                        || DatagramChannel.class.isAssignableFrom(clazz)) {
                    return true;
                }

                // also match against SctpChannel via String matching as it may not present.
                if (PlatformDependent.javaVersion() >= 7
                        && "com.sun.nio.sctp.SctpChannel".equals(clazz.getSuperclass().getName())) {
                    return true;
                }
            } catch (ClassNotFoundException e) {
                // This should not happen just ignore
            }
        }
    }

    return false;
}