TO DO --Use StoreCallback instead of SessionEventDispatcher??
961496
@ProbeAtEntry
    @ProbeSite(clazz="com.ibm.ws.session.SessionEventDispatcher",method="sessionLiveCountInc",args="java.lang.Object")
    public void IncrementLiveCount(@Args Object[] myargs )
    {                      	
        if(tc.isEntryEnabled()){
            Tr.entry(tc, "IncrementLiveCount");
        }
        if(myargs == null){
            if(tc.isEntryEnabled()){
                Tr.exit(tc, "IncrementLiveCount","Args list is null");
            }
            return;
        }
        ISession session = (ISession) myargs[0];
        
        if(session == null){
            if(tc.isEntryEnabled()){
                Tr.exit(tc,"IncrementLiveCount","session object is null"); 
            }
              return;
        }        
        String appName =  session.getIStore().getId();        
        SessionStats sStats = sessionCountByName.get(appName);        
        if(sStats==null){
            sStats = initializeSessionStats(appName ,new SessionStats() );
        }      
        
        sStats.liveCountInc();    
        if(tc.isEntryEnabled()){
            Tr.exit(tc, "IncrementLiveCount");
        }
    }
808488
async function session(ctx, next) {
    ctx.sessionStore = store
    if (ctx.session || ctx._session) {
      return next()
    }
    const result = await getSession(ctx)
    if (!result) {
      return next()
    }

    addCommonAPI(ctx)

    ctx._session = result.session

    // more flexible
    Object.defineProperty(ctx, 'session', {
      get() {
        return this._session
      },
      set(sess) {
        this._session = sess
      }
    })

    ctx.regenerateSession = async function regenerateSession() {
      debug('regenerating session')
      if (!result.isNew) {
        // destroy the old session
        debug('destroying previous session')
        await store.destroy(ctx.sessionId)
      }

      ctx.session = generateSession()
      ctx.sessionId = genSid.call(ctx, 24)
      sessionIdStore.reset.call(ctx)

      debug('created new session: %s', ctx.sessionId)
      result.isNew = true
    }

    // make sure `refreshSession` always called
    let firstError = null
    try {
      await next()
    } catch (err) {
      debug('next logic error: %s', err.message)
      firstError = err
    }
    // can't use finally because `refreshSession` is async
    try {
      await refreshSession(ctx, ctx.session, result.originalHash, result.isNew)
    } catch (err) {
      debug('refresh session error: %s', err.message)
      if (firstError) ctx.app.emit('error', err, ctx)
      firstError = firstError || err
    }
    if (firstError) throw firstError
  }
1224660
async function deferSession(ctx, next) {
    ctx.sessionStore = store

    // TODO:
    // Accessing ctx.session when it's defined is causing problems
    // because it has side effect. So, here we use a flag to determine
    // that session property is already defined.
    if (ctx.__isSessionDefined) {
      return next()
    }
    let isNew = false
    let originalHash = null
    let touchSession = false
    let getter = false

    // if path not match
    if (!matchPath(ctx)) {
      return next()
    }

    addCommonAPI(ctx)

    Object.defineProperty(ctx, 'session', {
      async get() {
        if (touchSession) {
          return this._session
        }
        touchSession = true
        getter = true

        const result = await getSession(this)
        // if cookie path not match
        // this route's controller should never use session
        if (!result) return

        originalHash = result.originalHash
        isNew = result.isNew
        this._session = result.session
        return this._session
      },
      set(value) {
        touchSession = true
        this._session = value
      }
    })

    // internal flag to determine that session is already defined
    ctx.__isSessionDefined = true

    ctx.regenerateSession = async function regenerateSession() {
      debug('regenerating session')
      // make sure that the session has been loaded
      await ctx.session

      if (!isNew) {
        // destroy the old session
        debug('destroying previous session')
        await store.destroy(ctx.sessionId)
      }

      ctx._session = generateSession()
      ctx.sessionId = genSid.call(ctx, 24)
      sessionIdStore.reset.call(ctx)
      debug('created new session: %s', ctx.sessionId)
      isNew = true
      return ctx._session
    }

    await next()

    if (touchSession) {
      // if only this.session=, need try to decode and get the sessionID
      if (!getter) {
        ctx.sessionId = sessionIdStore.get.call(ctx)
      }

      await refreshSession(ctx, ctx._session, originalHash, isNew)
    }
  }
1343017
function (data) {
		if (mockIndexedDBTestFlags.canSave === true) {
			mockIndexedDBItems.push(data);
			mockIndexedDB_storeAddTimer = setTimeout(function () {
				mockIndexedDBTransaction.callCompleteHandler();
				mockIndexedDB_saveSuccess = true;
			}, 20);
		}
		else {
			mockIndexedDB_storeAddTimer = setTimeout(function () {
				mockIndexedDBTransaction.callErrorHandler();
				mockIndexedDB_saveFail = true;
			}, 20);
		}

		return mockIndexedDBTransaction;
	}
182400
function(callback){
			if(!this.id){
				return process.nextTick(function(){
					callback(new Error("Invalid session ID"));
				});
			}
			options.client.setex(options.keyspace + this.id, options.maxAge, JSON.stringify(serializeSession(this)), callback);
		}
884068
function initSession(storedSession, callback) {
  if (typeof storedSession === "function") {
    callback = storedSession;
  }

  core.setSession((storedSession && makeSession(storedSession)) || {});

  getStatus({ force: true }, function(err, status) {
    if (status.authenticated) {
      core.events.emit('auth.login', status);
    }

    if (typeof callback === "function") {
      callback(err, status);
    }
  });
}
750086
@Override
    public void registerStore(IStore store) {
        _store = store;
        _store.setStoreCallback(_storeCallback);
        if (store instanceof ISessionObserver) {
            this.registerSessionObserver((ISessionObserver) store);
        }
        if (store instanceof ISessionStateObserver) {
            this.registerSessionStateObserver((ISessionStateObserver) store);
        }
    }
1191008
public void registerDestructionCallback(String name, Runnable callback) {
		synchronized (getSessionMutex()) {
			if (isSessionCompleted()) {
				throw new IllegalStateException(
						"Session id=" + getWebSocketSessionId() + " already completed");
			}
			setAttribute(DESTRUCTION_CALLBACK_NAME_PREFIX + name, callback);
		}
	}
605973
function(callback) {
        if (res.parsedHeader.payload.mode === 'handshake') {
          res.session = {
            sid: reqSid,
            cert: senderCert,
            token: reqToken
          };
          callback(null);
        } else {
          var querySid;
          if (sessionStore instanceof Store || 'undefined' !== typeof window) {
            querySid = my.config.urlBase;
          } else {
            querySid = reqSid;
          }
          // load the session if exists
          sessionStore.load(querySid, function(err, session){
            if (err) {
              callback(err);
            } else if (session) {
              log.debug('%s loaded session', app.name);
              log.debug(session);
              res.session = session;
              callback(null);
            } else {
              callback('session expired');
            }
          });
        }
      }
1268738
function authCallback(obj, window, parent) {

			var cb = obj.callback;
			var network = obj.network;

			// Trigger the callback on the parent
			_this.store(network, obj);

			// If this is a page request it has no parent or opener window to handle callbacks
			if (('display' in obj) && obj.display === 'page') {
				return;
			}

			// Remove from session object
			if (parent && cb && cb in parent) {

				try {
					delete obj.callback;
				}
				catch (e) {}

				// Update store
				_this.store(network, obj);

				// Call the globalEvent function on the parent
				// It's safer to pass back a string to the parent,
				// Rather than an object/array (better for IE8)
				var str = JSON.stringify(obj);

				try {
					callback(parent, cb)(str);
				}
				catch (e) {
					// Error thrown whilst executing parent callback
				}
			}

			closeWindow();
		}
46661
function bindEvent ( namespacedEvent, callback ) {
            scope_Events[namespacedEvent] = scope_Events[namespacedEvent] || [];
            scope_Events[namespacedEvent].push(callback);

            // If the event bound is 'update,' fire it immediately for all handles.
            if ( namespacedEvent.split('.')[0] === 'update' ) {
                scope_Handles.forEach(function(a, index){
                    fireEvent('update', index);
                });
            }
        }
348331
function(sessionId, socketId, cb) {
      return api.store.get().load(sessionId, function(err, session) {
        // Create a new session if we don't have this sessionId in memory
        // Note: in production you should be using Redis or another
        // persistent store so this should rarely happen
        if (!session) {
          session = strategy.create(sessionId);
          debug('created session for %s',sessionId);
        } else {
          debug('using existing session for %s',sessionId);
        }

        // Append methods to session object
        session.channel = channels(ss, session, socketId);
        session.setUserId = function(userId, cb) {
          if (!cb) {
            cb = function() {};
          }
          if (userId) {
            this.userId = userId;
            this._bindToSocket();
          } else if (this.userId) {  // if null (i.e. user has signed out)
            subscriptions.user.remove(this.userId, socketId);
            delete this.userId;
          }
          return this.save(cb);
        };

        // Bind username and any channel subscriptions to this socketID on each request
        session._bindToSocket = function() {
          if (session.userId) {
            subscriptions.user.add(session.userId, socketId);
          }
          if ((session.channels) && session.channels.length > 0) {
            session.channel._bindToSocket();
          }
          return this;
        };
        session.save = function(cb) {
          return sessionStore.set(sessionId, session, cb);
        };
        session._bindToSocket();
        return cb(session);
      });
    }
225301
private void dispatchGrantedResource(
      Map<String, List<ResourceGrant>> sessionIdToGranted) {
    for (Map.Entry<String, List<ResourceGrant>> entry :
        sessionIdToGranted.entrySet()) {
      LOG.info("Assigning " + entry.getValue().size() + " " +
          type + " requests to Session: " + entry.getKey());
      try {
        Session session = sessionManager.getSession(entry.getKey());
        session.setResourceGrant(entry.getValue());
      } catch (InvalidSessionHandle e) {
        LOG.warn("Trying to add call for invalid session: " + entry.getKey());
      }
      if (LOG.isDebugEnabled()) {
        LOG.debug(Arrays.toString(entry.getValue().toArray()));
      }
      sessionNotifier.notifyGrantResource(entry.getKey(), entry.getValue());
    }
  }
235222
public void fireHttpSessionUpdated(final HttpSession session) {
		if (View.isInitialised() && !EventQueue.isDispatchThread()) {
			EventQueue.invokeLater(new Runnable() {

				@Override
				public void run() {
					fireHttpSessionUpdated(session);
				}
			});

			return;
		}

		int index = sessions.indexOf(session);
		fireTableRowsUpdated(index, index);
	}
1337841
function (evtOrId, callback) {
    if (typeof evtOrId === 'object') {
      evtOrId = evtOrId.id;
    }
    this.store.setEventToDispatched(evtOrId, callback);
  }
845509
public void onPageEvent(long officialTime) {
		//cleanup expired sessions
		ArrayList garbage = new ArrayList(sessionsMirror.size());
		Iterator i;
		StandardSession session;
		synchronized (sessionsMirror) {
			i = sessionsMirror.values().iterator();
			while (i.hasNext()) {
				session = (StandardSession) i.next();
				if (session.isExpired()) {
					garbage.add(session);
				}
			}
		}
		i = garbage.iterator();
		while (i.hasNext()) {
			session = (StandardSession) i.next();
			System.out.println(new LogEntry("session " + session.getToken() + " expired..."));
			this.destroySessionByToken(session.getToken());
		}
	}
275074
public void setSessionManager(SessionManager sm)
    {
        if (isStarted())
            throw new IllegalStateException("Started");

        SessionManager old= getSessionManager();

        if (getHttpContext() != null)
        {
            // recover config and remove listeners from old session manager
            if (old != null && old != sm)
            {
                if (_sessionListeners != null)
                {
                    for (Iterator i= LazyList.iterator(_sessionListeners); i.hasNext();)
                    {
                        EventListener listener= (EventListener)i.next();
                        _sessionManager.removeEventListener(listener);
                    }
                }
            }

            // Set listeners and config on new listener.
            if (sm != null && old != sm)
            {
                if (_sessionListeners != null)
                {
                    for (Iterator i= LazyList.iterator(_sessionListeners); i.hasNext();)
                    {
                        EventListener listener= (EventListener)i.next();
                        sm.addEventListener(listener);
                    }
                }
            }
        }

        super.setSessionManager(sm);
    }