01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: *
17: */
18: package org.apache.ivy.plugins.resolver;
19:
20: import java.net.URL;
21:
22: import org.apache.ivy.util.url.URLHandler;
23: import org.apache.ivy.util.url.URLHandlerRegistry;
24:
25: /**
26: * TODO write javadoc
27: */
28: public class IBiblioHelper {
29: private static boolean _checked = false;
30:
31: private static String _mirror = null;
32:
33: private static URLHandler handler = URLHandlerRegistry.getHttp();
34:
35: public static String getIBiblioMirror() throws Exception {
36: if (!_checked) {
37: String[] mirrors = new String[] {
38: "http://repo1.maven.org/maven/REPOSITORY-V1.txt",
39: "http://mirrors.sunsite.dk/maven",
40: "http://public.planetmirror.com/pub/maven",
41: "http://www.ibiblio.org/maven" };
42: String[] mirrorsRoot = new String[] {
43: "http://repo1.maven.org/maven",
44: "http://mirrors.sunsite.dk/maven",
45: "http://public.planetmirror.com/pub/maven",
46: "http://www.ibiblio.org/maven" };
47:
48: long best = -1;
49: for (int i = 0; i < mirrors.length; i++) {
50: long start = System.currentTimeMillis();
51: if (handler.isReachable(new URL(mirrors[i]), 300)) {
52: long took = System.currentTimeMillis() - start;
53: System.out.println("reached " + mirrors[i] + " in "
54: + took + "ms");
55: if (best == -1 || took < best) {
56: best = took;
57: _mirror = mirrorsRoot[i];
58: if (took < 400) {
59: // this mirror is good enough
60: break;
61: }
62: }
63: }
64: }
65: if (_mirror == null) {
66: System.out
67: .println("No ibiblio mirror available: no ibiblio test done");
68: }
69: }
70: return _mirror;
71: }
72:
73: public static void main(String[] args) throws Exception {
74: long start = System.currentTimeMillis();
75: String biblioMirror = getIBiblioMirror();
76: System.out.println("best mirror is " + biblioMirror
77: + " - found in " + (System.currentTimeMillis() - start)
78: + "ms");
79: }
80:
81: }
|