You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by no...@apache.org on 2010/07/29 13:54:26 UTC
svn commit: r980412 -
/james/imap/trunk/store/src/main/java/org/apache/james/imap/store/StoreMailboxManager.java
Author: norman
Date: Thu Jul 29 11:54:26 2010
New Revision: 980412
URL: http://svn.apache.org/viewvc?rev=980412&view=rev
Log:
Remove not needed mutex
Modified:
james/imap/trunk/store/src/main/java/org/apache/james/imap/store/StoreMailboxManager.java
Modified: james/imap/trunk/store/src/main/java/org/apache/james/imap/store/StoreMailboxManager.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/store/src/main/java/org/apache/james/imap/store/StoreMailboxManager.java?rev=980412&r1=980411&r2=980412&view=diff
==============================================================================
--- james/imap/trunk/store/src/main/java/org/apache/james/imap/store/StoreMailboxManager.java (original)
+++ james/imap/trunk/store/src/main/java/org/apache/james/imap/store/StoreMailboxManager.java Thu Jul 29 11:54:26 2010
@@ -55,8 +55,6 @@ import org.apache.james.imap.store.trans
public abstract class StoreMailboxManager<Id> extends DelegatingMailboxManager {
public static final char SQL_WILDCARD_CHAR = '%';
-
- private final Object mutex = new Object();
private final MailboxEventDispatcher dispatcher = new MailboxEventDispatcher();
private final DelegatingMailboxListener delegatingListener = new DelegatingMailboxListener();
@@ -107,19 +105,17 @@ public abstract class StoreMailboxManage
* @throws MailboxException get thrown if no Mailbox could be found for the given name
*/
private StoreMessageManager<Id> doGetMailbox(MailboxPath mailboxPath, MailboxSession session) throws MailboxException {
- synchronized (mutex) {
- final MailboxMapper<Id> mapper = mailboxSessionMapperFactory.getMailboxMapper(session);
- Mailbox<Id> mailboxRow = mapper.findMailboxByPath(mailboxPath);
-
- if (mailboxRow == null) {
- getLog().info("Mailbox '" + mailboxPath + "' not found.");
- throw new MailboxNotFoundException(mailboxPath);
+ final MailboxMapper<Id> mapper = mailboxSessionMapperFactory.getMailboxMapper(session);
+ Mailbox<Id> mailboxRow = mapper.findMailboxByPath(mailboxPath);
- } else {
- getLog().debug("Loaded mailbox " + mailboxPath);
+ if (mailboxRow == null) {
+ getLog().info("Mailbox '" + mailboxPath + "' not found.");
+ throw new MailboxNotFoundException(mailboxPath);
- return createMessageManager(dispatcher, consumer, mailboxRow, session);
- }
+ } else {
+ getLog().debug("Loaded mailbox " + mailboxPath);
+
+ return createMessageManager(dispatcher, consumer, mailboxRow, session);
}
}
@@ -133,20 +129,18 @@ public abstract class StoreMailboxManage
final int length = mailboxPath.getName().length();
if (length == 0) {
getLog().warn("Ignoring mailbox with empty name");
- }
- else {
+ } else {
if (mailboxPath.getName().charAt(length - 1) == MailboxConstants.DEFAULT_DELIMITER)
mailboxPath.setName(mailboxPath.getName().substring(0, length - 1));
if (mailboxExists(mailboxPath, mailboxSession))
- throw new MailboxExistsException(mailboxPath.toString());
- synchronized (mutex) {
- // Create parents first
- // If any creation fails then the mailbox will not be created
- // TODO: transaction
- for (MailboxPath mailbox : mailboxPath.getHierarchyLevels(MailboxConstants.DEFAULT_DELIMITER))
- if (!mailboxExists(mailbox, mailboxSession))
- doCreateMailbox(mailbox, mailboxSession);
- }
+ throw new MailboxExistsException(mailboxPath.toString());
+ // Create parents first
+ // If any creation fails then the mailbox will not be created
+ // TODO: transaction
+ for (MailboxPath mailbox : mailboxPath.getHierarchyLevels(MailboxConstants.DEFAULT_DELIMITER))
+ if (!mailboxExists(mailbox, mailboxSession))
+ doCreateMailbox(mailbox, mailboxSession);
+
}
}
@@ -154,80 +148,73 @@ public abstract class StoreMailboxManage
* (non-Javadoc)
* @see org.apache.james.imap.mailbox.MailboxManager#deleteMailbox(org.apache.james.imap.api.MailboxPath, org.apache.james.imap.mailbox.MailboxSession)
*/
- public void deleteMailbox(final MailboxPath mailboxPath, final MailboxSession session)
- throws MailboxException {
+ public void deleteMailbox(final MailboxPath mailboxPath, final MailboxSession session) throws MailboxException {
session.getLog().info("deleteMailbox " + mailboxPath);
- synchronized (mutex) {
- // TODO put this into a serilizable transaction
-
- final MailboxMapper<Id> mapper = mailboxSessionMapperFactory.getMailboxMapper(session);
-
- mapper.execute(new TransactionalMapper.Transaction() {
+ final MailboxMapper<Id> mapper = mailboxSessionMapperFactory.getMailboxMapper(session);
- public void run() throws MailboxException {
- Mailbox<Id> mailbox = mapper.findMailboxByPath(mailboxPath);
- if (mailbox == null) {
- throw new MailboxNotFoundException("Mailbox not found");
- }
- mapper.delete(mailbox);
+ mapper.execute(new TransactionalMapper.Transaction() {
+
+ public void run() throws MailboxException {
+ Mailbox<Id> mailbox = mapper.findMailboxByPath(mailboxPath);
+ if (mailbox == null) {
+ throw new MailboxNotFoundException("Mailbox not found");
}
-
- });
-
- dispatcher.mailboxDeleted(session.getSessionId(), mailboxPath);
- }
+ mapper.delete(mailbox);
+ }
+
+ });
+
+ dispatcher.mailboxDeleted(session.getSessionId(), mailboxPath);
+
}
/*
* (non-Javadoc)
* @see org.apache.james.imap.mailbox.MailboxManager#renameMailbox(org.apache.james.imap.api.MailboxPath, org.apache.james.imap.api.MailboxPath, org.apache.james.imap.mailbox.MailboxSession)
*/
- public void renameMailbox(final MailboxPath from, final MailboxPath to, final MailboxSession session)
- throws MailboxException {
+ public void renameMailbox(final MailboxPath from, final MailboxPath to, final MailboxSession session) throws MailboxException {
final Log log = getLog();
- if (log.isDebugEnabled()) log.debug("renameMailbox " + from + " to " + to);
- synchronized (mutex) {
- if (mailboxExists(to, session)) {
- throw new MailboxExistsException(to.toString());
- }
+ if (log.isDebugEnabled())
+ log.debug("renameMailbox " + from + " to " + to);
+ if (mailboxExists(to, session)) {
+ throw new MailboxExistsException(to.toString());
+ }
- final MailboxMapper<Id> mapper = mailboxSessionMapperFactory.getMailboxMapper(session);
- mapper.execute(new TransactionalMapper.Transaction() {
+ final MailboxMapper<Id> mapper = mailboxSessionMapperFactory.getMailboxMapper(session);
+ mapper.execute(new TransactionalMapper.Transaction() {
- public void run() throws MailboxException {
- // TODO put this into a serilizable transaction
- final Mailbox<Id> mailbox = mapper.findMailboxByPath(from);
- if (mailbox == null) {
- throw new MailboxNotFoundException(from);
- }
- mailbox.setNamespace(to.getNamespace());
- mailbox.setUser(to.getUser());
- mailbox.setName(to.getName());
- mapper.save(mailbox);
-
- changeMailboxName(from, to, session);
-
- // rename submailboxes
- MailboxPath children = new MailboxPath(MailboxConstants.USER_NAMESPACE, from.getUser(), from.getName() + MailboxConstants.DEFAULT_DELIMITER + "%");
- final List<Mailbox<Id>> subMailboxes = mapper.findMailboxWithPathLike(children);
- for (Mailbox<Id> sub:subMailboxes) {
- final String subOriginalName = sub.getName();
- final String subNewName = to.getName() + subOriginalName.substring(from.getName().length());
- sub.setName(subNewName);
- mapper.save(sub);
+ public void run() throws MailboxException {
+ // TODO put this into a serilizable transaction
+ final Mailbox<Id> mailbox = mapper.findMailboxByPath(from);
+ if (mailbox == null) {
+ throw new MailboxNotFoundException(from);
+ }
+ mailbox.setNamespace(to.getNamespace());
+ mailbox.setUser(to.getUser());
+ mailbox.setName(to.getName());
+ mapper.save(mailbox);
+
+ changeMailboxName(from, to, session);
+
+ // rename submailboxes
+ MailboxPath children = new MailboxPath(MailboxConstants.USER_NAMESPACE, from.getUser(), from.getName() + MailboxConstants.DEFAULT_DELIMITER + "%");
+ final List<Mailbox<Id>> subMailboxes = mapper.findMailboxWithPathLike(children);
+ for (Mailbox<Id> sub : subMailboxes) {
+ final String subOriginalName = sub.getName();
+ final String subNewName = to.getName() + subOriginalName.substring(from.getName().length());
+ sub.setName(subNewName);
+ mapper.save(sub);
- changeMailboxName(new MailboxPath(children, subOriginalName),
- new MailboxPath(children, subNewName), session);
+ changeMailboxName(new MailboxPath(children, subOriginalName), new MailboxPath(children, subNewName), session);
- if (log.isDebugEnabled()) log.debug("Rename mailbox sub-mailbox " + subOriginalName + " to "
- + subNewName);
- }
+ if (log.isDebugEnabled())
+ log.debug("Rename mailbox sub-mailbox " + subOriginalName + " to " + subNewName);
}
-
- });
- }
- }
+ }
+
+ });
+ }
/**
* Changes the name of the mailbox instance in the cache.
@@ -242,13 +229,11 @@ public abstract class StoreMailboxManage
* (non-Javadoc)
* @see org.apache.james.imap.mailbox.MailboxManager#copyMessages(org.apache.james.imap.mailbox.MessageRange, org.apache.james.imap.api.MailboxPath, org.apache.james.imap.api.MailboxPath, org.apache.james.imap.mailbox.MailboxSession)
*/
- public void copyMessages(MessageRange set, MailboxPath from, MailboxPath to, MailboxSession session)
- throws MailboxException {
- synchronized (mutex) {
- StoreMessageManager<Id> toMailbox = doGetMailbox(to, session);
- StoreMessageManager<Id> fromMailbox = doGetMailbox(from, session);
- fromMailbox.copyTo(set, toMailbox, session);
- }
+ public void copyMessages(MessageRange set, MailboxPath from, MailboxPath to, MailboxSession session) throws MailboxException {
+ StoreMessageManager<Id> toMailbox = doGetMailbox(to, session);
+ StoreMessageManager<Id> fromMailbox = doGetMailbox(from, session);
+ fromMailbox.copyTo(set, toMailbox, session);
+
}
/*
@@ -299,15 +284,14 @@ public abstract class StoreMailboxManage
* @see org.apache.james.imap.mailbox.MailboxManager#mailboxExists(org.apache.james.imap.api.MailboxPath, org.apache.james.imap.mailbox.MailboxSession)
*/
public boolean mailboxExists(MailboxPath mailboxPath, MailboxSession session) throws MailboxException {
- synchronized (mutex) {
- try {
- final MailboxMapper<Id> mapper = mailboxSessionMapperFactory.getMailboxMapper(session);
- mapper.findMailboxByPath(mailboxPath);
- return true;
- } catch (MailboxNotFoundException e) {
- return false;
- }
+ try {
+ final MailboxMapper<Id> mapper = mailboxSessionMapperFactory.getMailboxMapper(session);
+ mapper.findMailboxByPath(mailboxPath);
+ return true;
+ } catch (MailboxNotFoundException e) {
+ return false;
}
+
}
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org