Start the IDLE command and put this folder into the IDLE state. IDLE processing is done later in handleIdle(), e.g., called from the IdleManager. @return true if IDLE started, false otherwise @exception MessagingException if the server doesn't support the IDLE extension @exception IllegalStateE
(final IdleManager im)
| 3227 | * @since JavaMail 1.5.2 |
| 3228 | */ |
| 3229 | boolean startIdle(final IdleManager im) throws MessagingException { |
| 3230 | // ASSERT: Must NOT be called with this folder's |
| 3231 | // synchronization lock held. |
| 3232 | assert !Thread.holdsLock(this); |
| 3233 | synchronized(this) { |
| 3234 | checkOpened(); |
| 3235 | if (im != null && idleManager != null && im != idleManager) |
| 3236 | throw new MessagingException( |
| 3237 | "Folder already being watched by another IdleManager"); |
| 3238 | Boolean started = (Boolean)doOptionalCommand("IDLE not supported", |
| 3239 | new ProtocolCommand() { |
| 3240 | @Override |
| 3241 | public Object doCommand(IMAPProtocol p) |
| 3242 | throws ProtocolException { |
| 3243 | // if the IdleManager is already watching this folder, |
| 3244 | // there's nothing to do here |
| 3245 | if (idleState == IDLE && |
| 3246 | im != null && im == idleManager) |
| 3247 | return Boolean.TRUE; // already watching it |
| 3248 | if (idleState == RUNNING) { |
| 3249 | p.idleStart(); |
| 3250 | logger.finest("startIdle: set to IDLE"); |
| 3251 | idleState = IDLE; |
| 3252 | idleManager = im; |
| 3253 | return Boolean.TRUE; |
| 3254 | } else { |
| 3255 | // some other thread must be running the IDLE |
| 3256 | // command, we'll just wait for it to finish |
| 3257 | // without aborting it ourselves |
| 3258 | try { |
| 3259 | // give up lock and wait to be not idle |
| 3260 | messageCacheLock.wait(); |
| 3261 | } catch (InterruptedException ex) { |
| 3262 | // restore the interrupted state, which callers |
| 3263 | // might depend on |
| 3264 | Thread.currentThread().interrupt(); |
| 3265 | } |
| 3266 | return Boolean.FALSE; |
| 3267 | } |
| 3268 | } |
| 3269 | }); |
| 3270 | logger.log(Level.FINEST, "startIdle: return {0}", started); |
| 3271 | return started.booleanValue(); |
| 3272 | } |
| 3273 | } |
| 3274 | |
| 3275 | /** |
| 3276 | * Read a response from the server while we're in the IDLE state. |
no test coverage detected