コード例 #1
0
ファイル: SSDBWriper.java プロジェクト: kdpujie/framework
 /**
  * 初始化SSDB
  *
  * @return
  */
 public SSDB init() {
   Config config = new Config();
   config.maxActive = this.maxActive;
   config.maxIdle = this.maxIdle;
   config.maxWait = this.maxWait;
   return SSDBs.pool(this.ipAddress, this.port, this.timeout, config);
 }
コード例 #2
0
  private void init() {
    // ExtServerConfig.init("/Users/tanxiuguang/work/youku/search/src/WEB-INF/conf/ext.conf");
    String[] servers = ExtServerConfig.getInstance().getStringArray("REDISSERVERS");
    if (servers == null || servers.length <= 0) {
      logger.error("Error REDISERCERS");
    } else {
      shards = new ArrayList<JedisShardInfo>();
      for (String server : servers) {
        shards.add(new JedisShardInfo(server, DEFAULT_PORT));
      }

      Config config = new Config();
      // config.maxActive = 1;
      // config.whenExhaustedAction = GenericObjectPool.WHEN_EXHAUSTED_FAIL;
      config.maxActive = 200;
      config.maxIdle = 40;
      pool = new ShardedJedisPool(config, shards);
    }
  }
コード例 #3
0
  private ObjectPool createConnectionPool(
      String host, String port, String schema, String user, String password) {
    PoolableObjectFactory mySqlPoolableObjectFactory =
        new MySqlPoolableObjectFactory(host, Integer.parseInt(port), schema, user, password);
    Config config = new GenericObjectPool.Config();
    config.maxActive = 10;
    config.maxWait = 20000;
    config.maxIdle = 5;
    config.minIdle = 0;
    config.testOnBorrow = false;
    config.testWhileIdle = true;
    config.timeBetweenEvictionRunsMillis = 10000;
    config.minEvictableIdleTimeMillis = 60000;

    GenericObjectPoolFactory genericObjectPoolFactory =
        new GenericObjectPoolFactory(mySqlPoolableObjectFactory, config);
    ObjectPool pool = genericObjectPoolFactory.createPool();
    return pool;
  }
コード例 #4
0
  /**
   * Creates a new SessionPool object for the given config.
   *
   * @param config holds connection options such as server, user and password, as well as tuning
   *     options as maximum number of connections allowed
   * @throws IOException If connection could not be established
   * @throws NullPointerException If config is null
   */
  protected SessionPool(ArcSDEConnectionConfig config) throws IOException {
    if (config == null) {
      throw new NullPointerException("parameter config can't be null");
    }

    this.config = config;
    LOGGER.fine("populating ArcSDE connection pool");

    this.seConnectionFactory = createConnectionFactory();

    final int minConnections = config.getMinConnections().intValue();
    final int maxConnections = config.getMaxConnections().intValue();
    if (minConnections > maxConnections) {
      throw new IllegalArgumentException("pool.minConnections > pool.maxConnections");
    }
    { // configure connection pool
      Config poolCfg = new Config();
      // pool upper limit
      poolCfg.maxActive = config.getMaxConnections().intValue();

      // minimum number of idle objects. MAKE SURE this is 0, otherwise the pool will start
      // trying to create connections permanently even if there's a connection failure,
      // ultimately leading to the exhaustion of resources
      poolCfg.minIdle = 0;

      // how many connections may be idle at any time? -1 = no limit. We're running an
      // eviction thread to take care of idle connections (see minEvictableIdleTimeMillis and
      // timeBetweenEvictionRunsMillis)
      poolCfg.maxIdle = -1;

      // When reached the pool upper limit, block and wait for an idle connection for maxWait
      // milliseconds before failing
      poolCfg.maxWait = config.getConnTimeOut().longValue();
      if (poolCfg.maxWait > 0) {
        poolCfg.whenExhaustedAction = GenericObjectPool.WHEN_EXHAUSTED_BLOCK;
      } else {
        poolCfg.whenExhaustedAction = GenericObjectPool.WHEN_EXHAUSTED_FAIL;
      }

      // check connection health at borrowObject()?
      poolCfg.testOnBorrow = true;
      // check connection health at returnObject()?
      poolCfg.testOnReturn = false;
      // check periodically the health of idle connections and discard them if can't be
      // validated?
      poolCfg.testWhileIdle = false;

      // check health of idle connections every 30 seconds
      // /poolCfg.timeBetweenEvictionRunsMillis = 30000;

      // drop connections that have been idle for at least 5 minutes
      poolCfg.minEvictableIdleTimeMillis = 5 * 60 * 1000;

      pool = new GenericObjectPool(seConnectionFactory, poolCfg);

      LOGGER.fine("Created ArcSDE connection pool for " + config);
    }

    ISession[] preload = new ISession[minConnections];

    try {
      for (int i = 0; i < minConnections; i++) {
        preload[i] = (ISession) pool.borrowObject();
        if (i == 0) {
          SeRelease seRelease = preload[i].getRelease();
          String sdeDesc = seRelease.getDesc();
          int major = seRelease.getMajor();
          int minor = seRelease.getMinor();
          int bugFix = seRelease.getBugFix();
          String desc = "ArcSDE " + major + "." + minor + "." + bugFix + " " + sdeDesc;
          LOGGER.fine("Connected to " + desc);
        }
      }

      for (int i = 0; i < minConnections; i++) {
        pool.returnObject(preload[i]);
      }
    } catch (Exception e) {
      close();
      if (e instanceof IOException) {
        throw (IOException) e;
      }
      throw (IOException) new IOException().initCause(e);
    }
  }
コード例 #5
0
  public void contextInitialized(ServletContextEvent sce) {
    ServletContext servletContext = sce.getServletContext();

    String appPath = servletContext.getRealPath("/WEB-INF/sipatra");
    String scriptPath =
        PropertyUtils.getStringProperty(Properties.SIPATRA_PATH_PROPERTY, null, servletContext);

    if (scriptPath == null) {
      scriptPath = appPath + "/application.rb";
    } else {
      File file = new File(scriptPath);
      if (!file.exists()) {
        _log.error(file.getAbsolutePath() + " does not exist!");
        scriptPath = null;
      }

      if (file.isFile()) {
        if (!file.getName().endsWith(".rb"))
          _log.warn(file.getAbsolutePath() + " is not a ruby file!");

        if (file.getParentFile() != null) appPath = file.getParentFile().getAbsolutePath();
        else _log.error(file.getAbsolutePath() + " got no parent directory!");
      } else if (file.isDirectory()) {
        appPath = new File(scriptPath).getAbsolutePath();
      }
    }

    Config conf = new Config();

    conf.maxActive =
        PropertyUtils.getIntegerProperty(
            Properties.SIPATRA_POOL_MAX_ACTIVE_PROPERTY, -1, servletContext);
    conf.maxIdle =
        PropertyUtils.getIntegerProperty(
            Properties.SIPATRA_POOL_MAX_IDLE_PROPERTY, -1, servletContext);
    conf.maxWait =
        PropertyUtils.getIntegerProperty(
            Properties.SIPATRA_POOL_MAX_WAIT_PROPERTY, -1, servletContext);
    conf.minIdle =
        PropertyUtils.getIntegerProperty(
            Properties.SIPATRA_POOL_MIN_IDLE_PROPERTY, -1, servletContext);
    conf.minEvictableIdleTimeMillis =
        PropertyUtils.getLongProperty(
            Properties.SIPATRA_POOL_MIN_EVICTABLE_PROPERTY, 1000L * 60L * 30L, servletContext);
    conf.lifo =
        PropertyUtils.getBooleanProperty(Properties.SIPATRA_POOL_LIFO, false, servletContext);
    conf.numTestsPerEvictionRun =
        PropertyUtils.getIntegerProperty(
            Properties.SIPATRA_POOL_TEST_EVICTION_RUN, 3, servletContext);
    conf.softMinEvictableIdleTimeMillis =
        PropertyUtils.getLongProperty(
            Properties.SIPATRA_POOL_SOFT_MIN_EVICTABLE, -1L, servletContext);
    conf.testOnBorrow =
        PropertyUtils.getBooleanProperty(
            Properties.SIPATRA_POOL_TEST_BORROW, false, servletContext);
    conf.testOnReturn =
        PropertyUtils.getBooleanProperty(
            Properties.SIPATRA_POOL_TEST_RETURN, false, servletContext);
    conf.testWhileIdle =
        PropertyUtils.getBooleanProperty(Properties.SIPATRA_POOL_TEST_IDLE, false, servletContext);
    conf.timeBetweenEvictionRunsMillis =
        PropertyUtils.getLongProperty(Properties.SIPATRA_POOL_TIME_EVICTION, -1L, servletContext);

    GenericObjectPool pool =
        new GenericObjectPool(new JRubyRuntimeFactory(appPath, scriptPath), conf);
    startPool(
        pool,
        PropertyUtils.getIntegerProperty(
            Properties.SIPATRA_POOL_INIT_POOL_SIZE, 1, servletContext));
    servletContext.setAttribute(Attributes.POOL, pool);
  }