Logo Search packages:      
Sourcecode: icedtea-web version File versions  Download package

void net::sourceforge::jnlp::cache::ResourceTracker::initializeResource ( Resource  resource  )  [inline, private]

Open a URL connection and get the content length and other fields.

Definition at line 730 of file ResourceTracker.java.

References net::sourceforge::jnlp::cache::Resource::changeStatus(), net::sourceforge::jnlp::cache::Resource::downloadVersion, net::sourceforge::jnlp::cache::Resource::fireDownloadEvent(), net::sourceforge::jnlp::cache::UpdatePolicy::FORCE, net::sourceforge::jnlp::cache::Resource::getUpdatePolicy(), getVersionedResourceURL(), net::sourceforge::jnlp::cache::CacheEntry::initialize(), net::sourceforge::jnlp::cache::Resource::localFile, net::sourceforge::jnlp::cache::Resource::location, lock, net::sourceforge::jnlp::cache::Resource::requestVersion, net::sourceforge::jnlp::cache::CacheEntry::setLastUpdated(), net::sourceforge::jnlp::cache::Resource::size, and net::sourceforge::jnlp::cache::CacheEntry::store().

Referenced by processResource().

                                                       {
        resource.fireDownloadEvent(); // fire CONNECTING

        try {
            File localFile = CacheUtil.getCacheFile(resource.location, resource.downloadVersion);

            // connect
            URLConnection connection = getVersionedResourceURL(resource).openConnection(); // this won't change so should be okay unsynchronized
            connection.addRequestProperty("Accept-Encoding", "pack200-gzip, gzip");

            int size = connection.getContentLength();
            boolean current = CacheUtil.isCurrent(resource.location, resource.requestVersion, connection) && resource.getUpdatePolicy() != UpdatePolicy.FORCE;

            synchronized(resource) {
                resource.localFile = localFile;
                // resource.connection = connection;
                resource.size = size;
                resource.changeStatus(CONNECT|CONNECTING, CONNECTED);

                // check if up-to-date; if so set as downloaded
                if (current)
                    resource.changeStatus(DOWNLOAD|DOWNLOADING, DOWNLOADED);
            }

            // update cache entry
            CacheEntry entry = new CacheEntry(resource.location, resource.requestVersion);
            if (!current)
                entry.initialize(connection);

            entry.setLastUpdated(System.currentTimeMillis());
            entry.store();

            synchronized(lock) {
                lock.notifyAll(); // wake up wait's to check for completion
            }
            resource.fireDownloadEvent(); // fire CONNECTED

            // explicitly close the URLConnection.
                        if (connection instanceof HttpURLConnection)
                ((HttpURLConnection)connection).disconnect();
        }
        catch (Exception ex) {
            if (JNLPRuntime.isDebug())
                ex.printStackTrace();

            resource.changeStatus(0, ERROR);
            synchronized(lock) {
                lock.notifyAll(); // wake up wait's to check for completion
            }
            resource.fireDownloadEvent(); // fire ERROR
        }
    }


Generated by  Doxygen 1.6.0   Back to index