Author: norman Date: Thu Sep 30 10:14:49 2010 New Revision: 1002989 URL: http://svn.apache.org/viewvc?rev=1002989&view=rev Log: LastUidTracker was moved on "extra class"
Added: james/imap/trunk/store/src/main/java/org/apache/james/mailbox/store/LastUidTracker.java Modified: james/imap/trunk/store/src/main/java/org/apache/james/mailbox/store/StoreMailboxManager.java Added: james/imap/trunk/store/src/main/java/org/apache/james/mailbox/store/LastUidTracker.java URL: http://svn.apache.org/viewvc/james/imap/trunk/store/src/main/java/org/apache/james/mailbox/store/LastUidTracker.java?rev=1002989&view=auto ============================================================================== --- james/imap/trunk/store/src/main/java/org/apache/james/mailbox/store/LastUidTracker.java (added) +++ james/imap/trunk/store/src/main/java/org/apache/james/mailbox/store/LastUidTracker.java Thu Sep 30 10:14:49 2010 @@ -0,0 +1,76 @@ +/**************************************************************** + * Licensed to the Apache Software Foundation (ASF) under one * + * or more contributor license agreements. See the NOTICE file * + * distributed with this work for additional information * + * regarding copyright ownership. The ASF licenses this file * + * to you under the Apache License, Version 2.0 (the * + * "License"); you may not use this file except in compliance * + * with the License. You may obtain a copy of the License at * + * * + * http://www.apache.org/licenses/LICENSE-2.0 * + * * + * Unless required by applicable law or agreed to in writing, * + * software distributed under the License is distributed on an * + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * + * KIND, either express or implied. See the License for the * + * specific language governing permissions and limitations * + * under the License. * + ****************************************************************/ + +package org.apache.james.mailbox.store; + +import java.util.concurrent.ConcurrentMap; +import java.util.concurrent.atomic.AtomicLong; + +import org.apache.james.mailbox.MailboxListener; +import org.apache.james.mailbox.MailboxPath; +import org.apache.james.mailbox.MailboxSession; + +/** + * {...@link MailboxListener} which takes care of update the lastUid for a Mailbox. + * + * + * + */ +public class LastUidTracker implements MailboxListener { + + private final ConcurrentMap<MailboxPath, AtomicLong> lastUids; + private final MailboxSession session; + + public LastUidTracker(ConcurrentMap<MailboxPath, AtomicLong> lastUids, MailboxSession session) { + this.lastUids = lastUids; + this.session = session; + } + + public void event(Event event) { + if (event instanceof Added) { + Added addedEvent = (Added) event; + lastUids.putIfAbsent(addedEvent.getMailboxPath(), new AtomicLong(0)); + AtomicLong lastUid = lastUids.get(addedEvent.getMailboxPath()); + long uid = ((Added) event).getSubjectUid(); + if (uid > lastUid.get()) { + lastUid.set(uid); + } + } else if (event instanceof MailboxDeletionEvent) { + // remove the lastUid if the Mailbox was deleted + lastUids.remove(((MailboxDeletionEvent) event).getMailboxPath()); + } else if (event instanceof MailboxRenamed) { + // If the mailbox was renamed we need take care of update the lastUid + // and move it to the new MailboxPath + MailboxRenamed rEvent = (MailboxRenamed) event; + AtomicLong oldLastUid = lastUids.remove(rEvent.getMailboxPath()); + if (oldLastUid == null) { + oldLastUid = new AtomicLong(0); + } + lastUids.putIfAbsent(rEvent.getNewPath(), oldLastUid); + } + } + + public boolean isClosed() { + if (session == null || session.isOpen() == false) { + return true; + } + return false; + } + +} Modified: james/imap/trunk/store/src/main/java/org/apache/james/mailbox/store/StoreMailboxManager.java URL: http://svn.apache.org/viewvc/james/imap/trunk/store/src/main/java/org/apache/james/mailbox/store/StoreMailboxManager.java?rev=1002989&r1=1002988&r2=1002989&view=diff ============================================================================== --- james/imap/trunk/store/src/main/java/org/apache/james/mailbox/store/StoreMailboxManager.java (original) +++ james/imap/trunk/store/src/main/java/org/apache/james/mailbox/store/StoreMailboxManager.java Thu Sep 30 10:14:49 2010 @@ -205,7 +205,7 @@ public abstract class StoreMailboxManage // are added to the mailbox final AtomicLong lastUid = getLastUid(mailboxPath); StoreMessageManager<Id> m = createMessageManager(lastUid, dispatcher, mailboxRow, session); - addListener(mailboxPath, new LastUidTracker(lastUid, session), session); + addListener(mailboxPath, new LastUidTracker(lastUids, session), session); return m; } } @@ -442,50 +442,6 @@ public abstract class StoreMailboxManage } - /** - * {...@link MailboxListener} which takes care of update the lastUid for a Mailbox. - * - * - * - */ - private final class LastUidTracker implements MailboxListener { - - private final AtomicLong lastUid; - private final MailboxSession session; - - public LastUidTracker(AtomicLong lastUid, MailboxSession session) { - this.lastUid = lastUid; - this.session = session; - } - - public void event(Event event) { - if (event instanceof Added) { - long uid = ((Added) event).getSubjectUid(); - if (uid > lastUid.get()) { - lastUid.set(uid); - } - } else if (event instanceof MailboxDeletionEvent) { - // remove the lastUid if the Mailbox was deleted - lastUids.remove(((MailboxDeletionEvent) event).getMailboxPath()); - } else if (event instanceof MailboxRenamed) { - // If the mailbox was renamed we need take care of update the lastUid - // and move it to the new MailboxPath - MailboxRenamed rEvent = (MailboxRenamed) event; - AtomicLong oldLastUid = lastUids.remove(rEvent.getMailboxPath()); - if (oldLastUid == null) { - oldLastUid = new AtomicLong(0); - } - lastUids.putIfAbsent(rEvent.getNewPath(), oldLastUid); - } - } - - public boolean isClosed() { - if (session == null || session.isOpen() == false) { - return true; - } - return false; - } - - } + } --------------------------------------------------------------------- To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org For additional commands, e-mail: server-dev-h...@james.apache.org