Search in sources :

Example 1 with WaitSetInfo

use of com.zimbra.soap.admin.type.WaitSetInfo in project zm-mailbox by Zimbra.

the class SomeAccountsWaitSet method isMonitoringFolder.

/**
 * Keeping this for possible future use.  Currently it is not reliable as WaitSets aren't necessarily
 * cleaned up immediately, resulting in false positives.
 */
public synchronized boolean isMonitoringFolder(String accountId, int folderId) {
    WaitSetInfo info = super.handleQuery();
    info.setCbSeqNo(Long.toString(mCbSeqNo));
    info.setCurrentSeqNo(Long.toString(mCurrentSeqNo));
    for (Map.Entry<String, WaitSetAccount> entry : mSessions.entrySet()) {
        String acctId = entry.getKey();
        if (!accountId.equals(acctId)) {
            continue;
        }
        WaitSetAccount wsa = entry.getValue();
        Set<Integer> folderInterests = wsa.getFolderInterests();
        if ((folderInterests != null) && folderInterests.contains(folderId)) {
            return true;
        }
    }
    return false;
}
Also used : WaitSetInfo(com.zimbra.soap.admin.type.WaitSetInfo) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with WaitSetInfo

use of com.zimbra.soap.admin.type.WaitSetInfo in project zm-mailbox by Zimbra.

the class TestImapServerListener method testRemoveFolderInterest.

@Test
public void testRemoveFolderInterest() throws Exception {
    Assume.assumeNotNull(remoteServer);
    Assume.assumeNotNull(remoteAccount);
    RemoteImapMailboxStore imapStore = new RemoteImapMailboxStore(mboxStore);
    ImapCredentials creds = new ImapCredentials(remoteAccount);
    // add listener on INBOX
    ImapPath path = new ImapPath("INBOX", creds);
    byte params = 0;
    ImapHandler handler = new MockImapHandler().setCredentials(creds);
    ImapFolder i4folder = new ImapFolder(path, params, handler);
    MockImapListener inboxSession = new MockImapListener(imapStore, i4folder, handler);
    remoteListener.addListener(inboxSession);
    // check created waitset
    QueryWaitSetResponse resp = TestUtil.waitForSessions(1, 1, 6000, remoteListener.getWSId(), remoteServer);
    assertNotNull(resp);
    List<WaitSetInfo> wsInfoList = resp.getWaitsets();
    assertFalse(wsInfoList.isEmpty());
    assertEquals(1, wsInfoList.size());
    WaitSetInfo wsInfo = wsInfoList.get(0);
    assertNotNull(wsInfo);
    assertEquals(remoteListener.getWSId(), wsInfo.getWaitSetId());
    List<SessionForWaitSet> sessions = wsInfo.getSessions();
    assertNotNull(sessions);
    assertEquals("expected to find 1 session after adding a listener for INBOX", 1, sessions.size());
    SessionForWaitSet s = sessions.get(0);
    Set<Integer> folders = s.getWaitSetSession().getFolderInterestsAsSet();
    assertNotNull("folder interests cannot be NULL", folders);
    assertEquals("should have one folder interest", 1, folders.size());
    assertTrue("folder interests should contain INBOX", folders.contains(Mailbox.ID_FOLDER_INBOX));
    // add listener on DRAFTS
    path = new ImapPath("DRAFTS", creds);
    params = 0;
    i4folder = new ImapFolder(path, params, handler);
    ImapRemoteSession draftsSession = (ImapRemoteSession) imapStore.createListener(i4folder, handler);
    remoteListener.addListener(draftsSession);
    // check that waitset was updated
    resp = TestUtil.waitForSessions(1, 2, 6000, remoteListener.getWSId(), remoteServer);
    assertNotNull(resp);
    wsInfoList = resp.getWaitsets();
    assertFalse(wsInfoList.isEmpty());
    wsInfo = wsInfoList.get(0);
    assertNotNull(wsInfo);
    assertEquals(remoteListener.getWSId(), wsInfo.getWaitSetId());
    sessions = wsInfo.getSessions();
    assertNotNull(sessions);
    assertEquals("expected to find 1 session after adding a listener for DRAFTS", 1, sessions.size());
    s = sessions.get(0);
    folders = s.getWaitSetSession().getFolderInterestsAsSet();
    assertNotNull("folder interests cannot be NULL", folders);
    assertEquals("should have two folder interests", 2, folders.size());
    assertTrue("folder interests should contain DRAFTS", folders.contains(Mailbox.ID_FOLDER_DRAFTS));
    assertTrue("folder interests should contain INBOX", folders.contains(Mailbox.ID_FOLDER_INBOX));
    remoteListener.removeListener(inboxSession);
    // check that waitset was updated after removing a listener
    resp = TestUtil.waitForSessions(1, 1, 6000, remoteListener.getWSId(), remoteServer);
    assertNotNull(resp);
    wsInfoList = resp.getWaitsets();
    assertFalse(wsInfoList.isEmpty());
    wsInfo = wsInfoList.get(0);
    assertNotNull(wsInfo);
    assertEquals(remoteListener.getWSId(), wsInfo.getWaitSetId());
    sessions = wsInfo.getSessions();
    assertNotNull(sessions);
    assertEquals("expected to find 1 session after removing listener for inbox", 1, sessions.size());
    s = sessions.get(0);
    folders = s.getWaitSetSession().getFolderInterestsAsSet();
    assertNotNull("folder interests cannot be NULL", folders);
    assertEquals("should have one folder interest after removing a listener", 1, folders.size());
    assertTrue("folder interests should contain DRAFTS after removing INBOX listener", folders.contains(Mailbox.ID_FOLDER_DRAFTS));
}
Also used : ImapRemoteSession(com.zimbra.cs.imap.ImapRemoteSession) ImapFolder(com.zimbra.cs.imap.ImapFolder) QueryWaitSetResponse(com.zimbra.soap.admin.message.QueryWaitSetResponse) RemoteImapMailboxStore(com.zimbra.cs.imap.RemoteImapMailboxStore) ImapHandler(com.zimbra.cs.imap.ImapHandler) ImapCredentials(com.zimbra.cs.imap.ImapCredentials) ImapPath(com.zimbra.cs.imap.ImapPath) WaitSetInfo(com.zimbra.soap.admin.type.WaitSetInfo) SessionForWaitSet(com.zimbra.soap.admin.type.SessionForWaitSet) Test(org.junit.Test)

Example 3 with WaitSetInfo

use of com.zimbra.soap.admin.type.WaitSetInfo in project zm-mailbox by Zimbra.

the class TestUtil method waitForSessions.

public static QueryWaitSetResponse waitForSessions(int numExpectedSessions, int numExpectedFolderInterests, int timeout_millis, String wsID, Server server) throws Exception {
    QueryWaitSetResponse resp = null;
    while (timeout_millis > 0) {
        QueryWaitSetRequest req = new QueryWaitSetRequest(wsID);
        SoapTransport transport = getAdminSoapTransport(server);
        resp = JaxbUtil.elementToJaxb(transport.invoke(JaxbUtil.jaxbToElement(req)));
        List<WaitSetInfo> wsInfoList = resp.getWaitsets();
        assertFalse("Expecting to find a waitset", wsInfoList.isEmpty());
        assertEquals("Expecting to find only one waitset", 1, wsInfoList.size());
        WaitSetInfo wsInfo = wsInfoList.get(0);
        assertEquals("Found wrong waitset", wsID, wsInfo.getWaitSetId());
        List<SessionForWaitSet> sessions = wsInfo.getSessions();
        if (sessions != null && numExpectedSessions > 0) {
            if (sessions.size() == numExpectedSessions) {
                int foundFolderInterests = 0;
                for (SessionForWaitSet s : sessions) {
                    WaitSetSessionInfo sessionInfo = s.getWaitSetSession();
                    if (sessionInfo != null) {
                        foundFolderInterests += s.getWaitSetSession().getFolderInterestsAsSet().size();
                    }
                }
                if (foundFolderInterests == numExpectedFolderInterests) {
                    return resp;
                }
            }
        } else if ((sessions == null || sessions.isEmpty()) && numExpectedSessions == 0) {
            return resp;
        }
        try {
            if (timeout_millis > 500) {
                Thread.sleep(500);
                timeout_millis = timeout_millis - 500;
            } else {
                Thread.sleep(timeout_millis);
                timeout_millis = 0;
            }
        } catch (InterruptedException e) {
            ZimbraLog.test.debug("sleep got interrupted", e);
        }
    }
    return resp;
}
Also used : WaitSetSessionInfo(com.zimbra.soap.admin.type.WaitSetSessionInfo) WaitSetInfo(com.zimbra.soap.admin.type.WaitSetInfo) QueryWaitSetResponse(com.zimbra.soap.admin.message.QueryWaitSetResponse) SessionForWaitSet(com.zimbra.soap.admin.type.SessionForWaitSet) QueryWaitSetRequest(com.zimbra.soap.admin.message.QueryWaitSetRequest) SoapTransport(com.zimbra.common.soap.SoapTransport) ZMountpoint(com.zimbra.client.ZMountpoint)

Example 4 with WaitSetInfo

use of com.zimbra.soap.admin.type.WaitSetInfo in project zm-mailbox by Zimbra.

the class AllAccountsWaitSet method handleQuery.

@Override
public synchronized WaitSetInfo handleQuery() {
    WaitSetInfo info = super.handleQuery();
    info.setCbSeqNo(mCbSeqNo);
    info.setCurrentSeqNo(mCurrentSeqNo);
    info.setNextSeqNo(mNextSeqNo);
    if (mBufferedCommits != null) {
        for (Pair<String, String> p : mBufferedCommits) {
            info.addBufferedCommit(new BufferedCommitInfo(p.getFirst(), p.getSecond()));
        }
    }
    return info;
}
Also used : WaitSetInfo(com.zimbra.soap.admin.type.WaitSetInfo) BufferedCommitInfo(com.zimbra.soap.admin.type.BufferedCommitInfo)

Example 5 with WaitSetInfo

use of com.zimbra.soap.admin.type.WaitSetInfo in project zm-mailbox by Zimbra.

the class SomeAccountsWaitSet method handleQuery.

@Override
public synchronized WaitSetInfo handleQuery() {
    WaitSetInfo info = super.handleQuery();
    info.setCbSeqNo(Long.toString(mCbSeqNo));
    info.setCurrentSeqNo(Long.toString(mCurrentSeqNo));
    for (Map.Entry<String, WaitSetAccount> entry : mSessions.entrySet()) {
        String acctId = entry.getKey();
        WaitSetAccount wsa = entry.getValue();
        SessionForWaitSet sess = new SessionForWaitSet(acctId, WaitSetRequest.expandInterestStr(wsa.getInterests()));
        if (!wsa.getAccountId().equals(acctId)) {
            sess.setAcctIdError(wsa.getAccountId());
        }
        if (wsa.getLastKnownSyncToken() != null) {
            sess.setToken(wsa.getLastKnownSyncToken().toString());
        }
        if (wsa.getLastKnownSyncToken() != null) {
            try {
                Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(acctId, FetchMode.ONLY_IF_CACHED);
                if (mbox != null) {
                    int mboxLastChange = mbox.getLastChangeID();
                    sess.setMboxSyncToken(mboxLastChange);
                    sess.setMboxSyncTokenDiff(mboxLastChange - wsa.getLastKnownSyncToken().getChangeId());
                }
            } catch (Exception e) {
                ZimbraLog.session.warn("Caught exception from MailboxManager in SomeAccountsWaitSet.handleQuery() for accountId %s", acctId, e);
            }
        }
        WaitSetSession wss = wsa.getSession();
        if (wss != null) {
            WaitSetSessionInfo waitSetSession = new WaitSetSessionInfo(WaitSetRequest.interestToStr(wss.interest), wss.mHighestChangeId, wss.getLastAccessTime(), wss.getCreationTime(), wss.getSessionId());
            waitSetSession.setFolderInterests(wss.folderInterest);
            if (wss.mSyncToken != null) {
                waitSetSession.setToken(wss.mSyncToken.toString());
            }
            sess.setWaitSetSession(waitSetSession);
        }
        info.addSession(sess);
    }
    return info;
}
Also used : WaitSetSessionInfo(com.zimbra.soap.admin.type.WaitSetSessionInfo) WaitSetInfo(com.zimbra.soap.admin.type.WaitSetInfo) Mailbox(com.zimbra.cs.mailbox.Mailbox) SessionForWaitSet(com.zimbra.soap.admin.type.SessionForWaitSet) HashMap(java.util.HashMap) Map(java.util.Map) AccountServiceException(com.zimbra.cs.account.AccountServiceException) ServiceException(com.zimbra.common.service.ServiceException)

Aggregations

WaitSetInfo (com.zimbra.soap.admin.type.WaitSetInfo)8 SessionForWaitSet (com.zimbra.soap.admin.type.SessionForWaitSet)4 QueryWaitSetResponse (com.zimbra.soap.admin.message.QueryWaitSetResponse)3 WaitSetSessionInfo (com.zimbra.soap.admin.type.WaitSetSessionInfo)3 SoapTransport (com.zimbra.common.soap.SoapTransport)2 ImapCredentials (com.zimbra.cs.imap.ImapCredentials)2 ImapFolder (com.zimbra.cs.imap.ImapFolder)2 ImapHandler (com.zimbra.cs.imap.ImapHandler)2 ImapPath (com.zimbra.cs.imap.ImapPath)2 RemoteImapMailboxStore (com.zimbra.cs.imap.RemoteImapMailboxStore)2 QueryWaitSetRequest (com.zimbra.soap.admin.message.QueryWaitSetRequest)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Test (org.junit.Test)2 ZMountpoint (com.zimbra.client.ZMountpoint)1 ServiceException (com.zimbra.common.service.ServiceException)1 AccountServiceException (com.zimbra.cs.account.AccountServiceException)1 ImapRemoteSession (com.zimbra.cs.imap.ImapRemoteSession)1 Mailbox (com.zimbra.cs.mailbox.Mailbox)1 AccountsAttrib (com.zimbra.soap.admin.type.AccountsAttrib)1