Skip to content

Commit

Permalink
JAMES-1733 Remove generics from mailbox API
Browse files Browse the repository at this point in the history
  • Loading branch information
aduprat committed May 17, 2016
1 parent 52153c4 commit 7015d94
Show file tree
Hide file tree
Showing 276 changed files with 2,286 additions and 2,523 deletions.
Expand Up @@ -3,18 +3,16 @@
import org.apache.james.mailbox.MailboxListener;
import org.apache.james.mailbox.MailboxListenerSupport;
import org.apache.james.mailbox.exception.MailboxException;
import org.apache.james.mailbox.store.mail.model.MailboxId;
/**
* A MailboxListener that invalidates the configured caches in response to Events
*
* @param <Id>
*/
public class CacheInvalidatingMailboxListener<Id extends MailboxId> implements MailboxListener {
public class CacheInvalidatingMailboxListener implements MailboxListener {

private final MailboxByPathCache<Id> mailboxCacheByPath;
private final MailboxMetadataCache<Id> mailboxMetadataCache;
private final MailboxByPathCache mailboxCacheByPath;
private final MailboxMetadataCache mailboxMetadataCache;

public CacheInvalidatingMailboxListener(MailboxByPathCache<Id> mailboxCacheByPath, MailboxMetadataCache<Id> mailboxMetadataCache) {
public CacheInvalidatingMailboxListener(MailboxByPathCache mailboxCacheByPath, MailboxMetadataCache mailboxMetadataCache) {
this.mailboxCacheByPath = mailboxCacheByPath;
this.mailboxMetadataCache = mailboxMetadataCache;
}
Expand Down
Expand Up @@ -6,22 +6,20 @@
import org.apache.james.mailbox.model.MailboxACL;
import org.apache.james.mailbox.model.MailboxPath;
import org.apache.james.mailbox.store.mail.MailboxMapper;
import org.apache.james.mailbox.store.mail.model.MailboxId;
import org.apache.james.mailbox.store.mail.model.Mailbox;

/**
* A MailboxMapper implementation that uses a MailboxByPathCache to cache the information
* from the underlying MailboxMapper
*
* @param <Id>
*/

public class CachingMailboxMapper<Id extends MailboxId> implements MailboxMapper<Id> {
public class CachingMailboxMapper implements MailboxMapper {

private final MailboxMapper<Id> underlying;
private final MailboxByPathCache<Id> cache;
private final MailboxMapper underlying;
private final MailboxByPathCache cache;

public CachingMailboxMapper(MailboxMapper<Id> underlying, MailboxByPathCache<Id> cache) {
public CachingMailboxMapper(MailboxMapper underlying, MailboxByPathCache cache) {
this.underlying = underlying;
this.cache = cache;
}
Expand All @@ -37,19 +35,19 @@ public <T> T execute(Transaction<T> transaction) throws MailboxException {
}

@Override
public void save(Mailbox<Id> mailbox) throws MailboxException {
public void save(Mailbox mailbox) throws MailboxException {
invalidate(mailbox);
underlying.save(mailbox);
}

@Override
public void delete(Mailbox<Id> mailbox) throws MailboxException {
public void delete(Mailbox mailbox) throws MailboxException {
invalidate(mailbox);
underlying.delete(mailbox);
}

@Override
public Mailbox<Id> findMailboxByPath(MailboxPath mailboxName)
public Mailbox findMailboxByPath(MailboxPath mailboxName)
throws MailboxException, MailboxNotFoundException {
try {
return cache.findMailboxByPath(mailboxName, underlying);
Expand All @@ -60,31 +58,31 @@ public Mailbox<Id> findMailboxByPath(MailboxPath mailboxName)
}

@Override
public List<Mailbox<Id>> findMailboxWithPathLike(MailboxPath mailboxPath)
public List<Mailbox> findMailboxWithPathLike(MailboxPath mailboxPath)
throws MailboxException {
// TODO possible to meaningfully cache it?
return underlying.findMailboxWithPathLike(mailboxPath);
}

@Override
public boolean hasChildren(Mailbox<Id> mailbox, char delimiter)
public boolean hasChildren(Mailbox mailbox, char delimiter)
throws MailboxException, MailboxNotFoundException {
// TODO possible to meaningfully cache it?
return underlying.hasChildren(mailbox, delimiter);
}

@Override
public List<Mailbox<Id>> list() throws MailboxException {
public List<Mailbox> list() throws MailboxException {
// TODO possible to meaningfully cache it? is it used at all?
return underlying.list();
}

@Override
public void updateACL(Mailbox<Id> mailbox, MailboxACL.MailboxACLCommand mailboxACLCommand) throws MailboxException {
public void updateACL(Mailbox mailbox, MailboxACL.MailboxACLCommand mailboxACLCommand) throws MailboxException {
mailbox.setACL(mailbox.getACL().apply(mailboxACLCommand));
}

private void invalidate(Mailbox<Id> mailbox) {
private void invalidate(Mailbox mailbox) {
cache.invalidate(mailbox);
}

Expand Down
Expand Up @@ -6,39 +6,37 @@
import org.apache.james.mailbox.store.MailboxSessionMapperFactory;
import org.apache.james.mailbox.store.mail.MailboxMapper;
import org.apache.james.mailbox.store.mail.MessageMapper;
import org.apache.james.mailbox.store.mail.model.MailboxId;
import org.apache.james.mailbox.store.user.SubscriptionMapper;

/**
* A MailboxSessionMapperFactory that uses the underlying MailboxSessionMapperFactory to provide
* caching variants of MessageMapper and MailboxMapper built around the MessageMapper and MailboxMapper
* provided by it
*
* @param <Id>
*/
public class CachingMailboxSessionMapperFactory<Id extends MailboxId> extends
MailboxSessionMapperFactory<Id> {
public class CachingMailboxSessionMapperFactory extends
MailboxSessionMapperFactory {

private final MailboxSessionMapperFactory<Id> underlying;
private final MailboxByPathCache<Id> mailboxByPathCache;
private final MailboxMetadataCache<Id> mailboxMetadataCache;
private final MailboxSessionMapperFactory underlying;
private final MailboxByPathCache mailboxByPathCache;
private final MailboxMetadataCache mailboxMetadataCache;

public CachingMailboxSessionMapperFactory(MailboxSessionMapperFactory<Id> underlying, MailboxByPathCache<Id> mailboxByPathCache, MailboxMetadataCache<Id> mailboxMetadataCache) {
public CachingMailboxSessionMapperFactory(MailboxSessionMapperFactory underlying, MailboxByPathCache mailboxByPathCache, MailboxMetadataCache mailboxMetadataCache) {
this.underlying = underlying;
this.mailboxByPathCache = mailboxByPathCache;
this.mailboxMetadataCache = mailboxMetadataCache;
}

@Override
public MessageMapper<Id> createMessageMapper(MailboxSession session)
public MessageMapper createMessageMapper(MailboxSession session)
throws MailboxException {
return new CachingMessageMapper<Id>(underlying.createMessageMapper(session), mailboxMetadataCache);
return new CachingMessageMapper(underlying.createMessageMapper(session), mailboxMetadataCache);
}

@Override
public MailboxMapper<Id> createMailboxMapper(MailboxSession session)
public MailboxMapper createMailboxMapper(MailboxSession session)
throws MailboxException {
return new CachingMailboxMapper<Id>(underlying.createMailboxMapper(session), mailboxByPathCache);
return new CachingMailboxMapper(underlying.createMailboxMapper(session), mailboxByPathCache);
}

@Override
Expand Down
Expand Up @@ -9,22 +9,20 @@
import org.apache.james.mailbox.model.UpdatedFlags;
import org.apache.james.mailbox.store.FlagsUpdateCalculator;
import org.apache.james.mailbox.store.mail.MessageMapper;
import org.apache.james.mailbox.store.mail.model.MailboxId;
import org.apache.james.mailbox.store.mail.model.Mailbox;
import org.apache.james.mailbox.store.mail.model.MailboxMessage;

/**
* A MessageMapper implementation that uses a MailboxMetadataCache to cache the information
* from the underlying MessageMapper
*
* @param <Id>
*/
public class CachingMessageMapper<Id extends MailboxId> implements MessageMapper<Id> {
public class CachingMessageMapper implements MessageMapper {

private final MessageMapper<Id> underlying;
private final MailboxMetadataCache<Id> cache;
private final MessageMapper underlying;
private final MailboxMetadataCache cache;

public CachingMessageMapper(MessageMapper<Id> underlying, MailboxMetadataCache<Id> cache) {
public CachingMessageMapper(MessageMapper underlying, MailboxMetadataCache cache) {
this.underlying = underlying;
this.cache = cache;
}
Expand All @@ -40,7 +38,7 @@ public <T> T execute(Transaction<T> transaction) throws MailboxException {
}

@Override
public Iterator<MailboxMessage<Id>> findInMailbox(Mailbox<Id> mailbox,
public Iterator<MailboxMessage> findInMailbox(Mailbox mailbox,
MessageRange set,
org.apache.james.mailbox.store.mail.MessageMapper.FetchType type,
int limit) throws MailboxException {
Expand All @@ -49,53 +47,53 @@ public Iterator<MailboxMessage<Id>> findInMailbox(Mailbox<Id> mailbox,

@Override
public Map<Long, MessageMetaData> expungeMarkedForDeletionInMailbox(
Mailbox<Id> mailbox, MessageRange set) throws MailboxException {
Mailbox mailbox, MessageRange set) throws MailboxException {
invalidateMetadata(mailbox);
return underlying.expungeMarkedForDeletionInMailbox(mailbox, set);
}

@Override
public long countMessagesInMailbox(Mailbox<Id> mailbox)
public long countMessagesInMailbox(Mailbox mailbox)
throws MailboxException {
return cache.countMessagesInMailbox(mailbox, underlying);
}

@Override
public long countUnseenMessagesInMailbox(Mailbox<Id> mailbox)
public long countUnseenMessagesInMailbox(Mailbox mailbox)
throws MailboxException {
return cache.countUnseenMessagesInMailbox(mailbox, underlying);
}

@Override
public void delete(Mailbox<Id> mailbox, MailboxMessage<Id> message)
public void delete(Mailbox mailbox, MailboxMessage message)
throws MailboxException {
invalidateMetadata(mailbox);
underlying.delete(mailbox, message);

}

@Override
public Long findFirstUnseenMessageUid(Mailbox<Id> mailbox)
public Long findFirstUnseenMessageUid(Mailbox mailbox)
throws MailboxException {
return cache.findFirstUnseenMessageUid(mailbox, underlying);
}

@Override
public List<Long> findRecentMessageUidsInMailbox(Mailbox<Id> mailbox)
public List<Long> findRecentMessageUidsInMailbox(Mailbox mailbox)
throws MailboxException {
// TODO can be meaningfully cached?
return underlying.findRecentMessageUidsInMailbox(mailbox);
}

@Override
public MessageMetaData add(Mailbox<Id> mailbox, MailboxMessage<Id> message)
public MessageMetaData add(Mailbox mailbox, MailboxMessage message)
throws MailboxException {
invalidateMetadata(mailbox);
return underlying.add(mailbox, message);
}

@Override
public Iterator<UpdatedFlags> updateFlags(Mailbox<Id> mailbox, FlagsUpdateCalculator calculator, MessageRange set)
public Iterator<UpdatedFlags> updateFlags(Mailbox mailbox, FlagsUpdateCalculator calculator, MessageRange set)
throws MailboxException {
//check if there are in fact any updates
if (set.iterator().hasNext())
Expand All @@ -105,29 +103,29 @@ public Iterator<UpdatedFlags> updateFlags(Mailbox<Id> mailbox, FlagsUpdateCalcul


@Override
public MessageMetaData copy(Mailbox<Id> mailbox, MailboxMessage<Id> original)
public MessageMetaData copy(Mailbox mailbox, MailboxMessage original)
throws MailboxException {
invalidateMetadata(mailbox);
return underlying.copy(mailbox, original);
}

@Override
public long getLastUid(Mailbox<Id> mailbox) throws MailboxException {
public long getLastUid(Mailbox mailbox) throws MailboxException {
return cache.getLastUid(mailbox, underlying);
}

@Override
public long getHighestModSeq(Mailbox<Id> mailbox) throws MailboxException {
public long getHighestModSeq(Mailbox mailbox) throws MailboxException {
return cache.getHighestModSeq(mailbox, underlying);
}

private void invalidateMetadata(Mailbox<Id> mailbox) {
private void invalidateMetadata(Mailbox mailbox) {
cache.invalidate(mailbox);

}

@Override
public MessageMetaData move(Mailbox<Id> mailbox, MailboxMessage<Id> original) throws MailboxException {
public MessageMetaData move(Mailbox mailbox, MailboxMessage original) throws MailboxException {
throw new UnsupportedOperationException("Move is not yet supported");
}

Expand Down
Expand Up @@ -4,21 +4,19 @@
import org.apache.james.mailbox.exception.MailboxNotFoundException;
import org.apache.james.mailbox.model.MailboxPath;
import org.apache.james.mailbox.store.mail.MailboxMapper;
import org.apache.james.mailbox.store.mail.model.MailboxId;
import org.apache.james.mailbox.store.mail.model.Mailbox;

/**
* Caches the MailboxPath -> Mailbox mapping
*
* @param <Id>
*/
public interface MailboxByPathCache<Id extends MailboxId> {
public interface MailboxByPathCache {

Mailbox<Id> findMailboxByPath(MailboxPath mailboxName,
MailboxMapper<Id> underlying) throws MailboxNotFoundException,
Mailbox findMailboxByPath(MailboxPath mailboxName,
MailboxMapper underlying) throws MailboxNotFoundException,
MailboxException;

void invalidate(Mailbox<Id> mailbox);
void invalidate(Mailbox mailbox);

void invalidate(MailboxPath mailboxPath);

Expand Down
Expand Up @@ -2,33 +2,31 @@

import org.apache.james.mailbox.exception.MailboxException;
import org.apache.james.mailbox.store.mail.MessageMapper;
import org.apache.james.mailbox.store.mail.model.MailboxId;
import org.apache.james.mailbox.store.mail.model.Mailbox;

/**
* Caches the simple yet possibly expensive to compute metadata info
* about a Mailbox like all/unseen messages count and similar
*
* @param <Id>
*/
public interface MailboxMetadataCache<Id extends MailboxId> {
public interface MailboxMetadataCache {

long countMessagesInMailbox(Mailbox<Id> mailbox,
MessageMapper<Id> underlying) throws MailboxException;
long countMessagesInMailbox(Mailbox mailbox,
MessageMapper underlying) throws MailboxException;

long countUnseenMessagesInMailbox(Mailbox<Id> mailbox,
MessageMapper<Id> underlying) throws MailboxException;
long countUnseenMessagesInMailbox(Mailbox mailbox,
MessageMapper underlying) throws MailboxException;

Long findFirstUnseenMessageUid(Mailbox<Id> mailbox,
MessageMapper<Id> underlying) throws MailboxException;
Long findFirstUnseenMessageUid(Mailbox mailbox,
MessageMapper underlying) throws MailboxException;

long getLastUid(Mailbox<Id> mailbox,
MessageMapper<Id> underlying) throws MailboxException;
long getLastUid(Mailbox mailbox,
MessageMapper underlying) throws MailboxException;

long getHighestModSeq(Mailbox<Id> mailbox,
MessageMapper<Id> underlying) throws MailboxException;
long getHighestModSeq(Mailbox mailbox,
MessageMapper underlying) throws MailboxException;

void invalidate(Mailbox<Id> mailbox);
void invalidate(Mailbox mailbox);

// public abstract void invalidate(MailboxPath mailboxPath);

Expand Down

0 comments on commit 7015d94

Please sign in to comment.