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