public void delete() throws MailQueueException { try { FileUtils.forceDelete(new File(getObjectFile())); } catch (IOException e) { throw new MailQueueException("Unable to delete mail"); } try { FileUtils.forceDelete(new File(getMessageFile())); } catch (IOException e) { LOGGER.debug("Remove of msg file for mail failed"); } } }
@Override public void done(boolean success) throws MailQueueException { if (!success) { try { inmemoryQueue.put(key); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new MailQueueException("Unable to rollback", e); } } else { fitem.delete(); keyMappings.remove(key); } LifecycleUtil.dispose(mail); } };
throw new MailQueueException("Unable to enqueue mail", e);
throw new MailQueueException("Unable to remove mails", e);
throw new MailQueueException("Unable to dequeue", e); throw new MailQueueException("Unable to dequeue", e);
closeConsumer(consumer); closeSession(session); throw new MailQueueException("Unable to dequeue next message", e); } finally { timeMetric.stopAndPublish();
throw new MailQueueException("Unable to browse queue " + queueName, e);
throw new MailQueueException("Unable to get size of queue " + queueName, e);
throw new MailQueueException("Unable to remove mails", e);
/** * TODO: implement me */ @Override public long remove(Type type, String value) throws MailQueueException { switch (type) { case Name: FileItem item = keyMappings.remove(value); if (item != null) { item.delete(); return 1; } else { return 0; } default: break; } throw new MailQueueException("Not supported yet"); }
@Override public void enQueue(Mail mail, long delay, TimeUnit unit) throws MailQueueException { TimeMetric timeMetric = metricFactory.timer(ENQUEUED_TIMER_METRIC_NAME_PREFIX + queueName); long nextDeliveryTimestamp = computeNextDeliveryTimestamp(delay, unit); try { int msgPrio = NORMAL_PRIORITY; Object prio = mail.getAttribute(MAIL_PRIORITY); if (prio instanceof Integer) { msgPrio = (Integer) prio; } Map<String, Object> props = getJMSProperties(mail, nextDeliveryTimestamp); produceMail(props, msgPrio, mail); enqueuedMailsMetric.increment(); } catch (Exception e) { throw new MailQueueException("Unable to enqueue mail " + mail, e); } finally { timeMetric.stopAndPublish(); } }
@Override protected void populateMailMimeMessage(Message message, Mail mail) throws MessagingException, JMSException { if (message instanceof BlobMessage) { try { BlobMessage blobMessage = (BlobMessage) message; try { // store URL and queueName for later usage mail.setAttribute(JAMES_BLOB_URL, blobMessage.getURL()); mail.setAttribute(JAMES_QUEUE_NAME, queueName); } catch (MalformedURLException e) { // Ignore on error LOGGER.debug("Unable to get url from blobmessage for mail {}", mail.getName()); } MimeMessageSource source = new MimeMessageBlobMessageSource(blobMessage); mail.setMessage(new MimeMessageCopyOnWriteProxy(source)); } catch (JMSException e) { throw new MailQueueException("Unable to populate MimeMessage for mail " + mail.getName(), e); } } else { super.populateMailMimeMessage(message, mail); } }
/** * Populat the given {@link Mail} instance with a {@link MimeMessage}. The * {@link MimeMessage} is read from the JMS Message. This implementation use * a {@link BytesMessage} * * @param message * @param mail * @throws MessagingException */ protected void populateMailMimeMessage(Message message, Mail mail) throws MessagingException, JMSException { if (message instanceof ObjectMessage) { mail.setMessage(new MimeMessageCopyOnWriteProxy(new MimeMessageObjectMessageSource((ObjectMessage) message))); } else { throw new MailQueueException("Not supported JMS Message received " + message); } }
@Override public void done(boolean success) throws MailQueueException { mailQueueItem.done(success); if (success && mandatoryJmapMetaDataIsPresent()) { MessageId messageId = messageIdFactory.fromString((String) getMail().getAttribute(MailMetadata.MAIL_METADATA_MESSAGE_ID_ATTRIBUTE)); String username = (String) getMail().getAttribute(MailMetadata.MAIL_METADATA_USERNAME_ATTRIBUTE); if (getMail().getAttribute(IS_DELIVERED) == null) { try { MailboxSession mailboxSession = mailboxManager.createSystemSession(username); moveFromOutboxToSentWithSeenFlag(messageId, mailboxSession); getMail().setAttribute(IS_DELIVERED, IS_DELIVERED); } catch (MailShouldBeInOutboxException e) { LOG.info("Message does not exist on Outbox anymore, it could have already been sent", e); } catch (MailboxException e) { throw new MailQueueException(e.getMessage(), e); } } } }
@Override public void done(boolean success) throws MailQueueException { try { if (success) { session.commit(); } else { JMSMailQueue.rollback(session); } } catch (JMSException ex) { throw new MailQueueException("Unable to commit dequeue operation for mail " + mail.getName(), ex); } finally { JMSMailQueue.closeConsumer(consumer); JMSMailQueue.closeSession(session); } }
@Override public long getSize() throws MailQueueException { try (QueueBrowser browser = session.createBrowser(queue)) { Enumeration<?> enumeration = browser.getEnumeration(); return Iterators.size(new EnumerationIterator(enumeration)); } catch (Exception e) { LOGGER.error("Unable to get size of queue {}", queueName, e); throw new MailQueueException("Unable to get size of queue " + queueName, e); } }