Package railo.runtime.listener

Examples of railo.runtime.listener.ApplicationContext


  /**
   * return the session count of this application context
   * @return
   */
  public int getAppContextSessionCount(PageContext pc) {
    ApplicationContext appContext = pc.getApplicationContext();
    if(pc.getSessionType()==Config.SESSION_TYPE_J2EE) return 0;

    Map<String, Scope> context = getSubMap(cfSessionContextes,appContext.getName());
    return getSessionCount(context);
  }
View Full Code Here


  }
 
 
  private boolean hasExistingCFSessionScope(PageContext pc) {
   
    ApplicationContext appContext = pc.getApplicationContext();
    // get Context
      Map<String, Scope> context = getSubMap(cfSessionContextes,appContext.getName());
     
    // get Session
      String storage = appContext.getSessionstorage();
      if(StringUtil.isEmpty(storage,true))storage="memory";
      else if("ram".equalsIgnoreCase(storage)) storage="memory";
      else if("registry".equalsIgnoreCase(storage)) storage="file";
      else storage=storage.toLowerCase();
     
     
     
      Session session=(Session) context.get(pc.getCFID());
     
      if(!(session instanceof StorageScope) || session.isExpired() || !((StorageScope)session).getStorage().equalsIgnoreCase(storage)) {
       
        if("memory".equals(storage)) return false;
        else if("file".equals(storage))
          return SessionFile.hasInstance(appContext.getName(),pc);
        else if("cookie".equals(storage))
          return SessionCookie.hasInstance(appContext.getName(),pc);
        else {
          DataSource ds = ((ConfigImpl)pc.getConfig()).getDataSource(storage,null);
          if(ds!=null && ds.isStorage()){
            if(SessionDatasource.hasInstance(storage,pc)) return true;
          }
          return  SessionCache.hasInstance(storage,appContext.getName(),pc);
        }
      }
      return true;
  }
View Full Code Here

   * @return cf session matching the context
   * @throws PageException
   */
  private synchronized Session getCFSessionScope(PageContext pc, RefBoolean isNew) throws PageException {
   
    ApplicationContext appContext = pc.getApplicationContext();
    // get Context
      Map<String, Scope> context = getSubMap(cfSessionContextes,appContext.getName());
     
    // get Session
      boolean isMemory=false;
      String storage = appContext.getSessionstorage();
      if(StringUtil.isEmpty(storage,true)){
        storage=ConfigImpl.DEFAULT_STORAGE_SESSION;
        isMemory=true;
      }
      else if("ram".equalsIgnoreCase(storage)) {
        storage="memory";
        isMemory=true;
      }
      else if("registry".equalsIgnoreCase(storage)) {
        storage="file";
      }
      else {
        storage=storage.toLowerCase();
        if("memory".equals(storage))isMemory=true;
      }
     
      final boolean doMemory=isMemory || !appContext.getSessionCluster();
      Session session=doMemory?appContext.getSessionCluster()?null:(Session) context.get(pc.getCFID()):null;
     
      if(!(session instanceof StorageScope) || session.isExpired() || !((StorageScope)session).getStorage().equalsIgnoreCase(storage)) {
        if(isMemory){
          session=SessionMemory.getInstance(pc,isNew,getLog());
        }
        else if("file".equals(storage)){
          session=SessionFile.getInstance(appContext.getName(),pc,getLog());
        }
        else if("cookie".equals(storage))
          session=SessionCookie.getInstance(appContext.getName(),pc,getLog());
        else{
          DataSource ds = ((PageContextImpl)pc).getDataSource(storage,null);
          if(ds!=null && ds.isStorage())session=SessionDatasource.getInstance(storage,pc,getLog(),null);
          else session=SessionCache.getInstance(storage,appContext.getName(),pc,getLog(),null);
         
          if(session==null){
            // datasource not enabled for storage
            if(ds!=null)
              throw new ApplicationException(
                  "datasource ["+storage+"] is not enabled to be used as session/client storage, " +
                  "you have to enable it in the railo administrator or define key \"storage=true\" for datasources defined in Application.cfc .");
           
            CacheConnection cc = Util.getCacheConnection(pc.getConfig(),storage,null);
            if(cc!=null)
              throw new ApplicationException("cache ["+storage+"] is not enabled to be used  as a session/client storage, you have to enable it in the railo administrator.");
           
            throw new ApplicationException("there is no cache or datasource with name ["+storage+"] defined.");
          }
        }
        ((StorageScope)session).setStorage(storage);
        if(doMemory)context.put(pc.getCFID(),session);
        isNew.setValue(true);
      }
      else {
        getLog().info("scope-context", "use existing session scope for "+appContext.getName()+"/"+pc.getCFID()+" from storage "+storage);
      }
      session.touchBeforeRequest(pc);
      return session;
  }
View Full Code Here

 
  public synchronized void removeSessionScope(PageContext pc) throws PageException {
   
    //CFSession
    Session sess = getCFSessionScope(pc, new RefBooleanImpl());
    ApplicationContext appContext = pc.getApplicationContext();
    Map<String, Scope> context = getSubMap(cfSessionContextes,appContext.getName());
    if(context!=null) {
      context.remove(pc.getCFID());
      if(sess instanceof StorageScope)((StorageScope)sess).unstore(pc.getConfig());
    }
   
    // JSession
    HttpSession httpSession=pc.getSession();
        if(httpSession!=null) {
          httpSession.removeAttribute(appContext.getName());
        }
  }
View Full Code Here

        }
  }
 
  public synchronized void removeClientScope(PageContext pc) throws PageException {
    Client cli = getClientScope(pc);
    ApplicationContext appContext = pc.getApplicationContext();
    Map<String, Scope> context = getSubMap(cfClientContextes,appContext.getName());
    if(context!=null) {
      context.remove(pc.getCFID());
      if(cli!=null)cli.unstore(pc.getConfig());
    }
  }
View Full Code Here

   * @return j session matching the context
   * @throws PageException
   */
  private synchronized 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);
          session= httpSession.getAttribute(appContext.getName());
        }
        else {
          Map<String, Scope> context = getSubMap(cfSessionContextes,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(cfSessionContextes,appContext.getName());
      context.put(pc.getCFID(),jSession);
    }
    jSession.touchBeforeRequest(pc);
    return jSession;   
  }
View Full Code Here

   * @param isNew
   * @return session matching the context
   * @throws PageException
   */
  public synchronized Application getApplicationScope(PageContext pc, RefBoolean isNew) {
    ApplicationContext appContext = pc.getApplicationContext();
    // getApplication Scope from Context
      ApplicationImpl application;
      Object objApp=applicationContextes.get(appContext.getName());
      if(objApp!=null) {
          application=(ApplicationImpl)objApp;
          if(application.isExpired()) {
            application.release()
            isNew.setValue(true);
          }
      }
      else {
        application=new ApplicationImpl();
        applicationContextes.put(appContext.getName(),application)
          isNew.setValue(true);
      }
      application.touchBeforeRequest(pc);
      //if(newApplication)listener.onApplicationStart(pc);
     
View Full Code Here

  public static String getNewCFToken() {
    return "0";
  }

  public synchronized void invalidateUserScope(PageContextImpl pc,boolean migrateSessionData,boolean migrateClientData) throws PageException {
    ApplicationContext appContext = pc.getApplicationContext();

    // get in memory scopes
    Map<String, Scope> clientContext = getSubMap(cfClientContextes,appContext.getName());
    UserScope clientScope = (UserScope) clientContext.get(pc.getCFID());
    Map<String, Scope> sessionContext = getSubMap(cfSessionContextes,appContext.getName());
    UserScope sessionScope = (UserScope) sessionContext.get(pc.getCFID());
   
    // remove  Scopes completly
    removeSessionScope(pc);
    removeClientScope(pc);
View Full Code Here

    }

    @Override
  public void touchBeforeRequest(PageContext pc) {
   
      ApplicationContext appContext = pc.getApplicationContext();
      timespan=appContext.getSessionTimeout().getMillis();
      this.name=appContext.getName();
      HttpSession hs = pc.getSession();
      String id="";
      try{
        if(hs!=null)this.httpSession=hs;
        if(httpSession!=null) {
View Full Code Here

TOP

Related Classes of railo.runtime.listener.ApplicationContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.