1 6 package fr.jayasoft.ivy.resolver; 7 8 import java.net.URL ; 9 10 import fr.jayasoft.ivy.url.URLHandler; 11 import fr.jayasoft.ivy.url.URLHandlerRegistry; 12 13 16 public class IBiblioHelper { 17 private static boolean _checked = false; 18 private static String _mirror = null; 19 private static URLHandler handler = URLHandlerRegistry.getHttp(); 20 public static String getIBiblioMirror() throws Exception { 21 String [] mirrors = new String [] { 29 "http://ftp.up.ac.za/pub/linux/maven", 30 "http://mirrors.sunsite.dk/maven", 31 "http://public.planetmirror.com/pub/maven", 32 "http://www.ibiblio.org/maven" 33 }; 34 String [] mirrorsRoot = new String [] { 35 "http://ftp.up.ac.za/pub/linux/maven", 36 "http://mirrors.sunsite.dk/maven", 37 "http://public.planetmirror.com/pub/maven", 38 "http://www.ibiblio.org/maven" 39 }; 40 if (!_checked) { 41 long best = -1; 42 for (int i = 0; i < mirrors.length; i++) { 43 long start = System.currentTimeMillis(); 44 if (handler.isReachable(new URL (mirrors[i]), 300)) { 45 long took = System.currentTimeMillis() - start; 46 System.out.println("reached "+mirrors[i]+" in "+took+"ms"); 47 if (best == -1 || took < best) { 48 best = took; 49 _mirror = mirrorsRoot[i]; 50 } 51 } 52 } 53 if (_mirror == null) { 54 System.out.println("No ibiblio mirror available: no ibiblio test done"); 55 } 56 } 57 return _mirror; 58 } 59 60 public static void main(String [] args) throws Exception { 61 long start = System.currentTimeMillis(); 62 String biblioMirror = getIBiblioMirror(); 63 System.out.println("best mirror is "+biblioMirror+ " - found in "+(System.currentTimeMillis() - start)+"ms"); 64 } 65 66 } 67 | Popular Tags |