Ejemplo n.º 1
0
  @Override
  public void initialize() {
    m_manager =
        new ChannelManager(m_logger, m_serverAddresses, m_queue, m_configManager, m_factory);

    Threads.forGroup("cat").start(this);
    Threads.forGroup("cat").start(m_manager);
    Threads.forGroup("cat").start(new MergeAtomicTask());
  }
Ejemplo n.º 2
0
  @Test
  public void testTaggedTransaction() throws Exception {
    Transaction t = Cat.newTransaction("TaggedRoot", "Root");
    Cat.newTaggedTransaction("TaggedChild", "Child1", "Tag1");
    Cat.newTaggedTransaction("TaggedChild", "Child2", "Tag2");

    Threads.forGroup().start(new TaggedThread(500, "Tag1"));
    Threads.forGroup().start(new TaggedThread(100, "Tag2"));

    TimeUnit.MILLISECONDS.sleep(200);

    t.setStatus(Message.SUCCESS);
    t.complete();
  }
Ejemplo n.º 3
0
  @Test
  public void testForkedTransaction() throws Exception {
    Transaction t = Cat.newTransaction("ForkedRoot", "Root");
    ForkedTransaction t1 = Cat.newForkedTransaction("ForkedChild", "Child1");
    ForkedTransaction t2 = Cat.newForkedTransaction("ForkedChild", "Child2");

    Threads.forGroup().start(new TimedThread(t1, 500)); // will run away
    Threads.forGroup().start(new TimedThread(t2, 100)); // will be back in time

    TimeUnit.MILLISECONDS.sleep(200);

    t.setStatus(Message.SUCCESS);
    t.complete();
  }
Ejemplo n.º 4
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));
  }
Ejemplo n.º 5
0
  @Override
  public void initialize() {
    try {
      Config config = m_configDao.findByName(CONFIG_NAME, ConfigEntity.READSET_FULL);
      String content = config.getContent();

      m_configId = config.getId();
      m_config = DefaultSaxParser.parse(content);
      m_modifyTime = config.getModifyDate().getTime();
      updateData();
    } catch (DalNotFoundException e) {
      try {
        String content = m_fetcher.getConfigContent(CONFIG_NAME);
        Config config = m_configDao.createLocal();

        config.setName(CONFIG_NAME);
        config.setContent(content);
        m_configDao.insert(config);
        m_configId = config.getId();
        m_config = DefaultSaxParser.parse(content);
      } catch (Exception ex) {
        Cat.logError(ex);
      }
    } catch (Exception e) {
      Cat.logError(e);
    }
    if (m_config == null) {
      m_config = new AppSpeedConfig();
    }
    Threads.forGroup("cat").start(new ConfigReloadTask());
  }
Ejemplo n.º 6
0
  @Override
  public void run() {
    long startTime = m_strategy.next(System.currentTimeMillis());

    // for current period
    try {
      startPeriod(startTime);
      m_latch.countDown();

      while (m_active) {
        try {
          long now = System.currentTimeMillis();
          long value = m_strategy.next(now);

          if (value > 0) {
            startPeriod(value);
          } else if (value < 0) {
            // last period is over,make it asynchronous
            Threads.forGroup("Cat").start(new EndTaskThread(-value));
          }
        } catch (Throwable e) {
          Cat.logError(e);
        }

        try {
          Thread.sleep(1000L);
        } catch (InterruptedException e) {
          break;
        }
      }
    } catch (Exception e) {
      Cat.logError(e);
    }
  }
Ejemplo n.º 7
0
  @Override
  protected void execute(ModuleContext ctx) throws Exception {
    ServerConfigManager serverConfigManager = ctx.lookup(ServerConfigManager.class);

    ctx.lookup(MessageConsumer.class);

    ConfigReloadTask configReloadTask = ctx.lookup(ConfigReloadTask.class);
    Threads.forGroup("cat").start(configReloadTask);

    if (serverConfigManager.isJobMachine()) {
      DefaultTaskConsumer taskConsumer = ctx.lookup(DefaultTaskConsumer.class);

      Threads.forGroup("cat").start(taskConsumer);
    }

    if (serverConfigManager.isAlertMachine()) {
      BusinessAlert metricAlert = ctx.lookup(BusinessAlert.class);
      NetworkAlert networkAlert = ctx.lookup(NetworkAlert.class);
      DatabaseAlert databaseAlert = ctx.lookup(DatabaseAlert.class);
      SystemAlert systemAlert = ctx.lookup(SystemAlert.class);
      ExceptionAlert exceptionAlert = ctx.lookup(ExceptionAlert.class);
      FrontEndExceptionAlert frontEndExceptionAlert = ctx.lookup(FrontEndExceptionAlert.class);
      HeartbeatAlert heartbeatAlert = ctx.lookup(HeartbeatAlert.class);
      ThirdPartyAlert thirdPartyAlert = ctx.lookup(ThirdPartyAlert.class);
      ThirdPartyAlertBuilder alertBuildingTask = ctx.lookup(ThirdPartyAlertBuilder.class);
      AppAlert appAlert = ctx.lookup(AppAlert.class);
      WebAlert webAlert = ctx.lookup(WebAlert.class);
      TransactionAlert transactionAlert = ctx.lookup(TransactionAlert.class);
      EventAlert eventAlert = ctx.lookup(EventAlert.class);
      StorageSQLAlert storageDatabaseAlert = ctx.lookup(StorageSQLAlert.class);
      StorageCacheAlert storageCacheAlert = ctx.lookup(StorageCacheAlert.class);

      Threads.forGroup("cat").start(networkAlert);
      Threads.forGroup("cat").start(databaseAlert);
      Threads.forGroup("cat").start(systemAlert);
      Threads.forGroup("cat").start(metricAlert);
      Threads.forGroup("cat").start(exceptionAlert);
      Threads.forGroup("cat").start(frontEndExceptionAlert);
      Threads.forGroup("cat").start(heartbeatAlert);
      Threads.forGroup("cat").start(thirdPartyAlert);
      Threads.forGroup("cat").start(alertBuildingTask);
      Threads.forGroup("cat").start(appAlert);
      Threads.forGroup("cat").start(webAlert);
      Threads.forGroup("cat").start(transactionAlert);
      Threads.forGroup("cat").start(eventAlert);
      Threads.forGroup("cat").start(storageDatabaseAlert);
      Threads.forGroup("cat").start(storageCacheAlert);
    }

    final MessageConsumer consumer = ctx.lookup(MessageConsumer.class);
    Runtime.getRuntime()
        .addShutdownHook(
            new Thread() {

              @Override
              public void run() {
                consumer.doCheckpoint();
              }
            });
  }
Ejemplo n.º 8
0
 @Override
 public void initialize() throws InitializationException {
   if (m_serverConfigManager.isJobMachine()) {
     Threads.forGroup("Cat").start(new Reload());
   }
 }
Ejemplo n.º 9
0
 @Override
 public void initialize() throws InitializationException {
   if (m_manager.isJobMachine()) {
     Threads.forGroup("Cat").start(new NetGraphBuilder());
   }
 }