Search in sources :

Example 6 with WaitSetAccount

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

the class WaitSetRequest method staticHandle.

public static void staticHandle(WaitSetReq req, Map<String, Object> context, WaitSetResp resp, boolean adminAllowed) throws ServiceException {
    ZimbraSoapContext zsc = getZimbraSoapContext(context);
    HttpServletRequest servletRequest = (HttpServletRequest) context.get(SoapServlet.SERVLET_REQUEST);
    String waitSetId = req.getWaitSetId();
    String lastKnownSeqNo = req.getLastKnownSeqNo();
    boolean block = req.getBlock();
    boolean expand = req.getExpand();
    WaitSetCallback cb = (WaitSetCallback) servletRequest.getAttribute(VARS_ATTR_NAME);
    if (cb == null) {
        // Initial
        Continuation continuation = ContinuationSupport.getContinuation(servletRequest);
        cb = new WaitSetCallback();
        cb.continuationResume = new ResumeContinuationListener(continuation);
        servletRequest.setAttribute(VARS_ATTR_NAME, cb);
        servletRequest.setAttribute(ZimbraSoapContext.soapRequestIdAttr, zsc.getSoapRequestId());
        String defInterestStr = null;
        if (waitSetId.startsWith(WaitSetMgr.ALL_ACCOUNTS_ID_PREFIX)) {
            WaitSetMgr.checkRightForAllAccounts(zsc);
            // default interest types required for "All" waitsets
            defInterestStr = req.getDefaultInterests();
            Set<MailItem.Type> defaultInterests = WaitSetRequest.parseInterestStr(defInterestStr, EnumSet.noneOf(MailItem.Type.class));
            cb.ws = WaitSetMgr.lookupOrCreateForAllAccts(zsc.getRequestedAccountId(), waitSetId, defaultInterests, lastKnownSeqNo);
        } else {
            cb.ws = WaitSetMgr.lookup(waitSetId);
        }
        if (cb.ws == null)
            throw AdminServiceException.NO_SUCH_WAITSET(waitSetId);
        WaitSetMgr.checkRightForOwnerAccount(cb.ws, zsc.getRequestedAccountId());
        List<WaitSetAccount> add = parseAddUpdateAccounts(zsc, req.getAddAccounts(), cb.ws.getDefaultInterest());
        List<WaitSetAccount> update = parseAddUpdateAccounts(zsc, req.getUpdateAccounts(), cb.ws.getDefaultInterest());
        List<String> remove = parseRemoveAccounts(zsc, req.getRemoveAccounts());
        // /////////////////
        // workaround for 27480: load the mailboxes NOW, before we grab the waitset lock
        preloadMailboxes(add);
        preloadMailboxes(update);
        // the server in a very fast loop (they should be using the 'block' mode)
        if (!block && !adminAllowed) {
            try {
                Thread.sleep(INITIAL_SLEEP_TIME_MILLIS);
            } catch (InterruptedException ex) {
            }
        }
        cb.errors.addAll(cb.ws.removeAccounts(remove));
        synchronized (cb.ws) {
            // bug 28190: always grab the WS lock before the CB lock.
            synchronized (cb) {
                // note that doWait for AllAccountsWaitSet ignores 'add' and 'update'
                cb.errors.addAll(cb.ws.doWait(cb, lastKnownSeqNo, add, update));
                // the ws until we release the cb lock!
                if (cb.completed) {
                    block = false;
                }
            }
        }
        if (block) {
            noDataSleep(cb);
            synchronized (cb) {
                if (!cb.completed) {
                    // don't wait if it completed right away
                    long timeout = getTimeoutMillis(req.getTimeout(), adminAllowed);
                    ZimbraLog.soap.trace("Suspending <WaitSetRequest> for %dms", timeout);
                    cb.continuationResume.suspendAndUndispatch(timeout);
                }
            }
        }
    }
    // if we got here, then we did *not* execute a jetty RetryContinuation,
    // soooo, we'll fall through and finish up at the bottom
    processCallback(resp, cb, waitSetId, lastKnownSeqNo, expand);
}
Also used : Continuation(org.eclipse.jetty.continuation.Continuation) WaitSetAccount(com.zimbra.cs.session.WaitSetAccount) ResumeContinuationListener(com.zimbra.cs.servlet.continuation.ResumeContinuationListener) HttpServletRequest(javax.servlet.http.HttpServletRequest) IdAndType(com.zimbra.soap.type.IdAndType) ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) WaitSetCallback(com.zimbra.cs.session.WaitSetCallback)

Example 7 with WaitSetAccount

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

the class WaitSetRequest method parseAddUpdateAccounts.

protected static List<WaitSetAccount> parseAddUpdateAccounts(ZimbraSoapContext zsc, List<WaitSetAddSpec> accountDetails, Set<MailItem.Type> defaultInterest) throws ServiceException {
    List<WaitSetAccount> toRet = new ArrayList<WaitSetAccount>();
    if (accountDetails != null) {
        for (WaitSetAddSpec accountDetail : accountDetails) {
            String id;
            String name = accountDetail.getName();
            if (name != null) {
                Account acct = Provisioning.getInstance().get(AccountBy.name, name);
                if (acct != null) {
                    id = acct.getId();
                } else {
                    // TODO - what's going on here???  Presumably this should be being used
                    WaitSetError err = new WaitSetError(name, WaitSetError.Type.NO_SUCH_ACCOUNT);
                    continue;
                }
            } else {
                id = accountDetail.getId();
            }
            WaitSetMgr.checkRightForAdditionalAccount(id, zsc);
            String tokenStr = accountDetail.getToken();
            SyncToken token = tokenStr != null ? new SyncToken(tokenStr) : null;
            Set<MailItem.Type> interests = parseInterestStr(accountDetail.getInterests(), defaultInterest);
            Set<Integer> folderInterests = accountDetail.getFolderInterestsAsSet();
            toRet.add(new WaitSetAccount(id, token, interests, folderInterests));
        }
    }
    return toRet;
}
Also used : WaitSetAccount(com.zimbra.cs.session.WaitSetAccount) Account(com.zimbra.cs.account.Account) SyncToken(com.zimbra.cs.service.util.SyncToken) IdAndType(com.zimbra.soap.type.IdAndType) WaitSetAddSpec(com.zimbra.soap.type.WaitSetAddSpec) WaitSetAccount(com.zimbra.cs.session.WaitSetAccount) ArrayList(java.util.ArrayList) WaitSetError(com.zimbra.cs.session.WaitSetError)

Aggregations

WaitSetAccount (com.zimbra.cs.session.WaitSetAccount)7 ArrayList (java.util.ArrayList)6 WaitSetError (com.zimbra.cs.session.WaitSetError)5 ZimbraSoapContext (com.zimbra.soap.ZimbraSoapContext)4 ServiceException (com.zimbra.common.service.ServiceException)3 Account (com.zimbra.cs.account.Account)3 Mailbox (com.zimbra.cs.mailbox.Mailbox)3 WaitSetCallback (com.zimbra.cs.session.WaitSetCallback)3 List (java.util.List)3 Element (com.zimbra.common.soap.Element)2 MailboxManager (com.zimbra.cs.mailbox.MailboxManager)2 SyncToken (com.zimbra.cs.service.util.SyncToken)2 ResumeContinuationListener (com.zimbra.cs.servlet.continuation.ResumeContinuationListener)2 IdAndType (com.zimbra.soap.type.IdAndType)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 Continuation (org.eclipse.jetty.continuation.Continuation)2 Pair (com.zimbra.common.util.Pair)1 AdminServiceException (com.zimbra.cs.service.admin.AdminServiceException)1 IWaitSet (com.zimbra.cs.session.IWaitSet)1 WaitSetAddSpec (com.zimbra.soap.type.WaitSetAddSpec)1