try
{
jqmlogger.debug(f.getPath());
jqmlogger.debug("Working Directory = " + System.getProperty("user.dir"));
Queue q;
if (f == null || !f.isFile())
{
throw new FileNotFoundException("The XML file " + f + " was not found");
}
dBuilder = dbFactory.newDocumentBuilder();
Document doc = dBuilder.parse(f);
doc.getDocumentElement().normalize();
NodeList nList = doc.getElementsByTagName("jqm");
// Get the information about the queue
for (int temp = 0; temp < nList.getLength(); temp++)
{
Node nNode = nList.item(temp);
if (nNode.getNodeType() == Node.ELEMENT_NODE)
{
Element e = (Element) nNode;
NodeList nl = e.getElementsByTagName("queue");
for (int i = 0; i < nl.getLength(); i++)
{
Element ee = (Element) nl.item(i);
name = ee.getElementsByTagName("name").item(0).getTextContent();
description = ee.getElementsByTagName("description").item(0).getTextContent();
if (ee.getElementsByTagName("timeToLive").getLength() == 1)
{
timeToLive = ee.getElementsByTagName("timeToLive").item(0).getTextContent();
}
else
{
timeToLive = "0";
}
jqmlogger.debug("Name: " + name);
jqmlogger.debug("Description: " + description);
jqmlogger.debug("maxTempInQueue: " + timeToLive);
// The list must be purged
jobs.clear();
NodeList l = ee.getElementsByTagName("applicationName");
jqmlogger.debug(l.getLength());
for (int j = 0; j < l.getLength(); j++)
{
Element t = (Element) l.item(j);
jqmlogger.debug("Default queue of the job " + t.getTextContent() + " must be changed");
jobs.add(t.getTextContent());
}
// We must check if the queue already exist and add it
try
{
q = em.createQuery("SELECT q FROM Queue q WHERE q.name = :n", Queue.class).setParameter("n", name)
.getSingleResult();
jqmlogger.info("The queue " + name + "already exists. It will be overriden");
q.setDescription(description);
q.setTimeToLive(Integer.parseInt(timeToLive));
}
catch (NonUniqueResultException s)
{
jqmlogger.warn("Queue " + name + " is non unique. The admin must change the queue configurations");
}
catch (NoResultException ss)
{
jqmlogger.debug("The queue will be created");
em.getTransaction().begin();
Queue queue = new Queue();
queue.setDefaultQueue(false);
queue.setDescription(description);
queue.setTimeToLive(Integer.parseInt(timeToLive));
queue.setName(name);
em.persist(queue);
em.getTransaction().commit();
}
for (String n : jobs)
{
jqmlogger.debug("The jobs will be changed");
try
{
JobDef j = em.createQuery("SELECT j FROM JobDef j WHERE j.applicationName = :n", JobDef.class)
.setParameter("n", n).getSingleResult();
Queue queue = em.createQuery("SELECT q FROM Queue q WHERE q.name = :n", Queue.class)
.setParameter("n", name).getSingleResult();
em.getTransaction().begin();
j.setQueue(queue);
em.getTransaction().commit();
jqmlogger.debug("New configurations applied");