Author: norman Date: Sat Oct 1 17:48:40 2011 New Revision: 1178050 URL: http://svn.apache.org/viewvc?rev=1178050&view=rev Log: Allow to set a max "batch size" while do the copy. This allows to not keep the lock for the whole time and so other waiting threads also have a chance to get it. By default it not tries to break things down in batches. See MAILBOX-148
Modified: james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/StoreMailboxManager.java Modified: james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/StoreMailboxManager.java URL: http://svn.apache.org/viewvc/james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/StoreMailboxManager.java?rev=1178050&r1=1178049&r2=1178050&view=diff ============================================================================== --- james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/StoreMailboxManager.java (original) +++ james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/StoreMailboxManager.java Sat Oct 1 17:48:40 2011 @@ -21,6 +21,7 @@ package org.apache.james.mailbox.store; import java.util.ArrayList; import java.util.Collections; +import java.util.Iterator; import java.util.List; import java.util.Locale; import java.util.Random; @@ -73,6 +74,9 @@ public class StoreMailboxManager<Id> imp private final Authenticator authenticator; private final static Random RANDOM = new Random(); + private int copyBatchSize = 0; + + private MailboxPathLocker locker; @@ -89,6 +93,10 @@ public class StoreMailboxManager<Id> imp this(mailboxSessionMapperFactory, authenticator, new JVMMailboxPathLocker()); } + public void setCopyBatchSize(int copyBatchSize) { + this.copyBatchSize = copyBatchSize; + } + /** * Init the {@link MailboxManager} * @@ -441,7 +449,17 @@ public class StoreMailboxManager<Id> imp public List<MessageRange> copyMessages(MessageRange set, MailboxPath from, MailboxPath to, MailboxSession session) throws MailboxException { StoreMessageManager<Id> toMailbox = (StoreMessageManager<Id>) getMailbox(to, session); StoreMessageManager<Id> fromMailbox = (StoreMessageManager<Id>) getMailbox(from, session); - return fromMailbox.copyTo(set, toMailbox, session); + + if (copyBatchSize > 0) { + List<MessageRange> copiedRanges = new ArrayList<MessageRange>(); + Iterator<MessageRange> ranges = set.split(copyBatchSize).iterator(); + while(ranges.hasNext()) { + copiedRanges.addAll(fromMailbox.copyTo(ranges.next(), toMailbox, session)); + } + return copiedRanges; + } else { + return fromMailbox.copyTo(set, toMailbox, session); + } } /* --------------------------------------------------------------------- To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org For additional commands, e-mail: server-dev-h...@james.apache.org