Read a response from the server while we're in the IDLE state. We hold the messageCacheLock while processing the responses so that we can update the number of messages in the folder (for example). @param once only do one notification? @return true if we should look for more IDLE responses, false i
(boolean once)
| 3285 | * @since JavaMail 1.5.2 |
| 3286 | */ |
| 3287 | boolean handleIdle(boolean once) throws MessagingException { |
| 3288 | Response r = null; |
| 3289 | long start = SystemClock.elapsedRealtime(); |
| 3290 | long restartIdleInterval = ((IMAPStore)store).getRestartIdleInterval() * 1000L; |
| 3291 | do { |
| 3292 | r = protocol.readIdleResponse(); |
| 3293 | try { |
| 3294 | synchronized (messageCacheLock) { |
| 3295 | if (r.isBYE() && r.isSynthetic() && idleState == IDLE) { |
| 3296 | /* |
| 3297 | * If it was a timeout and no bytes were transferred |
| 3298 | * we ignore it and go back and read again. |
| 3299 | * If the I/O was otherwise interrupted, and no |
| 3300 | * bytes were transferred, we take it as a request |
| 3301 | * to abort the IDLE. |
| 3302 | */ |
| 3303 | Exception ex = r.getException(); |
| 3304 | if (ex instanceof InterruptedIOException && |
| 3305 | ((InterruptedIOException)ex). |
| 3306 | bytesTransferred == 0) { |
| 3307 | if (ex instanceof SocketTimeoutException) { |
| 3308 | logger.finest( |
| 3309 | "handleIdle: ignoring socket timeout"); |
| 3310 | r = null; // repeat do/while loop |
| 3311 | long elapsed = SystemClock.elapsedRealtime() - start; |
| 3312 | if (restartIdleInterval > 0 && elapsed > restartIdleInterval) { |
| 3313 | logger.finest("handleIdle: restart elapsed=" + elapsed); |
| 3314 | protocol.idleAbort(); |
| 3315 | idleState = ABORTING; |
| 3316 | } |
| 3317 | } else { |
| 3318 | logger.finest("handleIdle: interrupting IDLE"); |
| 3319 | IdleManager im = idleManager; |
| 3320 | if (im != null) { |
| 3321 | logger.finest( |
| 3322 | "handleIdle: request IdleManager to abort"); |
| 3323 | im.requestAbort(this); |
| 3324 | } else { |
| 3325 | logger.finest("handleIdle: abort IDLE"); |
| 3326 | protocol.idleAbort(); |
| 3327 | idleState = ABORTING; |
| 3328 | } |
| 3329 | // normally will exit the do/while loop |
| 3330 | } |
| 3331 | continue; |
| 3332 | } |
| 3333 | } |
| 3334 | boolean done = true; |
| 3335 | try { |
| 3336 | if (protocol == null || |
| 3337 | !protocol.processIdleResponse(r)) |
| 3338 | return false; // done |
| 3339 | done = false; |
| 3340 | } finally { |
| 3341 | if (done) { |
| 3342 | logger.finest("handleIdle: set to RUNNING"); |
| 3343 | idleState = RUNNING; |
| 3344 | idleManager = null; |
no test coverage detected