com.limegroup.gnutella.util
Class URLOpener

java.lang.Object
  extended bycom.limegroup.gnutella.util.URLOpener

public class URLOpener
extends java.lang.Object

Opens a Java URLConnection with a bounded timeout. Typical use:

    try {
        URLConnection url=(new URLOpener(host, port)).connect(timeout);
    } catch (IOException e) {
        System.out.println("Couldn't connect in time.");
    }
 
This is basically a hack to work around limitations in the URL/URLConnection classes. It is implemented with an extra thread much like SocketOpener. That means frequent calls to this may result in numerous threads waiting to die. The next release of Java ("Merlin") will have timeouts on connect, so this won't be needed.

This class is currently NOT thread safe. Currently connect() can only be called once.


Constructor Summary
URLOpener(java.net.URL url)
          Creates a URLOpener that will open the given url when connect is called.
 
Method Summary
 java.net.URLConnection connect(int timeout)
          Returns a new URLConnection to this' url.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

URLOpener

public URLOpener(java.net.URL url)
Creates a URLOpener that will open the given url when connect is called.

Method Detail

connect

public java.net.URLConnection connect(int timeout)
                               throws java.io.IOException
Returns a new URLConnection to this' url. If the connection couldn't be established within timeout milliseconds, throws IOException. If timeout==0, no timeout occurs. If this thread is interrupted while making the connection, throws IOException.

Throws:
java.io.IOException