/**
* Loads the messages in the queue.
*/
public void loadNextBatch() {
MessageProxy mp;
// start this load section.
int queueSize = getQueueSize();
if (! stopped) {
if (queueSize > 0) {
folderInfo.getLogger().log(java.util.logging.Level.FINE, folderInfo.getFolderID() + " loading " + queueSize + " messages.");
// get the batch sizes.
int fetchBatchSize = 50;
try {
fetchBatchSize = Integer.parseInt(Pooka.getProperty("Pooka.fetchBatchSize", "50"));
} catch (NumberFormatException nfe) {
}
FetchProfile fetchProfile = getFolderInfo().getFetchProfile();
// get the next batch.
List messageProxies = retrieveNextBatch(fetchBatchSize);
List toFetchInfos = new LinkedList();
// go through and find all of the messages that need to be fetched
// or refetched, and add them to the toFetchInfos list.
for (int i = 0 ; i < messageProxies.size(); i++) {
MessageInfo fetchCheckInfo = ((MessageProxy) messageProxies.get(i)).getMessageInfo();
if (! fetchCheckInfo.hasBeenFetched()) {
toFetchInfos.add(fetchCheckInfo);
}
}
if (toFetchInfos.size() > 0) {
try {
MessageInfo[] toFetch = new MessageInfo[toFetchInfos.size()];
toFetch = (MessageInfo[]) toFetchInfos.toArray(toFetch);
getFolderInfo().fetch(toFetch, fetchProfile);
} catch(MessagingException me) {
if (folderInfo.getLogger().isLoggable(java.util.logging.Level.WARNING)) {
System.out.println("caught error while fetching for folder " + getFolderInfo().getFolderID() + ": " + me);
me.printStackTrace();
}
}
}
// now load each individual messageproxy.
// and refresh each message.
for (int i = 0 ; i < messageProxies.size(); i++) {
mp = (MessageProxy) messageProxies.get(i);
try {
if (! mp.isLoaded())
mp.loadTableInfo();
if (mp.needsRefresh()) {
mp.refreshMessage();
}
else if (! mp.matchedFilters()) {
mp.matchFilters();
}
} catch (Exception e) {
if (folderInfo.getLogger().isLoggable(java.util.logging.Level.WARNING)) {
e.printStackTrace();
}
}
}
} else if (getCacheQueueSize() > 0) {
try {
MessageProxy nextCache = (MessageProxy) cacheQueue.remove(0);
if (folderInfo instanceof CachingFolderInfo) {
MessageInfo mi = nextCache.getMessageInfo();
MimeMessage mimeMessage = (MimeMessage) mi.getMessage();
CachingFolderInfo cfi = (CachingFolderInfo) folderInfo;
if (cfi.getFolderDisplayUI() != null) {
cfi.showStatusMessage(cfi.getFolderDisplayUI(), "caching messages, " + getCacheQueueSize() + " remaining...");
}