[rfc][icedtea-web] Refactor initializeResources in ResourceDownloader

Jie Kang jkang at redhat.com
Tue Feb 10 18:47:42 UTC 2015


Hello,


After the lengthy discussion in the thread for "[rfc][icedtea-web] Check online detection even if checked before", I present another solution.

The initializeResources method is refactored to incorporate online/offline more explicitly and the JNLPRuntime has a new method 'isConnectable(URL)' that is used to determine whether or not a connection can be made to the host of a supplied URL. The previous functionality of IT-W's online/offline system is maintained with no functional changes to the other methods in JNLPRuntime.

Important bits:

    private void initializeResource() {
        if (!JNLPRuntime.isOfflineForced() && JNLPRuntime.isConnectable(resource.getLocation())) {
            initializeOnlineResource();
        } else {
            initializeOfflineResource();
        }
    }

This new initial method makes it very clear what's going to happen. Rather than using JNLPRuntime.detectOnline && JNLPRuntime.isOnline, we now use the new JNLPRuntime.isConnectable. The code within these methods is basically the same as the code within the old initializeResource, just copy-pasted into appropriate section.

    public static void detectOnline(URL location) {
        if (onlineDetected != null) {
            return;
        }

        JNLPRuntime.setOnlineDetected(isConnectable(location));
    }

    public static boolean isConnectable(URL location) {
        if (location.getProtocol().equals("file")) {
            return true;
        }

        try {
            OutputController.getLogger().log(OutputController.Level.ERROR_ALL, "The host of " + location.toExternalForm() + " file should be located seems down, or you are simply offline.");
            InetAddress.getByName(location.getHost());
        } catch (UnknownHostException e) {
            return false;
        }

        return true;
    }

Note that detectOnline has been refactored to call isConnectable. The functionality is the same though as 'isConnectable' is copy-pasted code from the original detectOnline.


So end-result is that the original framework still exists and is the same. The part that was broken for ResourceTracker has been fixed using the refactored 'initializeResource' along with the 'isConnectable' method.

Thoughts?



Regards,

-- 

Jie Kang

OpenJDK Team - Software Engineering Intern
-------------- next part --------------
A non-text attachment was scrubbed...
Name: itw-res-init-refactor-1.patch
Type: text/x-patch
Size: 10273 bytes
Desc: not available
URL: <http://mail.openjdk.java.net/pipermail/distro-pkg-dev/attachments/20150210/661d48bb/itw-res-init-refactor-1.patch>


More information about the distro-pkg-dev mailing list