1 4 package com.tc.net; 5 6 import com.tc.util.runtime.Os; 7 8 import java.io.IOException ; 9 import java.util.Properties ; 10 import java.util.regex.Matcher ; 11 import java.util.regex.Pattern ; 12 13 public class NIOWorkarounds { 14 15 private NIOWorkarounds() { 16 } 18 19 public static boolean windowsWritevWorkaround(IOException ioe) { 20 final String err = ioe.getMessage(); 21 if (null != err) { 22 if (err.equals("A non-blocking socket operation could not be completed immediately")) { 25 if (Os.isWindows()) { return true; } 26 } 27 } 28 29 return false; 30 } 31 32 public static boolean linuxSelectWorkaround(IOException ioe) { 33 36 if (Os.isLinux()) { 37 String msg = ioe.getMessage(); 38 if ("Interrupted system call".equals(msg)) { return true; } 39 } 40 41 return false; 42 } 43 44 public static void solaris10Workaround() { 45 boolean workaround = solaris10Workaround(System.getProperties()); 46 if (workaround) { 47 String prev = System.getProperty("java.nio.channels.spi.SelectorProvider"); 48 System.setProperty("java.nio.channels.spi.SelectorProvider", "sun.nio.ch.PollSelectorProvider"); 49 50 String msg = "\nWARNING: Terracotta is forcing the use of poll based NIO selector to workaround Sun bug 6322825\n"; 51 if (prev != null) { 52 msg += "This overrides the previous value of " + prev + "\n"; 53 } 54 System.err.println(msg.toString()); 55 } 56 } 57 58 63 static boolean solaris10Workaround(Properties props) { 64 String vendor = props.getProperty("java.vendor", ""); 65 String osName = props.getProperty("os.name", ""); 66 String osVersion = props.getProperty("os.version", ""); 67 String javaVersion = props.getProperty("java.version", ""); 68 69 if (vendor.toLowerCase().startsWith("sun") && "SunOS".equals(osName) && "5.10".equals(osVersion)) { 70 if (javaVersion.matches("^1\\.[12345]\\..*")) { Pattern p = Pattern.compile("^1\\.5\\.0_(\\d\\d)$"); 73 Matcher m = p.matcher(javaVersion); 74 if (m.matches()) { 75 String minorRev = m.group(1); 76 int ver = Integer.parseInt(minorRev); 77 if (ver >= 8) { return false; } 78 } 79 80 return true; 81 } 82 } 83 return false; 84 } 85 86 public static boolean selectorOpenRace(NullPointerException npe) { 88 StackTraceElement source = npe.getStackTrace()[0]; 89 if (source.getClassName().equals("sun.nio.ch.Util") && source.getMethodName().equals("atBugLevel")) { return true; } 90 return false; 91 } 92 93 public static void main(String args[]) { 94 NIOWorkarounds.solaris10Workaround(); 95 } 96 97 } 98 | Popular Tags |