Search in sources :

Example 1 with WaitSetSession

use of com.zimbra.cs.session.WaitSetSession in project zm-mailbox by Zimbra.

the class WaitSetRequest method processCallback.

private static void processCallback(WaitSetResp resp, WaitSetCallback cb, String waitSetId, String lastKnownSeqNo, boolean expand) throws ServiceException {
    cb.ws.doneWaiting(cb);
    resp.setWaitSetId(waitSetId);
    if (cb.canceled) {
        resp.setCanceled(true);
    } else if (cb.completed) {
        resp.setSeqNo(cb.seqNo);
        for (String signalledAccount : cb.signalledAccounts) {
            WaitSetSession signalledSession = cb.signalledSessions.get(signalledAccount);
            int lastChangeId = 0;
            Set<Integer> folderInterests = null;
            if (signalledSession != null) {
                folderInterests = signalledSession.getFolderInterest();
                if (signalledSession.getMailbox() != null) {
                    lastChangeId = signalledSession.getMailbox().getLastChangeID();
                }
            } else {
                Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(signalledAccount, false);
                if (mbox != null) {
                    lastChangeId = mbox.getLastChangeID();
                }
            }
            AccountWithModifications info = new AccountWithModifications(signalledAccount, lastChangeId);
            @SuppressWarnings("rawtypes") PendingModifications accountMods = cb.pendingModifications.get(signalledAccount);
            Map<Integer, PendingFolderModifications> folderMap = PendingModifications.encodeIMAPFolderModifications(accountMods, folderInterests);
            if (folderInterests != null && !folderInterests.isEmpty() && !folderMap.isEmpty()) {
                // interested only in specific folders
                if (expand) {
                    info.setPendingFolderModifications(folderMap.values());
                }
                resp.addSignalledAccount(info);
            } else if (folderInterests == null || folderInterests.isEmpty()) {
                // interested in any folder
                resp.addSignalledAccount(info);
            }
        }
    } else {
        // timed out....they should try again
        resp.setSeqNo(lastKnownSeqNo);
    }
    resp.setErrors(encodeErrors(cb.errors));
}
Also used : EnumSet(java.util.EnumSet) Set(java.util.Set) Mailbox(com.zimbra.cs.mailbox.Mailbox) AccountWithModifications(com.zimbra.soap.type.AccountWithModifications) PendingModifications(com.zimbra.cs.session.PendingModifications) WaitSetSession(com.zimbra.cs.session.WaitSetSession) Map(java.util.Map)

Aggregations

Mailbox (com.zimbra.cs.mailbox.Mailbox)1 PendingModifications (com.zimbra.cs.session.PendingModifications)1 WaitSetSession (com.zimbra.cs.session.WaitSetSession)1 AccountWithModifications (com.zimbra.soap.type.AccountWithModifications)1 EnumSet (java.util.EnumSet)1 Map (java.util.Map)1 Set (java.util.Set)1