Make sure a session is open.

        If it's not and autosession is turned on, create a new session automatically.
        If it's not and autosession is off, raise an exception.
543650
def check_session(self):
        
        if self.session is None:
            if self.autosession:
                self.open_session()
            else:
                msg = "must open a session before modifying %s" % self
                raise RuntimeError(msg)
936286
public void start()
    throws Exception
    {
        if (_random==null)
        {
            log.debug("New random session seed");
            try 
            {
                _random=SecureRandom.getInstance("SHA1PRNG");
            }
            catch (NoSuchAlgorithmException e)
            {
                log.warn("Could not generate SecureRandom for session-id randomness",e);
                _random=new Random();
                _weakRandom=true;
            }
            _random.setSeed(_random.nextLong()^System.currentTimeMillis()^hashCode()^Runtime.getRuntime().freeMemory());
        }
        
        if (_sessions==null)
            _sessions=new HashMap();
        
        // Start the session scavenger if we haven't already
        if (_scavenger == null)
        {
            _scavenger = new SessionScavenger();
            _scavenger.start();
        }
    }
1348895
def _ensure_session(self, session=None):
        """"""
        if session:
            return session

        try:
            # Don't make implicit sessions causally consistent. Applications
            # should always opt-in.
            return self.__start_session(True, causal_consistency=False)
        except (ConfigurationError, InvalidOperation):
            # Sessions not supported, or multiple users authenticated.
            return None
206327
def create_session(self, username, prekeybundle, autotrust=False):
        
        logger.debug("create_session(username=%s, prekeybunder=[omitted], autotrust=%s)" % (username, autotrust))
        session_builder = SessionBuilder(self._store, self._store, self._store, self._store, username, 1)
        try:
            session_builder.processPreKeyBundle(prekeybundle)
        except UntrustedIdentityException as ex:
            if autotrust:
                self.trust_identity(ex.getName(), ex.getIdentityKey())
            else:
                raise exceptions.UntrustedIdentityException(ex.getName(), ex.getIdentityKey())
1013546
protected void checkValid() throws SISessionUnavailableException {

        if (!_parentConnection.isValid()) {

            final SISessionUnavailableException exception = new SISessionUnavailableException(
                    NLS.getString("INVALID_SESSION_CWSIV0200"));
            if (TRACE.isEventEnabled()) {
                SibTr.exception(this, TRACE, exception);
            }
            throw exception;

        }

    }
1203643
def open(self, session=None):
        
        self.__kwargs.update(stream=True)
        session = session or requests
        resp = session.request(self.__method, self.__url, **self.__kwargs)
        try:
            yield resp
        finally:
            resp.close()
1166357
public Session createSession() throws OpenViduJavaClientException, OpenViduHttpException {
		Session s = new Session();
		OpenVidu.activeSessions.put(s.getSessionId(), s);
		return s;
	}
835270
public void sessionCreated(ISession session) {
        if (com.ibm.ejs.ras.TraceComponent.isAnyTracingEnabled() && LoggingUtil.SESSION_LOGGER_CORE.isLoggable(Level.FINE)) {
            LoggingUtil.SESSION_LOGGER_CORE.logp(Level.FINE, methodClassName, "sessionCreated", "sessionObservers.size()=" + _sessionObservers.size());
        }
        if (_sessionObservers == null || _sessionObservers.size() < 1) {
            return;
        }
        ISessionObserver sessionObserver = null;
        for (int i = 0; i < _sessionObservers.size(); i++) {
            sessionObserver = (ISessionObserver) _sessionObservers.get(i);
            sessionObserver.sessionCreated(session);
        }
    }
278632
public void createSession(Session session) {
        sessionMap.put(session.id(), session);
        Event event = new Event();
        event.attribute("session", session);

        eventManager.fireEvent(EventType.SESSION_CREATED, event);
    }
1358489
public void passivate() {
        // Notify ActivationListeners
    	SipSessionEvent event = null;
    	if(this.sipSessionAttributeMap != null) {
	        Set<String> keySet = getAttributeMap().keySet();
	        for (String key : keySet) {
	        	Object attribute = getAttributeMap().get(key);
	            if (attribute instanceof SipSessionActivationListener) {
	                if (event == null)
	                	event = new SipSessionActivationEvent(this, SessionActivationNotificationCause.PASSIVATION);
	                try {
	                    ((SipSessionActivationListener)attribute)
	                        .sessionWillPassivate(event);
	                } catch (Throwable t) {
	                    logger.error("SipSessionActivationListener threw exception", t);
	                }
	            }
			}
    	}
    }
994176
public void sessionCreated(HttpSessionEvent httpSessionEvent) {
		if (active) {
			if (log.isDebugEnabled()) 
				log.debug("sessionCreated sessionId = "
						+ httpSessionEvent.getSession().getId());
		}
	}
252286
def _session(self):
        """"""
        # Taken from the session docs.
        session = self._session_maker()
        try:
            yield session
            session.commit()
        except:
            session.rollback()
            raise
        finally:
            session.close()
946642
def set_exception(self, exception):
        
        assert isinstance(exception, Exception), \
            "%r should be an Exception" % exception
        self._exception = exception
        self._state = self.FINISHED
1202583
def create_session!
      # Skip authorizing if there was an error from the authorization.
      handle_token_error
      # Try to get a code (the rescue block will also prevent crazy crashes)
      access = @strategy.authenticate(@request.GET['code'])
      @request.session[:redd_session] = access.to_h
    rescue Errors::TokenRetrievalError, Errors::ResponseError => error
      @request.env['redd.error'] = error
    end
200284
def create_session(self):
        

        url = self.build_url(self._endpoints.get('create_session'))
        response = self.con.post(url, data={'persistChanges': self.persist})
        if not response:
            raise RuntimeError('Could not create session as requested by the user.')
        data = response.json()
        self.session_id = data.get('id')

        return True
364636
protected synchronized void doStart()
        throws Exception
    {
        if (isStarted())
            return;
        
        _contextLog = LogFactory.getLog("org.browsermob.proxy.jetty.jetty.context."+getHttpContext().getHttpContextName());
        
        if (_contextLog==null)
            _contextLog=log;
        
        if (_sessionManager!=null)
            _sessionManager.start();
        
        // Initialize classloader
        _loader=getHttpContext().getClassLoader();

        if (_autoInitializeServlets)
            initializeServlets();
    }
754192
function usersStarted(err, session) {
          if (err)
            self.badCount++;
          else
            self.goodCount++;

          if (self.badCount == 2 && self.goodCount == 2) {
            // Resume session1 correctly
            new Session().resumeSession(store, ip1, session1.get('passCode'), sessionResumed_Test1);
          }
        }