Retrieve the Spring-managed Session for the current thread, if any.
19843
public Session currentSession() throws HibernateException {
        Object value = TransactionSynchronizationManager.getResource(sessionFactory);
        if (value instanceof Session) {
            return (Session) value;
        }

        if (value instanceof SessionHolder) {
            SessionHolder sessionHolder = (SessionHolder) value;
            Session session = sessionHolder.getSession();
            if (TransactionSynchronizationManager.isSynchronizationActive() && !sessionHolder.isSynchronizedWithTransaction()) {
                TransactionSynchronizationManager.registerSynchronization(createSpringSessionSynchronization(sessionHolder));
                sessionHolder.setSynchronizedWithTransaction(true);
                // Switch to FlushMode.AUTO, as we have to assume a thread-bound Session
                // with FlushMode.MANUAL, which needs to allow flushing within the transaction.
                FlushMode flushMode = session.getHibernateFlushMode();
                if (flushMode.equals(FlushMode.MANUAL) && !TransactionSynchronizationManager.isCurrentTransactionReadOnly()) {
                    session.setHibernateFlushMode(FlushMode.AUTO);
                    sessionHolder.setPreviousFlushMode(flushMode);
                }
            }
            return session;
        }

        if (jtaSessionContext != null) {
            Session session = jtaSessionContext.currentSession();
            if (TransactionSynchronizationManager.isSynchronizationActive()) {
                TransactionSynchronizationManager.registerSynchronization(createSpringFlushSynchronization(session));
            }
            return session;
        }

        if (allowCreate) {
            // be consistent with older HibernateTemplate behavior
            return createSession(value);
        }

        throw new HibernateException("No Session found for current thread");
    }
789698
public String getCurrentSessionId() {
        String currentId = null;
        Hashtable ht = (Hashtable) currentThreadSacHashtable.get();
        if (ht != null) {
            SessionAffinityContext sac = (SessionAffinityContext) ht.get(_smc.getSessionAffinityContextKey());
            if (sac != null) {
                currentId = _sam.getInUseSessionID(null, sac);
                // Make sure this is set if nothing was passed in.
                if (currentId == null) {
                    currentId = "NONE";
                }
            }
        }
        // If null is returned, this is considered to be a user spawned thread.
        return currentId;
    }
1173927
public Session getSession() throws HibernateException {
		Session sess = (Session)SessionFactoryHolder.getSession();
		if (sess == null) {
			sess = getFactory().openSession();
			Transaction tr = sess.beginTransaction();
			SessionFactoryHolder.setSession(sess);
			SessionFactoryHolder.setTransaction(tr);
		}
		return sess;
	}
330143
public ContainerAS getCurrentSessionalUOW(boolean checkMarkedReset) throws CSIException, CSITransactionRolledbackException {
        ContainerAS result = null;
        Object currASKey = uowCtrl.getCurrentSessionalUOW(checkMarkedReset);

        //---------------------------------------------------------
        // No activity session available in after_completion callbacks.
        // Okay to return null in this case.
        //---------------------------------------------------------

        if (currASKey == null) {
            return null;
        }

        result = containerASMap.get(currASKey);
        if (result == null) {
            result = new ContainerAS(this, currASKey);
            uowCtrl.enlistWithSession(result);
            containerASMap.put(currASKey, result);
        }

        return result;
    }
206208
private Session getJSessionScope(PageContext pc, RefBoolean isNew) throws PageException {
	HttpSession httpSession = pc.getSession();
	ApplicationContext appContext = pc.getApplicationContext();
	Object session = null;// this is from type object, because it is possible that httpSession return object from
	// prior restart

	int s = (int) appContext.getSessionTimeout().getSeconds();
	if (maxSessionTimeout < s) maxSessionTimeout = s;

	if (httpSession != null) {
	    httpSession.setMaxInactiveInterval(maxSessionTimeout + 60);
	    session = httpSession.getAttribute(appContext.getName());
	}
	else {
	    Map<String, Scope> context = getSubMap(cfSessionContexts, appContext.getName());
	    session = context.get(pc.getCFID());
	}

	JSession jSession = null;
	if (session instanceof JSession) {
	    jSession = (JSession) session;
	    try {
		if (jSession.isExpired()) {
		    jSession.touch();
		}
		info(getLog(), "use existing JSession for " + appContext.getName() + "/" + pc.getCFID());

	    }
	    catch (ClassCastException cce) {
		error(getLog(), cce);
		// if there is no HTTPSession
		if (httpSession == null) return getCFSessionScope(pc, isNew);

		jSession = new JSession();
		httpSession.setAttribute(appContext.getName(), jSession);
		isNew.setValue(true);
	    }
	}
	else {
	    // if there is no HTTPSession
	    if (httpSession == null) return getCFSessionScope(pc, isNew);

	    info(getLog(), "create new JSession for " + appContext.getName() + "/" + pc.getCFID());
	    jSession = new JSession();
	    httpSession.setAttribute(appContext.getName(), jSession);
	    isNew.setValue(true);
	    Map<String, Scope> context = getSubMap(cfSessionContexts, appContext.getName());
	    context.put(pc.getCFID(), jSession);
	}
	jSession.touchBeforeRequest(pc);
	return jSession;
    }
1367007
public ThreadUsage getThreadUsage() {
        ThreadMXBean threadMxBean = ManagementFactory.getThreadMXBean();

        ThreadUsage threadUsage = new ThreadUsage();
        long[] threadIds = threadMxBean.getAllThreadIds();
        threadUsage.liveThreadCount = threadIds.length;

        for (long tId : threadIds) {
            ThreadInfo threadInfo = threadMxBean.getThreadInfo(tId);
            threadUsage.threadData.put(Long.toString(tId), new ThreadData(
                    threadInfo.getThreadName(), threadInfo.getThreadState()
                            .name(), threadMxBean.getThreadCpuTime(tId)));

        }
        return threadUsage;
    }
122810
protected Session getConsumerSession() throws JMSException {
        if (consumerSession == null) {
            synchronized (this) {
                if (consumerSession == null) {
                    consumerSession = createSession(Session.AUTO_ACKNOWLEDGE);
                }
            }
        }
        return consumerSession;
    }
632031
protected final Object getEventSessionMutex(HttpSession session) {
        synchronized (WebUtils.getSessionMutex(session)) {
            SerializableObject mutex =
                    (SerializableObject) session.getAttribute(EVENT_SESSION_MUTEX);
            if (mutex == null) {
                mutex = new SerializableObject();
                session.setAttribute(EVENT_SESSION_MUTEX, mutex);
            }

            return mutex;
        }
    }
1054619
public static SessionBean getSessionBean(){
        String id = idLocal.get();
        if(id==null)
            return null;
        SessionBean s = getSessionMap().get(id);

        //check TTL
        if(s!=null && (System.currentTimeMillis()-s.lastUsed)>TTL){
            if(LOG.isDebugEnabled())
                LOG.debug("Discarding session "+id+" with livetime="+(System.currentTimeMillis()-s.lastUsed)+"ms");
            s = null;
        }

        //new session
        if(s==null)
            s = new SessionBean();

        s.lastUsed = System.currentTimeMillis();
        updateSessionBean(s);
        s.id = id;
        return s;
    }
782838
def get(self, session):
        
        idle = self.idle_connections
        if idle:
            connection = idle.pop(0)
            connection.lock(session)
            if self.idle_start:
                with self._lock:
                    self.idle_start = None
            return connection.handle
        raise NoIdleConnectionsError(self.id)
739407
def getSession(self):
        """"""
        if self.session is not None:
            return self.session

        # Get value of cookie header that was sent
        cookie_str = self.headers.get('Cookie')
        if cookie_str:
            cookie_obj = SimpleCookie(cookie_str)
            sid_morsel = cookie_obj.get(self.SESSION_COOKIE_NAME, None)
            if sid_morsel is not None:
                sid = sid_morsel.value
            else:
                sid = None
        else:
            sid = None

        # If a session id was not set, create a new one
        if sid is None:
            sid = randomString(16, '0123456789abcdef')
            session = None
        else:
            session = self.server.sessions.get(sid)

        # If no session exists for this session ID, create one
        if session is None:
            session = self.server.sessions[sid] = {}

        session['id'] = sid
        self.session = session
        return session
590959
protected Session getProducerSession() throws JMSException {
        if (producerSession == null) {
            synchronized (this) {
                if (producerSession == null) {
                    producerSession = createSession(Session.AUTO_ACKNOWLEDGE);
                }
            }
        }
        return producerSession;
    }
670373
private CmsADESessionCache getSessionCache() {

        if (m_sessionCache == null) {
            m_sessionCache = CmsADESessionCache.getCache(getRequest(), getCmsObject());
        }
        return m_sessionCache;
    }
694040
public Session getSessionScope(PageContext pc, RefBoolean isNew) throws PageException {
	if (pc.getSessionType() == Config.SESSION_TYPE_APPLICATION) return getCFSessionScope(pc, isNew);
	return getJSessionScope(pc, isNew);
    }
564795
Session getStorageSession() throws RepositoryException
   {
      try
      {
         ManageableRepository repository = getWorkingRepository();

         String workspaceName = storageWorkspace;
         if (workspaceName == null)
         {
            workspaceName = repository.getConfiguration().getDefaultWorkspaceName();
         }

         return repository.getSystemSession(workspaceName);
      }
      catch (RepositoryConfigurationException e)
      {
         throw new RepositoryException("Can not get system session", e);
      }
   }
151196
public static Session retrieve(String session) throws StripeException {
    return retrieve(session, (Map<String, Object>) null, (RequestOptions) null);
  }
484338
private final Session getSession (final String targetName) throws NoSuchSessionException {

        final Session session = sessions.get(targetName);

        if (session != null) {
            return session;
        } else {
            throw new NoSuchSessionException("Session " + targetName + " not found!");
        }
    }