/** * Called when a new submission message is received. Unpacks the job data and sends the * information as a SubmissionData to a JobSubmitter for bridging into the Heritrix submission * system. */ public synchronized void onMessage(Message msg) { if (msg instanceof MapMessage) { UrlSubmissionMsg subMsg = new UrlSubmissionMsg((MapMessage) msg); try { if (!subMsg.validate()) { throw new JMSException("Invalid UrlSubmissionMsg"); } SubmissionData data = new SubmissionData(); data.setMetaName(subMsg.getJobID()); data.setSeeds(subMsg.getUrl()); data.setJobDescription(subMsg.getDescription()); CrawlJob job = jobSubmitter.submit(data); JobFinishedListener listener = new JobFinishedListener(data, msg, this); inProcess = true; handler.addJob(job); CrawlController controller = job.getController(); // This sucks, but an alternative would require heavy hacking. while (controller == null) { Thread.sleep(50); controller = job.getController(); } controller.addCrawlStatusListener(listener); sendJobStarted(subMsg.getJobID(), subMsg.getUrl()); // Only take one message at a time. while (inProcess) { try { this.wait(); if (!inProcess) { break; } } catch (InterruptedException e) { } } } catch (JMSException e) { e.printStackTrace(); } catch (Exception e) { // Submission went awry e.printStackTrace(); } } } // - onMessage