Search in sources :

Example 1 with AdminCreateWaitSetRequest

use of com.zimbra.soap.admin.message.AdminCreateWaitSetRequest in project zm-mailbox by Zimbra.

the class TestWaitSetRequest method createAdminWaitSet.

private AdminCreateWaitSetResponse createAdminWaitSet(Set<String> accountIds, String authToken, boolean all) throws Exception {
    AdminCreateWaitSetRequest req = new AdminCreateWaitSetRequest("all", all);
    if (accountIds != null) {
        for (String accountId : accountIds) {
            WaitSetAddSpec add = new WaitSetAddSpec();
            add.setId(accountId);
            req.addAccount(add);
        }
    }
    DocumentResult dr = new DocumentResult();
    marshaller.marshal(req, dr);
    Document doc = dr.getDocument();
    AdminCreateWaitSetResponse acwsResp = sendReq(envelope(authToken, doc.getRootElement().asXML(), "urn:zimbra"), TestUtil.getAdminSoapUrl() + "AdminCreateWaitSetRequest");
    return acwsResp;
}
Also used : WaitSetAddSpec(com.zimbra.soap.type.WaitSetAddSpec) DocumentResult(org.dom4j.io.DocumentResult) Document(org.dom4j.Document) AdminCreateWaitSetRequest(com.zimbra.soap.admin.message.AdminCreateWaitSetRequest) AdminCreateWaitSetResponse(com.zimbra.soap.admin.message.AdminCreateWaitSetResponse)

Example 2 with AdminCreateWaitSetRequest

use of com.zimbra.soap.admin.message.AdminCreateWaitSetRequest in project zm-mailbox by Zimbra.

the class ImapServerListener method restoreWaitSet.

private synchronized void restoreWaitSet() throws ServiceException {
    ZimbraLog.imap.debug("Attempting to restore admin waitset for all registered listeners.");
    if (wsID != null) {
        ZimbraLog.imap.debug("Another thread has already restored waitset.");
        // another thread has already restored waitset
        return;
    }
    cancelPendingRequest();
    AdminCreateWaitSetRequest req = new AdminCreateWaitSetRequest("all", false);
    checkAuth();
    AdminCreateWaitSetResponse resp;
    resp = soapProv.invokeJaxbAsAdminWithRetry(req, server);
    if (resp == null) {
        throw ServiceException.FAILURE("Received null response from AdminCreateWaitSetRequest", null);
    }
    wsID = resp.getWaitSetId();
    setWaitSetIdOnMailboxes();
    lastSequence.set(resp.getSequence());
    ZimbraLog.imap.debug("Created new waitset to replace lost or cancelled one. WaitSet ID: %s", wsID);
    // send non-blocking synchronous WaitSetRequest. This way the caller has certainty that listeners were added on remote server
    AdminWaitSetRequest waitSetReq = new AdminWaitSetRequest(wsID, lastSequence.toString());
    waitSetReq.setBlock(false);
    waitSetReq.setExpand(true);
    Enumeration<String> accountIds = this.sessionMap.keys();
    while (accountIds.hasMoreElements()) {
        String accountId = accountIds.nextElement();
        WaitSetAddSpec updateOrAdd = new WaitSetAddSpec();
        updateOrAdd.setId(accountId);
        Enumeration<Integer> folderIDs = this.sessionMap.get(accountId).keys();
        while (folderIDs.hasMoreElements()) {
            updateOrAdd.addFolderInterest(folderIDs.nextElement());
            ZimbraLog.imap.debug("Adding account %s to waitset %s", accountId, wsID);
            waitSetReq.addAddAccount(updateOrAdd);
        }
    }
    ZimbraLog.imap.debug("Sending initial AdminWaitSetRequest. WaitSet ID: %s", wsID);
    AdminWaitSetResponse wsResp = soapProv.invokeJaxbAsAdminWithRetry(waitSetReq, server);
    try {
        processAdminWaitSetResponse(wsResp);
    } catch (Exception e) {
        throw ServiceException.FAILURE("Failed to process initial AdminWaitSetResponse", e);
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AdminWaitSetRequest(com.zimbra.soap.admin.message.AdminWaitSetRequest) WaitSetAddSpec(com.zimbra.soap.type.WaitSetAddSpec) AdminWaitSetResponse(com.zimbra.soap.admin.message.AdminWaitSetResponse) SoapFaultException(com.zimbra.common.soap.SoapFaultException) ServiceException(com.zimbra.common.service.ServiceException) AdminServiceException(com.zimbra.cs.service.admin.AdminServiceException) AdminCreateWaitSetRequest(com.zimbra.soap.admin.message.AdminCreateWaitSetRequest) AdminCreateWaitSetResponse(com.zimbra.soap.admin.message.AdminCreateWaitSetResponse)

Example 3 with AdminCreateWaitSetRequest

use of com.zimbra.soap.admin.message.AdminCreateWaitSetRequest in project zm-mailbox by Zimbra.

the class ImapServerListener method initWaitSet.

private synchronized void initWaitSet(String accountId, boolean alreadyListening) throws ServiceException {
    if (wsID == null && this.sessionMap.containsKey(accountId)) {
        AdminCreateWaitSetRequest req = new AdminCreateWaitSetRequest("all", false);
        checkAuth();
        AdminCreateWaitSetResponse resp;
        resp = soapProv.invokeJaxbAsAdminWithRetry(req, server);
        if (resp == null) {
            throw ServiceException.FAILURE("Received null response from AdminCreateWaitSetRequest", null);
        }
        wsID = resp.getWaitSetId();
        setWaitSetIdOnMailboxes();
        lastSequence.set(resp.getSequence());
    } else {
        cancelPendingRequest();
    }
    ZimbraLog.imap.debug("Current waitset ID is %s", wsID);
    // send non-blocking synchronous WaitSetRequest. This way the caller has certainty that listener was added on remote server
    AdminWaitSetRequest waitSetReq = new AdminWaitSetRequest(wsID, lastSequence.toString());
    waitSetReq.setBlock(false);
    waitSetReq.setExpand(true);
    if (!this.sessionMap.containsKey(accountId) || this.sessionMap.get(accountId).isEmpty()) {
        ZimbraLog.imap.debug("Removing accout %s from waitset %s", accountId, wsID);
        waitSetReq.addRemoveAccount(new Id(accountId));
    } else {
        WaitSetAddSpec updateOrAdd = new WaitSetAddSpec();
        updateOrAdd.setId(accountId);
        Enumeration<Integer> folderIDs = this.sessionMap.get(accountId).keys();
        while (folderIDs.hasMoreElements()) {
            updateOrAdd.addFolderInterest(folderIDs.nextElement());
        }
        if (alreadyListening) {
            ZimbraLog.imap.debug("Updating folder interests for account %s in waitset %s", accountId, wsID);
            waitSetReq.addUpdateAccount(updateOrAdd);
        } else {
            ZimbraLog.imap.debug("Adding account %s to waitset %s", accountId, wsID);
            waitSetReq.addAddAccount(updateOrAdd);
        }
    }
    try {
        ZimbraLog.imap.debug("Sending initial AdminWaitSetRequest. WaitSet ID: %s", wsID);
        AdminWaitSetResponse wsResp = soapProv.invokeJaxbAsAdminWithRetry(waitSetReq, server);
        processAdminWaitSetResponse(wsResp);
    } catch (SoapFaultException e) {
        if (AdminServiceException.NO_SUCH_WAITSET.equalsIgnoreCase(e.getCode())) {
            // waitset is gone. Create a new one
            ZimbraLog.imap.warn("AdminWaitSet %s does not exist anymore", wsID);
            wsID = null;
            unsetWaitSetIdOnMailboxes();
            lastSequence.set(0);
            restoreWaitSet();
        } else {
            throw ServiceException.FAILURE("Failed to process initial AdminWaitSetResponse", e);
        }
    } catch (Exception e) {
        throw ServiceException.FAILURE("Failed to process initial AdminWaitSetResponse", e);
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AdminWaitSetRequest(com.zimbra.soap.admin.message.AdminWaitSetRequest) WaitSetAddSpec(com.zimbra.soap.type.WaitSetAddSpec) AdminWaitSetResponse(com.zimbra.soap.admin.message.AdminWaitSetResponse) Id(com.zimbra.soap.type.Id) SoapFaultException(com.zimbra.common.soap.SoapFaultException) SoapFaultException(com.zimbra.common.soap.SoapFaultException) ServiceException(com.zimbra.common.service.ServiceException) AdminServiceException(com.zimbra.cs.service.admin.AdminServiceException) AdminCreateWaitSetRequest(com.zimbra.soap.admin.message.AdminCreateWaitSetRequest) AdminCreateWaitSetResponse(com.zimbra.soap.admin.message.AdminCreateWaitSetResponse)

Aggregations

AdminCreateWaitSetRequest (com.zimbra.soap.admin.message.AdminCreateWaitSetRequest)3 AdminCreateWaitSetResponse (com.zimbra.soap.admin.message.AdminCreateWaitSetResponse)3 WaitSetAddSpec (com.zimbra.soap.type.WaitSetAddSpec)3 ServiceException (com.zimbra.common.service.ServiceException)2 SoapFaultException (com.zimbra.common.soap.SoapFaultException)2 AdminServiceException (com.zimbra.cs.service.admin.AdminServiceException)2 AdminWaitSetRequest (com.zimbra.soap.admin.message.AdminWaitSetRequest)2 AdminWaitSetResponse (com.zimbra.soap.admin.message.AdminWaitSetResponse)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 Id (com.zimbra.soap.type.Id)1 Document (org.dom4j.Document)1 DocumentResult (org.dom4j.io.DocumentResult)1