Search in sources :

Example 1 with ResourceListing

use of net.sourceforge.processdash.tool.bridge.ResourceListing in project processdash by dtuma.

the class XmlCollectionListing method parseListing.

public static ResourceCollectionInfo parseListing(InputStream in) throws IOException {
    try {
        Element data = XMLUtils.parse(in).getDocumentElement();
        ResourceListing result = new ResourceListing();
        NodeList resourceElems = data.getElementsByTagName(RESOURCE_TAG);
        if (resourceElems != null) {
            for (int i = 0; i < resourceElems.getLength(); i++) {
                Element res = (Element) resourceElems.item(i);
                String name = res.getAttribute(NAME_ATTR);
                long mod = Long.parseLong(res.getAttribute(MOD_TIME_ATTR));
                long sum = Long.parseLong(res.getAttribute(CHECKSUM_ATTR));
                result.addResource(name, mod, sum);
            }
        }
        return result;
    } catch (Exception e) {
        IOException ioe = new IOException("Unable to parse collection listing");
        ioe.initCause(e);
        throw ioe;
    }
}
Also used : ResourceListing(net.sourceforge.processdash.tool.bridge.ResourceListing) Element(org.w3c.dom.Element) NodeList(org.w3c.dom.NodeList) IOException(java.io.IOException) IOException(java.io.IOException)

Example 2 with ResourceListing

use of net.sourceforge.processdash.tool.bridge.ResourceListing in project processdash by dtuma.

the class ResourceBridgeClient method getDiff.

private ResourceCollectionDiff getDiff() throws IOException {
    // start by initiating the HTTP connection to the server
    URLConnection conn = makeGetRequest(LIST_ACTION);
    conn.connect();
    // now, while the server is thinking, do our calculations locally.
    localCollection.validate();
    ResourceCollectionInfo localList = new ResourceListing(localCollection, ResourceFilterFactory.DEFAULT_FILTER);
    // finally, retrieve the list from the server and compare the two.
    serverVersion = conn.getHeaderField(VERSION_HEADER);
    ResourceCollectionInfo remoteList = XmlCollectionListing.parseListing(new BufferedInputStream(conn.getInputStream()));
    return new ResourceCollectionDiff(localList, remoteList);
}
Also used : ResourceCollectionInfo(net.sourceforge.processdash.tool.bridge.ResourceCollectionInfo) ResourceListing(net.sourceforge.processdash.tool.bridge.ResourceListing) ResourceCollectionDiff(net.sourceforge.processdash.tool.bridge.report.ResourceCollectionDiff) BufferedInputStream(java.io.BufferedInputStream) HttpURLConnection(java.net.HttpURLConnection) URLConnection(java.net.URLConnection)

Example 3 with ResourceListing

use of net.sourceforge.processdash.tool.bridge.ResourceListing in project processdash by dtuma.

the class BridgedWorkingDirectory method syncTimestampIsRecent.

private boolean syncTimestampIsRecent() {
    try {
        String timestamp = getMetadata(SYNC_TIMESTAMP);
        if (timestamp == null)
            return false;
        ResourceFilter filter = ResourceFilterFactory.getForRequest(Collections.singletonMap(ResourceFilterFactory.LAST_MOD_PARAM, timestamp));
        ResourceCollectionInfo changedFiles = new ResourceListing(client.localCollection, filter);
        return changedFiles.listResourceNames().isEmpty();
    } catch (Exception e) {
        return false;
    }
}
Also used : ResourceFilter(net.sourceforge.processdash.tool.bridge.ResourceFilter) ResourceCollectionInfo(net.sourceforge.processdash.tool.bridge.ResourceCollectionInfo) ResourceListing(net.sourceforge.processdash.tool.bridge.ResourceListing) LockFailureException(net.sourceforge.processdash.util.lock.LockFailureException) LockUncertainException(net.sourceforge.processdash.util.lock.LockUncertainException) OfflineLockLostException(net.sourceforge.processdash.util.lock.OfflineLockLostException) IOException(java.io.IOException) AlreadyLockedException(net.sourceforge.processdash.util.lock.AlreadyLockedException)

Aggregations

ResourceListing (net.sourceforge.processdash.tool.bridge.ResourceListing)3 IOException (java.io.IOException)2 ResourceCollectionInfo (net.sourceforge.processdash.tool.bridge.ResourceCollectionInfo)2 BufferedInputStream (java.io.BufferedInputStream)1 HttpURLConnection (java.net.HttpURLConnection)1 URLConnection (java.net.URLConnection)1 ResourceFilter (net.sourceforge.processdash.tool.bridge.ResourceFilter)1 ResourceCollectionDiff (net.sourceforge.processdash.tool.bridge.report.ResourceCollectionDiff)1 AlreadyLockedException (net.sourceforge.processdash.util.lock.AlreadyLockedException)1 LockFailureException (net.sourceforge.processdash.util.lock.LockFailureException)1 LockUncertainException (net.sourceforge.processdash.util.lock.LockUncertainException)1 OfflineLockLostException (net.sourceforge.processdash.util.lock.OfflineLockLostException)1 Element (org.w3c.dom.Element)1 NodeList (org.w3c.dom.NodeList)1