Exemple #1
0
 private synchronized void unLoadSchema(final String app) throws TddlException {
   SchemaConfig schema = schemas.remove(app);
   if (schema != null) {
     TDataSource dataSource = schema.getDataSource();
     if (dataSource != null) {
       dataSource.destroy();
     }
   }
 }
Exemple #2
0
  private synchronized void loadSchema(final String app) {
    SchemaConfig schema = schemas.get(app);
    if (schema != null) {
      return;
    }

    // MDC.put("app", app);
    TDataSource ds = new TDataSource();
    ds.putConnectionProperties(ConnectionProperties.CHOOSE_STREAMING, true);
    ds.putConnectionProperties(ConnectionProperties.PROCESS_AUTO_INCREMENT_BY_SEQUENCE, true);
    ds.putConnectionProperties(ConnectionProperties.INIT_CONCURRENT_POOL_EVERY_CONNECTION, false);
    // 共享一个链接池
    ds.setGlobalExecutorService(CobarServer.getInstance().getServerExectuor());
    // ds.putConnectionProperties(ConnectionProperties.MERGE_CONCURRENT,
    // true);
    // ds.putConnectionProperties(ConnectionProperties.CONCURRENT_THREAD_SIZE,
    // CobarServer.getInstance()
    // .getConfig()
    // .getSystem()
    // .getServerExecutor());
    ds.setSharding(false); // 允许非sharding启动
    ds.setAppName(app);
    // try {
    // ds.init();
    // } catch (TddlException e) {
    // // 启动时出错不往上抛
    // logger.error(e);
    // } finally {
    // MDC.remove("app");
    // }
    schema = new SchemaConfig(app);
    schema.setDataSource(ds);
    schemas.put(app, schema);
  }
Exemple #3
0
  @Override
  protected void doDestroy() throws TddlException {
    for (ConfigDataHandler cdh : cdhs.asMap().values()) {
      try {
        cdh.destroy();
      } catch (Exception e) {
        // ignore
      }
    }

    for (SchemaConfig schema : schemas.values()) {
      TDataSource dataSource = schema.getDataSource();
      try {
        if (dataSource != null) {
          dataSource.destroy();
        }
      } catch (Exception e) {
        // ignore
      }
    }
  }