Search in sources :

Example 1 with SessionPollerSender

use of org.forgerock.openam.session.SessionPollerSender in project OpenAM by OpenRock.

the class Session method run.

public void run() {
    if (sessionPollerPool.isPollingEnabled()) {
        try {
            if (!getIsPolling()) {
                long expectedTime;
                if (willExpire(maxIdleTime)) {
                    expectedTime = (latestRefreshTime + (maxIdleTime * 60)) * 1000;
                    if (sessionPollerPool.getCacheBasedPolling()) {
                        expectedTime = Math.min(expectedTime, (latestRefreshTime + (maxCachingTime * 60)) * 1000);
                    }
                } else {
                    expectedTime = (latestRefreshTime + (SessionMeta.getAppSSOTokenRefreshTime() * 60)) * 1000;
                }
                if (expectedTime > scheduledExecutionTime()) {
                    // Get an instance as required otherwise it causes issues on container restart.
                    SystemTimerPool.getTimerPool().schedule(this, new Date(expectedTime));
                    return;
                }
                if (sender == null) {
                    sender = new SessionPollerSender(this);
                }
                RestrictedTokenContext.doUsing(getContext(), new RestrictedTokenAction() {

                    public Object run() throws Exception {
                        try {
                            setIsPolling(true);
                            sessionPollerPool.getThreadPool().run(sender);
                        } catch (ThreadPoolException e) {
                            setIsPolling(false);
                            sessionDebug.error("Send Polling Error: ", e);
                        }
                        return null;
                    }
                });
            }
        } catch (SessionException se) {
            sessionCache.removeSID(sessionID);
            sessionDebug.message("session is not in timeout state so clean it", se);
        } catch (Exception ex) {
            sessionDebug.error("Exception encountered while polling", ex);
        }
    } else {
        String sessionRemovalDebugMessage;
        if (purgeAt > 0) {
            // destroyed session scheduled for purge
            if (purgeAt > scheduledExecutionTime()) {
                SystemTimerPool.getTimerPool().schedule(this, new Date(purgeAt));
                return;
            }
            sessionRemovalDebugMessage = "Session Removed, Reduced Crosstalk Purge Time complete";
        } else {
            // schedule at the max session time
            long expectedTime = -1;
            if (willExpire(maxSessionTime)) {
                expectedTime = (latestRefreshTime + (maxSessionTime * 60)) * 1000;
            }
            if (expectedTime > scheduledExecutionTime()) {
                SystemTimerPool.getTimerPool().schedule(this, new Date(expectedTime));
                return;
            }
            sessionRemovalDebugMessage = "Session Destroyed, Caching time exceeded the Max Session Time";
        }
        try {
            sessionCache.removeSID(sessionID);
            if (sessionDebug.messageEnabled()) {
                sessionDebug.message(sessionRemovalDebugMessage);
            }
        } catch (Exception ex) {
            sessionDebug.error("Exception occured while cleaning up Session Cache", ex);
        }
    }
}
Also used : SessionPollerSender(org.forgerock.openam.session.SessionPollerSender) ThreadPoolException(com.iplanet.am.util.ThreadPoolException) Date(java.util.Date) RestrictedTokenAction(com.sun.identity.session.util.RestrictedTokenAction) ThreadPoolException(com.iplanet.am.util.ThreadPoolException) SSOException(com.iplanet.sso.SSOException)

Aggregations

ThreadPoolException (com.iplanet.am.util.ThreadPoolException)1 SSOException (com.iplanet.sso.SSOException)1 RestrictedTokenAction (com.sun.identity.session.util.RestrictedTokenAction)1 Date (java.util.Date)1 SessionPollerSender (org.forgerock.openam.session.SessionPollerSender)1