public int processIdleSession()

in core/src/main/java/org/apache/mina/service/idlechecker/IndexedIdleChecker.java [210:249]


    public int processIdleSession(long timeMs) {
        int counter = 0;
        long delta = timeMs - lastCheckTimeMs;

        if (LOG.isTraceEnabled()) {
            LOG.trace("checking idle time, last = {}, now = {}, delta = {}", new Object[] { lastCheckTimeMs, timeMs,
                    delta });
        }

        if (delta < 1000) {
            LOG.debug("not a second between the last checks, abort");
            return 0;
        }

        // if (lastCheckTimeMs == 0) {
        // LOG.debug("first check, we start now");
        // lastCheckTimeMs = System.currentTimeMillis() - 1000;
        // }
        int startIdx = ((int) (Math.max(lastCheckTimeMs, timeMs - MAX_IDLE_TIME_IN_MS + 1) / 1000L))
                % MAX_IDLE_TIME_IN_SEC;
        int endIdx = ((int) (timeMs / 1000L)) % MAX_IDLE_TIME_IN_SEC;

        LOG.trace("scaning from index {} to index {}", startIdx, endIdx);

        int index = startIdx;
        do {

            LOG.trace("scanning index {}", index);
            // look at the read idle index
            counter += processIndex(readIdleSessionIndex, index, IdleStatus.READ_IDLE);
            counter += processIndex(writeIdleSessionIndex, index, IdleStatus.WRITE_IDLE);

            index = (index + 1) % MAX_IDLE_TIME_IN_SEC;
        } while (index != endIdx);

        // save last check time for next call
        lastCheckTimeMs = timeMs;
        LOG.trace("detected {} idleing sessions", counter);
        return counter;
    }