MCPcopy Create free account
hub / github.com/M66B/FairEmail / select

Method select

app/src/main/java/com/sun/mail/imap/IdleManager.java:234–285  ·  view source on GitHub ↗

Run the java.nio.channels.Selector#select select loop to poll each watched folder for events sent from the server.

()

Source from the content-addressed store, hash-verified

232 * to poll each watched folder for events sent from the server.
233 */
234 private void select() {
235 die = false;
236 try {
237 while (!die) {
238 watchAll();
239 logger.finest("IdleManager waiting...");
240 int ns = selector.select();
241 if (logger.isLoggable(Level.FINEST))
242 logger.log(Level.FINEST,
243 "IdleManager selected {0} channels", ns);
244 if (die || Thread.currentThread().isInterrupted())
245 break;
246
247 /*
248 * Process any selected folders. We cancel the
249 * selection key for any selected folder, so if we
250 * need to continue watching that folder it's added
251 * to the toWatch list again. We can't actually
252 * register that folder again until the previous
253 * selection key is cancelled, so we call selectNow()
254 * just for the side effect of cancelling the selection
255 * keys. But if selectNow() selects something, we
256 * process it before adding folders from the toWatch
257 * queue. And so on until there is nothing to do, at
258 * which point it's safe to register folders from the
259 * toWatch queue. This should be "fair" since each
260 * selection key is used only once before being added
261 * to the toWatch list.
262 */
263 do {
264 processKeys();
265 } while (selector.selectNow() > 0 || !toAbort.isEmpty());
266 }
267 } catch (InterruptedIOException ex) {
268 logger.log(Level.FINEST, "IdleManager interrupted", ex);
269 } catch (IOException ex) {
270 logger.log(Level.FINEST, "IdleManager got I/O exception", ex);
271 } catch (Exception ex) {
272 logger.log(Level.FINEST, "IdleManager got exception", ex);
273 } finally {
274 die = true; // prevent new watches in case of exception
275 logger.finest("IdleManager unwatchAll");
276 try {
277 unwatchAll();
278 selector.close();
279 } catch (IOException ex2) {
280 // nothing to do...
281 logger.log(Level.FINEST, "IdleManager unwatch exception", ex2);
282 }
283 logger.fine("IdleManager exiting");
284 }
285 }
286
287 /**
288 * Register all of the folders in the queue with the selector,

Callers 1

runMethod · 0.95

Calls 10

watchAllMethod · 0.95
processKeysMethod · 0.95
unwatchAllMethod · 0.95
finestMethod · 0.80
fineMethod · 0.80
selectMethod · 0.65
isLoggableMethod · 0.45
logMethod · 0.45
isEmptyMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected