Author: elecharny Date: Wed Feb 17 22:22:48 2010 New Revision: 911196 URL: http://svn.apache.org/viewvc?rev=911196&view=rev Log: o Added missing javadoc o Added some comments o Renamed some method to make their action more explicit
Modified: mina/trunk/core/src/main/java/org/apache/mina/core/polling/AbstractPollingConnectionlessIoAcceptor.java mina/trunk/core/src/main/java/org/apache/mina/core/polling/AbstractPollingIoProcessor.java mina/trunk/core/src/main/java/org/apache/mina/core/session/AbstractIoSession.java Modified: mina/trunk/core/src/main/java/org/apache/mina/core/polling/AbstractPollingConnectionlessIoAcceptor.java URL: http://svn.apache.org/viewvc/mina/trunk/core/src/main/java/org/apache/mina/core/polling/AbstractPollingConnectionlessIoAcceptor.java?rev=911196&r1=911195&r2=911196&view=diff ============================================================================== --- mina/trunk/core/src/main/java/org/apache/mina/core/polling/AbstractPollingConnectionlessIoAcceptor.java (original) +++ mina/trunk/core/src/main/java/org/apache/mina/core/polling/AbstractPollingConnectionlessIoAcceptor.java Wed Feb 17 22:22:48 2010 @@ -362,6 +362,9 @@ } private boolean scheduleFlush(T session) { + // Set the schedule for flush flag if the session + // has not already be added to the flushingSessions + // queue if (session.setScheduledForFlush(true)) { flushingSessions.add(session); return true; @@ -477,7 +480,9 @@ break; } - session.setScheduledForFlush(false); + // Reset the Schedule for flush flag for this session, + // as we are flushing it now + session.unscheduledForFlush(); try { boolean flushedAll = flush(session, currentTime); Modified: mina/trunk/core/src/main/java/org/apache/mina/core/polling/AbstractPollingIoProcessor.java URL: http://svn.apache.org/viewvc/mina/trunk/core/src/main/java/org/apache/mina/core/polling/AbstractPollingIoProcessor.java?rev=911196&r1=911195&r2=911196&view=diff ============================================================================== --- mina/trunk/core/src/main/java/org/apache/mina/core/polling/AbstractPollingIoProcessor.java (original) +++ mina/trunk/core/src/main/java/org/apache/mina/core/polling/AbstractPollingIoProcessor.java Wed Feb 17 22:22:48 2010 @@ -428,15 +428,18 @@ * {...@inheritdoc} */ public final void flush(T session) { - if (session.setScheduledForFlush(true)) { + // add the session to the queue if it's not already + // in the queue, then wake up the select() + if (session.setScheduledForFlush( true )) { flushingSessions.add(session); wakeup(); } } private void scheduleFlush(T session) { + // add the session to the queue if it's not already + // in the queue if (session.setScheduledForFlush(true)) { - // add the session to the queue flushingSessions.add(session); } } @@ -666,9 +669,11 @@ } // Process writes - if (isWritable(session) && !session.isWriteSuspended() && session.setScheduledForFlush(true)) { - // add the session to the queue - flushingSessions.add(session); + if (isWritable(session) && !session.isWriteSuspended()) { + // add the session to the queue, if it's not already there + if (session.setScheduledForFlush(true)) { + flushingSessions.add(session); + } } } @@ -758,7 +763,10 @@ break; } - session.setScheduledForFlush(false); + // Reset the Schedule for flush flag for this session, + // as we are flushing it now + session.unscheduledForFlush(); + SessionState state = getState(session); switch (state) { Modified: mina/trunk/core/src/main/java/org/apache/mina/core/session/AbstractIoSession.java URL: http://svn.apache.org/viewvc/mina/trunk/core/src/main/java/org/apache/mina/core/session/AbstractIoSession.java?rev=911196&r1=911195&r2=911196&view=diff ============================================================================== --- mina/trunk/core/src/main/java/org/apache/mina/core/session/AbstractIoSession.java (original) +++ mina/trunk/core/src/main/java/org/apache/mina/core/session/AbstractIoSession.java Wed Feb 17 22:22:48 2010 @@ -206,22 +206,43 @@ } /** - * TODO Add method documentation + * Tells if the session is scheduled for flushed + * @param true if the session is scheduled for flush */ public final boolean isScheduledForFlush() { return scheduledForFlush.get(); } /** - * TODO Add method documentation + * Schedule the session for flushed + */ + public final void scheduledForFlush() { + scheduledForFlush.set(true); + } + + /** + * Change the session's status : it's not anymore scheduled for flush */ - public final boolean setScheduledForFlush(boolean flag) { - if (flag) { - // If the current tag is set to false, switch it to true - return scheduledForFlush.compareAndSet(false, true); + public final void unscheduledForFlush() { + scheduledForFlush.set(false); + } + + /** + * Set the scheduledForFLush flag. As we may have concurrent access + * to this flag, we compare and set it in one call. + * @param schedule the new value to set if not already set. + * @return true if the session flag has been set, and if + * it wasn't set already. + */ + public final boolean setScheduledForFlush(boolean schedule) { + if (schedule) { + // If the current tag is set to false, switch it to true, + // otherwise, we do nothing but return false : the session + // is already scheduled for flush + return scheduledForFlush.compareAndSet(false, schedule); } - scheduledForFlush.set(false); + scheduledForFlush.set(schedule); return true; }