public void run() { try { tt.execute(this); } catch (Exception e) { handleException(e); } finally { latch.countDown(); } }
public void poll() throws Exception { TransactionTemplate tt = new TransactionTemplate( endpoint.getTransactionConfig(), connector.getExceptionListener(), connector.getManagementContext()); if (this.isReceiveMessagesInTransaction()) { // Receive messages and process them in a single transaction // Do not enable threading here, but several workers // may have been started TransactionCallback cb = new TransactionCallback() { public Object doInTransaction() throws Exception { List messages = getMessages(); if (messages != null && messages.size() > 0) { for (Iterator it = messages.iterator(); it.hasNext(); ) { TransactedPollingMessageReceiver.this.processMessage(it.next()); } } return null; } }; tt.execute(cb); } else { // Receive messages and launch a worker for each message List messages = getMessages(); if (messages != null && messages.size() > 0) { final CountDownLatch countdown = new CountDownLatch(messages.size()); for (Iterator it = messages.iterator(); it.hasNext(); ) { try { this.getWorkManager() .scheduleWork(new MessageProcessorWorker(tt, countdown, it.next())); } catch (Exception e) { countdown.countDown(); throw e; } } countdown.await(); } } }