private void scheduleTimerTasks(StatefulSessionContainer container) {
    String ejbName = ejbDescriptor.getEjbClassName();

    if (cacheProps.getCacheIdleTimeoutInSeconds() > 0) {
      long timeout = cacheProps.getCacheIdleTimeoutInSeconds() * 1000;
      try {
        sfsbContainer.invokePeriodically(
            timeout, timeout, new CachePassivatorTask(ejbName, sessionCache, _logger));
        if (_logger.isLoggable(TRACE_LEVEL)) {
          _logger.log(
              TRACE_LEVEL,
              "[SFSBBuilder]: Added CachePassivator for: "
                  + ejbName
                  + ". To run after "
                  + timeout
                  + " millis...");
        }

      } catch (Throwable th) {
        _logger.log(Level.WARNING, "ejb.sfsb_helper_add_idle_passivatortask_failed", th);
      }
    }

    if (cacheProps.getRemovalTimeoutInSeconds() > 0) {
      long timeout = cacheProps.getRemovalTimeoutInSeconds() * 1000;
      try {
        sfsbContainer.invokePeriodically(
            timeout, timeout, new ExpiredSessionsRemovalTask(ejbName, this.sfsbContainer, _logger));
        if (_logger.isLoggable(TRACE_LEVEL)) {
          _logger.log(
              TRACE_LEVEL,
              "[SFSBBuilder]: Added StorePassivator for: "
                  + ejbName
                  + ". To run after "
                  + "after "
                  + timeout
                  + " millis...");
        }
      } catch (Throwable th) {
        _logger.log(Level.WARNING, "ejb.sfsb_helper_add_remove_passivatortask_failed", th);
      }
    }
  }
  private void buildCache() {
    String cacheName = ejbDescriptor.getEjbClassName();
    String victimPolicy = cacheProps.getVictimSelectionPolicy();

    if (cacheProps.getMaxCacheSize() <= 0) {
      sessionCache =
          new UnBoundedSessionCache(
              cacheName,
              sfsbContainer,
              cacheProps.getCacheIdleTimeoutInSeconds(),
              cacheProps.getRemovalTimeoutInSeconds());
    } else if ("lru".equalsIgnoreCase(victimPolicy)) {
      sessionCache =
          new LruSessionCache(
              cacheName,
              sfsbContainer,
              cacheProps.getCacheIdleTimeoutInSeconds(),
              cacheProps.getRemovalTimeoutInSeconds());
    } else if ("fifo".equalsIgnoreCase(victimPolicy)) {
      sessionCache =
          new FIFOSessionCache(
              cacheName,
              sfsbContainer,
              cacheProps.getCacheIdleTimeoutInSeconds(),
              cacheProps.getRemovalTimeoutInSeconds());
    } else {
      sessionCache =
          new NRUSessionCache(
              cacheName,
              sfsbContainer,
              cacheProps.getCacheIdleTimeoutInSeconds(),
              cacheProps.getRemovalTimeoutInSeconds());
    }

    float ratio =
        (float) (1.0 * cacheProps.getNumberOfVictimsToSelect() / cacheProps.getMaxCacheSize());
    float loadFactor = (float) (1.0 - ratio);
    if (loadFactor < 0 || loadFactor > 1) {
      loadFactor = 0.75f;
    }

    if (cacheProps.getMaxCacheSize() <= 0) {
      sessionCache.init(16 * 1024, loadFactor, null);
    } else {
      sessionCache.init(cacheProps.getMaxCacheSize(), loadFactor, null);
    }

    sessionCache.addCacheListener((CacheListener) sfsbContainer);
    sessionCache.setSessionStore(this.sfsbStoreManager);

    sfsbContainer.setSessionCache(sessionCache);
    if (cacheProps.getNumberOfVictimsToSelect() > sfsbContainer.MIN_PASSIVATION_BATCH_COUNT) {
      sfsbContainer.setPassivationBatchCount(cacheProps.getNumberOfVictimsToSelect());
    }

    if (_logger.isLoggable(TRACE_LEVEL)) {
      _logger.log(
          TRACE_LEVEL,
          "Created cache [for "
              + ejbDescriptor.getName()
              + "] "
              + cacheProps
              + "; loadFactor: "
              + loadFactor
              + "; storeManager: "
              + this.sfsbStoreManager);
    }
  }