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);
}
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;
}
Aggregations