示例#1
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);
  }
示例#2
0
  public static void execute(ManagerConnection c) {
    ByteBuffer buffer = c.allocate();

    // write header
    buffer = header.write(buffer, c);

    // write fields
    for (FieldPacket field : fields) {
      buffer = field.write(buffer, c);
    }

    // write eof
    buffer = eof.write(buffer, c);

    // write rows
    byte packetId = eof.packetId;
    for (NIOProcessor p : CobarServer.getInstance().getProcessors()) {
      RowDataPacket row = getRow(p, c.getCharset());
      row.packetId = ++packetId;
      buffer = row.write(buffer, c);
    }

    // write last eof
    EOFPacket lastEof = new EOFPacket();
    lastEof.packetId = ++packetId;
    buffer = lastEof.write(buffer, c);

    // write buffer
    c.write(buffer);
  }
示例#3
0
  public void startup() throws IOException {
    SystemConfig system = CobarServer.getInstance().getConfig().getSystem();
    FrontendConnection.setServerVersion(VERSION);
    // start processors
    NIOProcessor[] processors = new NIOProcessor[system.getProcessors()];

    for (int i = 0; i < processors.length; i++) {
      processors[i] =
          new NIOProcessor(
              "Processor" + i, system.getProcessorHandler(), system.getProcessorExecutor());
      processors[i].startup();
    }

    // startup connector
    NIOConnector connector = new NIOConnector("BeeConnector");

    connector.setProcessors(processors);
    connector.start();

    // startup server
    SimpleServerConnectionFactory sf = new SimpleServerConnectionFactory();

    sf.setIdleTimeout(system.getIdleTimeout()); // one hour
    sf.setContainer(ContainerLoader.getDefaultContainer());

    NIOAcceptor server = new NIOAcceptor("BeeServer", m_port, sf);

    server.setProcessors(processors);
    server.start();

    Threads.forGroup("Bee").start(new ProcessorCheckTask(processors));

    LOGGER.info(String.format("BEE server started at %s", m_port));
  }
示例#4
0
  public static void execute(ManagerConnection c) {
    ByteBuffer buffer = c.allocate();

    // write header
    buffer = header.write(buffer, c);

    // write fields
    for (FieldPacket field : fields) {
      buffer = field.write(buffer, c);
    }

    // write eof
    buffer = eof.write(buffer, c);

    // write rows
    byte packetId = eof.packetId;
    Map<String, SchemaConfig> schemas = CobarServer.getInstance().getConfig().getSchemas();
    for (String name : new TreeSet<String>(schemas.keySet())) {
      RowDataPacket row = new RowDataPacket(FIELD_COUNT);
      row.add(StringUtil.encode(name, c.getCharset()));
      row.packetId = ++packetId;
      buffer = row.write(buffer, c);
    }

    // write lastEof
    EOFPacket lastEof = new EOFPacket();
    lastEof.packetId = ++packetId;
    buffer = lastEof.write(buffer, c);

    // write buffer
    c.write(buffer);
  }
示例#5
0
 public void shutdown() {
   CobarServer.getInstance().offline();
 }