Пример #1
0
  @Override
  protected void doStart() throws Exception {

    if (isEndpointTransacted()) {
      throw new IllegalArgumentException(
          "InOut exchange pattern is incompatible with transacted=true as it cuases a deadlock. Please use transacted=false or InOnly exchange pattern.");
    }

    if (getConnectionResource() == null) {
      throw new IllegalArgumentException(
          String.format("ConnectionResource or ConnectionFactory must be configured for %s", this));
    }

    if (ObjectHelper.isEmpty(getNamedReplyTo())) {
      log.debug("No reply to destination is defined.  Using temporary destinations.");
    } else {
      log.debug("Using {} as the reply to destination.", getNamedReplyTo());
    }
    if (uuidGenerator == null) {
      // use the generator configured on the camel context
      uuidGenerator = getEndpoint().getCamelContext().getUuidGenerator();
    }
    if (consumers == null) {
      consumers =
          new GenericObjectPool<MessageConsumerResources>(new MessageConsumerResourcesFactory());
      consumers.setMaxActive(getConsumerCount());
      consumers.setMaxIdle(getConsumerCount());
      while (consumers.getNumIdle() < consumers.getMaxIdle()) {
        consumers.addObject();
      }
    }
    super.doStart();
  }
Пример #2
0
 public XsltTransformer() {
   super();
   transformerPool = new GenericObjectPool(new PooledXsltTransformerFactory());
   transformerPool.setMinIdle(MIN_IDLE_TRANSFORMERS);
   transformerPool.setMaxIdle(MAX_IDLE_TRANSFORMERS);
   transformerPool.setMaxActive(MAX_ACTIVE_TRANSFORMERS);
   contextProperties = new HashMap<String, Object>();
 }
  private static synchronized void initialize(String poolname) {
    if (!isInitialized) {
      // create worker pool
      workerPool = new GenericObjectPool(new RWorkerObjectFactory(poolname));
      workerPool.setMaxActive(4);
      workerPool.setMaxIdle(4);
      workerPool.setTestOnBorrow(true);
      workerPool.setTestOnReturn(true);

      isInitialized = true;
    }
  }
Пример #4
0
  /** Initializes DatabaseFactory. */
  public static synchronized void init() {
    if (dataSource != null) {
      return;
    }

    DatabaseConfig.load();

    try {
      DatabaseConfig.DATABASE_DRIVER.newInstance();
    } catch (Exception e) {
      log.fatal("Error obtaining DB driver", e);
      throw new Error("DB Driver doesnt exist!");
    }

    connectionPool = new GenericObjectPool();

    if (DatabaseConfig.DATABASE_CONNECTIONS_MIN > DatabaseConfig.DATABASE_CONNECTIONS_MAX) {
      log.error(
          "Please check your database configuration. Minimum amount of connections is > maximum");
      DatabaseConfig.DATABASE_CONNECTIONS_MAX = DatabaseConfig.DATABASE_CONNECTIONS_MIN;
    }

    connectionPool.setMaxIdle(DatabaseConfig.DATABASE_CONNECTIONS_MIN);
    connectionPool.setMaxActive(DatabaseConfig.DATABASE_CONNECTIONS_MAX);

    /* test if connection is still valid before returning */
    connectionPool.setTestOnBorrow(true);

    try {
      dataSource = setupDataSource();
      Connection c = getConnection();
      DatabaseMetaData dmd = c.getMetaData();
      databaseName = dmd.getDatabaseProductName();
      databaseMajorVersion = dmd.getDatabaseMajorVersion();
      databaseMinorVersion = dmd.getDatabaseMinorVersion();
      c.close();
    } catch (Exception e) {
      log.fatal("Error with connection string: " + DatabaseConfig.DATABASE_URL, e);
      throw new Error("DatabaseFactory not initialized!");
    }

    log.info("Successfully connected to database");
  }
  public static GenericObjectPool getInstance(
      String poolName, String driver, final String url, final String user, final String password) {

    String key = driver + "%" + poolName + "%" + url + "%" + user + "%" + password;

    // log.info("getInstance-key="+key);

    if (_pool.get(key) != null) return _pool.get(key);

    synchronized (lock) {
      if (_pool.get(key) == null) {
        try {
          Class.forName(driver);

          DBLayerInterface dbLayer =
              DBLayer.getLayer(
                  getDBType(url),
                  new ConnectionProvider() {
                    public Connection newConnection() throws SQLException {
                      return DriverManager.getConnection(url, user, password);
                    }
                  });

          GenericObjectPool p = new ServerObjectPool(new ServantProxyFactoryDB(poolName, dbLayer));

          _pool.put(key, p);
          p.setMaxIdle(0);
          p.setMaxActive(-1);
          p.setTestOnBorrow(true);
          p.setTestOnReturn(true);
        } catch (Exception e) {
          throw new RuntimeException(getStackTraceAsString(e));
        }
      }
      return _pool.get(key);
    }
  }
Пример #6
0
 /**
  * Sets the the current maximum number of idle transformer objects allowed in the pool
  *
  * @param maxIdleTransformers New maximum size to set
  */
 public void setMaxIdleTransformers(int maxIdleTransformers) {
   transformerPool.setMaxIdle(maxIdleTransformers);
 }
  private synchronized void registerPool(String username, String password)
      throws javax.naming.NamingException {
    Map pools = (Map) dsInstanceMap.get(instanceKey);
    PoolKey key = getPoolKey(username);
    if (!pools.containsKey(key)) {
      int maxActive = getDefaultMaxActive();
      int maxIdle = getDefaultMaxIdle();
      int maxWait = getDefaultMaxWait();

      // The source of physical db connections
      ConnectionPoolDataSource cpds = this.cpds;
      if (cpds == null) {
        Context ctx = null;
        if (jndiEnvironment == null) {
          ctx = new InitialContext();
        } else {
          ctx = new InitialContext(jndiEnvironment);
        }
        cpds = (ConnectionPoolDataSource) ctx.lookup(dataSourceName);
      }

      Object whicheverPool = null;
      if (perUserMaxActive != null && perUserMaxActive.containsKey(username)) {
        Integer userMax = getPerUserMaxActive(username);
        if (userMax != null) {
          maxActive = userMax.intValue();
        }
        userMax = getPerUserMaxIdle(username);
        if (userMax != null) {
          maxIdle = userMax.intValue();
        }
        userMax = getPerUserMaxWait(username);
        if (userMax != null) {
          maxWait = userMax.intValue();
        }

        // Create an object pool to contain our PooledConnections
        GenericObjectPool pool = new GenericObjectPool(null);
        pool.setMaxActive(maxActive);
        pool.setMaxIdle(maxIdle);
        pool.setMaxWait(maxWait);
        pool.setWhenExhaustedAction(getWhenExhausted(maxActive, maxWait));
        pool.setTestOnBorrow(getTestOnBorrow());
        pool.setTestOnReturn(getTestOnReturn());
        pool.setTimeBetweenEvictionRunsMillis(getTimeBetweenEvictionRunsMillis());
        pool.setNumTestsPerEvictionRun(getNumTestsPerEvictionRun());
        pool.setMinEvictableIdleTimeMillis(getMinEvictableIdleTimeMillis());
        pool.setTestWhileIdle(getTestWhileIdle());

        // Set up the factory we will use (passing the pool associates
        // the factory with the pool, so we do not have to do so
        // explicitly)
        new CPDSConnectionFactory(cpds, pool, validationQuery, username, password);
        whicheverPool = pool;
      } else {
        // use default pool
        // Create an object pool to contain our PooledConnections
        GenericKeyedObjectPool pool = new GenericKeyedObjectPool(null);
        pool.setMaxActive(maxActive);
        pool.setMaxIdle(maxIdle);
        pool.setMaxWait(maxWait);
        pool.setWhenExhaustedAction(getWhenExhausted(maxActive, maxWait));
        pool.setTestOnBorrow(getTestOnBorrow());
        pool.setTestOnReturn(getTestOnReturn());
        pool.setTimeBetweenEvictionRunsMillis(getTimeBetweenEvictionRunsMillis());
        pool.setNumTestsPerEvictionRun(getNumTestsPerEvictionRun());
        pool.setMinEvictableIdleTimeMillis(getMinEvictableIdleTimeMillis());
        pool.setTestWhileIdle(getTestWhileIdle());

        // Set up the factory we will use (passing the pool associates
        // the factory with the pool, so we do not have to do so
        // explicitly)
        new KeyedCPDSConnectionFactory(cpds, pool, validationQuery);
        whicheverPool = pool;
      }

      // pools is a FastHashMap set to put the pool in a thread-safe way
      pools.put(key, whicheverPool);
    }
  }