if (mbox.getIndex() != null) mbox.getIndex().flush();
if (mbox.getMailboxIndex() != null) mbox.getMailboxIndex().flush();
    public void endMaintenance(MailboxLock lock, boolean success, boolean removeFromCache) throws ServiceException {        if (lock == null)            throw ServiceException.INVALID_REQUEST("no lock provided", null);            synchronized (this) {            Object obj = mMailboxCache.get(lock.getMailboxId());            if (obj != lock)                throw MailServiceException.MAINTENANCE(lock.getMailboxId());            // start by removing the lock from the Mailbox object cache            mMailboxCache.remove(lock.getMailboxId());            Mailbox mbox = lock.getMailbox();            if (success) {                // XXX: don't recall the rationale for re-setting this...                mMailboxIds.put(lock.getAccountId().toLowerCase(), lock.getMailboxId());                if (mbox != null) {                    assert(lock == mbox.getMailboxLock());                        // Backend data may have changed while mailbox was in                    // maintenance mode.  Invalidate all caches.                    mbox.purge(MailItem.TYPE_UNKNOWN);                        if (removeFromCache) {                        // We're going to let the Mailbox drop out of the                        // cache and eventually get GC'd.  Some immediate                        // cleanup is necessary though.                        if (mbox.getIndex() != null)                            mbox.getIndex().flush();                        // Note: mbox is left in maintenance mode.                    } else {                        mbox.endMaintenance(success);                        mMailboxCache.put(lock.getMailboxId(), lock.getMailbox());                    }                }            } else {                // on failed maintenance, mark the Mailbox object as off-limits to everyone                if (mbox != null)                    mbox.endMaintenance(success);                lock.markUnavailable();            }        }    }