Search in sources :

Example 1 with FetchMode

use of com.zimbra.cs.mailbox.MailboxManager.FetchMode in project zm-mailbox by Zimbra.

the class SomeAccountsWaitSet method addAccounts.

synchronized List<WaitSetError> addAccounts(List<WaitSetAccount> wsas) {
    List<WaitSetError> errors = new ArrayList<WaitSetError>();
    for (WaitSetAccount wsa : wsas) {
        if (!mSessions.containsKey(wsa.getAccountId())) {
            // add the account to our session list
            mSessions.put(wsa.getAccountId(), wsa);
            // create the Session, if necessary, to listen to the requested mailbox
            try {
                // if there is a sync token, then we need to check to see if the
                // token is up-to-date...which means we have to fetch the mailbox.  Otherwise,
                // we don't have to fetch the mailbox.
                MailboxManager.FetchMode fetchMode = MailboxManager.FetchMode.AUTOCREATE;
                if (wsa.getLastKnownSyncToken() == null)
                    fetchMode = MailboxManager.FetchMode.ONLY_IF_CACHED;
                //
                // THIS CALL MIGHT REGISTER THE SESSION (via the MailboxManager notification --> mailboxLoaded() callback!
                //
                Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(wsa.getAccountId(), fetchMode);
                if (mbox != null) {
                    WaitSetError error = initializeWaitSetSession(wsa, mbox);
                    if (error != null) {
                        errors.add(error);
                    }
                }
            } catch (ServiceException e) {
                if (e.getCode() == AccountServiceException.NO_SUCH_ACCOUNT) {
                    errors.add(new WaitSetError(wsa.getAccountId(), WaitSetError.Type.NO_SUCH_ACCOUNT));
                } else if (e.getCode() == ServiceException.WRONG_HOST) {
                    errors.add(new WaitSetError(wsa.getAccountId(), WaitSetError.Type.WRONG_HOST_FOR_ACCOUNT));
                } else {
                    errors.add(new WaitSetError(wsa.getAccountId(), WaitSetError.Type.ERROR_LOADING_MAILBOX));
                }
                mSessions.remove(wsa);
            }
        } else {
            errors.add(new WaitSetError(wsa.getAccountId(), WaitSetError.Type.ALREADY_IN_SET_DURING_ADD));
        }
    }
    return errors;
}
Also used : MailboxManager(com.zimbra.cs.mailbox.MailboxManager) Mailbox(com.zimbra.cs.mailbox.Mailbox) AccountServiceException(com.zimbra.cs.account.AccountServiceException) ServiceException(com.zimbra.common.service.ServiceException) FetchMode(com.zimbra.cs.mailbox.MailboxManager.FetchMode) ArrayList(java.util.ArrayList)

Aggregations

ServiceException (com.zimbra.common.service.ServiceException)1 AccountServiceException (com.zimbra.cs.account.AccountServiceException)1 Mailbox (com.zimbra.cs.mailbox.Mailbox)1 MailboxManager (com.zimbra.cs.mailbox.MailboxManager)1 FetchMode (com.zimbra.cs.mailbox.MailboxManager.FetchMode)1 ArrayList (java.util.ArrayList)1