@Override public void removeMaxStorage(QuotaRoot quotaRoot) throws MailboxException { throw new MailboxException("Operation is not supported"); }
@Override public void setGlobalMaxMessage(QuotaCount globalMaxMessageCount) throws MailboxException { throw new MailboxException("Operation is not supported"); }
public List<String> toParts(String serializedQuotaRoot) throws MailboxException { List<String> parts = Splitter.on(SEPARATOR).splitToList(serializedQuotaRoot); if (parts.size() != 2) { throw new MailboxException(serializedQuotaRoot + " used as QuotaRoot should contain exactly one \"" + SEPARATOR + "\""); } return parts; } }
@Override public void register(MailboxPath path) throws MailboxException { int count = 0; boolean success = false; while (count < maxRetry && !success) { count++; success = tryRegister(path); } if (!success) { throw new MailboxException(maxRetry + " reached while trying to register " + path); } }
@Override public void unregister(MailboxPath path) throws MailboxException { int count = 0; boolean success = false; while (count < maxRetry && !success) { count++; success = tryUnregister(path); } if (!success) { throw new MailboxException(maxRetry + " reached while trying to unregister " + path); } }
public void deleteAllMemberships() throws MailboxException { try { getEntityManager().createNamedQuery("deleteAllMemberships").executeUpdate(); } catch (PersistenceException e) { throw new MailboxException("Delete of mailboxes failed", e); } }
/** * Commit the Transaction and close the EntityManager */ @Override protected void commit() throws MailboxException { try { getEntityManager().getTransaction().commit(); } catch (PersistenceException e) { throw new MailboxException("Commit of transaction failed",e); } }
@Override protected void begin() throws MailboxException { try { getEntityManager().getTransaction().begin(); } catch (PersistenceException e) { throw new MailboxException("Begin of transaction failed", e); } }
private void doIncrease(QuotaRoot quotaRoot, long count, long size) throws MailboxException { try { Entry entry = quotaCache.get(quotaRoot); entry.getCount().addAndGet(count); entry.getSize().addAndGet(size); } catch (ExecutionException e) { throw new MailboxException("Exception caught", e); } }
@Override public QuotaSize getCurrentStorage(QuotaRoot quotaRoot) throws MailboxException { try { return QuotaSize.size(quotaCache.get(quotaRoot).getSize().get()); } catch (ExecutionException e) { throw new MailboxException("Exception caught", e); } }
@Override public long nextModSeq(MailboxSession mailboxSession, Mailbox mailbox) throws MailboxException { CassandraId mailboxId = (CassandraId) mailbox.getMailboxId(); return nextModSeq(mailboxId).join() .orElseThrow(() -> new MailboxException("Can not retrieve modseq for " + mailboxId)); }
/** * Create a copy of the given message */ public JPAMailboxMessage(JPAMailbox mailbox, MessageUid uid, long modSeq, MailboxMessage message) throws MailboxException { super(mailbox, uid, modSeq, message); try { this.body = IOUtils.toByteArray(message.getBodyContent()); this.header = IOUtils.toByteArray(message.getHeaderContent()); } catch (IOException e) { throw new MailboxException("Unable to parse message",e); } }
private static SharedByteArrayInputStream copyFullContent(MailboxMessage original) throws MailboxException { try { return new SharedByteArrayInputStream(IOUtils.toByteArray(original.getFullContent())); } catch (IOException e) { throw new MailboxException("Unable to parse message", e); } }
@Override public long countMessagesInMailbox(Mailbox mailbox) throws MailboxException { try { JPAId mailboxId = (JPAId) mailbox.getMailboxId(); return (Long) getEntityManager().createNamedQuery("countMessagesInMailbox") .setParameter("idParam", mailboxId.getRawId()).getSingleResult(); } catch (PersistenceException e) { throw new MailboxException("Count of messages failed in mailbox " + mailbox, e); } }
@Override public long countUnseenMessagesInMailbox(Mailbox mailbox) throws MailboxException { try { JPAId mailboxId = (JPAId) mailbox.getMailboxId(); return (Long) getEntityManager().createNamedQuery("countUnseenMessagesInMailbox") .setParameter("idParam", mailboxId.getRawId()).getSingleResult(); } catch (PersistenceException e) { throw new MailboxException("Count of useen messages failed in mailbox " + mailbox, e); } }
@Override public void delete(Mailbox mailbox, MailboxMessage message) throws MailboxException { try { AbstractJPAMailboxMessage jpaMessage = getEntityManager().find(AbstractJPAMailboxMessage.class, buildKey(mailbox, message)); getEntityManager().remove(jpaMessage); } catch (PersistenceException e) { throw new MailboxException("Delete of message " + message + " failed in mailbox " + mailbox, e); } }
@Override public void addGlobalListener(MailboxListener listener, MailboxSession session) throws MailboxException { if (listener.getType() != ListenerType.EACH_NODE && listener.getType() != ListenerType.ONCE) { throw new MailboxException(listener.getClass().getCanonicalName() + " registered on global event dispatching while its listener type was " + listener.getType()); } registry.addGlobalListener(listener); }
@Override public void addGlobalListener(MailboxListener listener, MailboxSession session) throws MailboxException { if (listener.getType().equals(ListenerType.EACH_NODE)) { throw new MailboxException("Attempt to register a global listener that need to be called on each node while using a non compatible delegating listeners"); } mailboxListenerRegistry.addGlobalListener(listener); }
private CompletableFuture<Pair<BlobId, BlobId>> saveContent(MailboxMessage message) throws MailboxException { try { byte[] headerContent = IOUtils.toByteArray(message.getHeaderContent()); byte[] bodyContent = IOUtils.toByteArray(message.getBodyContent()); return CompletableFutureUtil.combine( blobStore.save(headerContent), blobStore.save(bodyContent), Pair::of); } catch (IOException e) { throw new MailboxException("Error saving mail content", e); } }
@Test public void testMailboxExceptionCause() { MailboxException mbe = new MailboxException(EXCEPTION_MESSAGE, EXCEPTION_CAUSE); assertThat(mbe).hasMessage(EXCEPTION_MESSAGE).hasCauseExactlyInstanceOf(Exception.class); assertThat(mbe.getCause()).hasMessage(CAUSE_MESSAGE); }