All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.daisy.pipeline.client.models.JobQueue Maven / Gradle / Ivy

There is a newer version: 5.0.1
Show newest version
package org.daisy.pipeline.client.models;

import java.util.ArrayList;
import java.util.List;

import org.daisy.pipeline.client.Pipeline2Logger;
import org.daisy.pipeline.client.utils.XPath;
import org.w3c.dom.Document;
import org.w3c.dom.Node;

/**
 * A representation of the "/queue" response from the Pipeline 2 Web Service.
 * 
 * Example XML:
 * {@code
 * 
 * 
 *     
 *     
 *     
 *     
 *     
 *     
 * 
 * }
 */
public class JobQueue {
	
	public enum Priority { LOW, MEDIUM, HIGH };
	
	public class QueuedJob {
		String id; // "464c72f9-ed59-44ff-8b7b-207abb4add7f"
		String href; // "http://localhost:8181/ws/jobs/464c72f9-ed59-44ff-8b7b-207abb4add7f"
		Double computedPriority; // "-43.333333333333336"
		Priority jobPriority; // "medium"
		Priority clientPriority; // "medium"
		Double relativeTime; // "1.0"
		Long timestamp; // "1398930862759"
		String moveUp; // "http://localhost:8181/ws/queue/up/464c72f9-ed59-44ff-8b7b-207abb4add7f"
		String moveDown; // "http://localhost:8181/ws/queue/down/464c72f9-ed59-44ff-8b7b-207abb4add7f"
	}
	
	public String href;
	public List queue;
    
	public JobQueue(Node queueNode) {
		queue = new ArrayList();
		
		try {
			// select root element if the node is a document node
			if (queueNode instanceof Document)
				queueNode = XPath.selectNode("/d:jobs", queueNode, XPath.dp2ns);

			List queuedJobNodes = XPath.selectNodes("d:job", queueNode, XPath.dp2ns);
			for (Node queuedJobNode : queuedJobNodes) {
				QueuedJob queuedJob = new QueuedJob();
				queuedJob.id = XPath.selectText("@id", queuedJobNode, XPath.dp2ns);
				queuedJob.href = XPath.selectText("@href", queuedJobNode, XPath.dp2ns);
				queuedJob.computedPriority = Double.valueOf(XPath.selectText("@computedPriority", queuedJobNode, XPath.dp2ns));
				queuedJob.jobPriority = Priority.valueOf(XPath.selectText("@jobPriority", queuedJobNode, XPath.dp2ns));
				queuedJob.clientPriority = Priority.valueOf(XPath.selectText("@clientPriority", queuedJobNode, XPath.dp2ns));
				queuedJob.relativeTime = Double.valueOf(XPath.selectText("@relativeTime", queuedJobNode, XPath.dp2ns));
				queuedJob.timestamp = Long.valueOf(XPath.selectText("@timestamp", queuedJobNode, XPath.dp2ns));
				queuedJob.moveUp = XPath.selectText("@moveUp", queuedJobNode, XPath.dp2ns);
				queuedJob.moveDown = XPath.selectText("@moveDown", queuedJobNode, XPath.dp2ns);
				queue.add(queuedJob);
			}
			
		} catch (Exception e) {
			Pipeline2Logger.logger().error("Failed to parse the job queue XML", e);
		}
	}
	
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy