Exemple #1
0
  public static void main(String[] args)
      throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException {
    DOMConfigurator.configure("logger.xml");

    Configuration conf = new Configuration();
    conf.configure(new File("configuation.xml"));
    conf.getEngineDefaults().getThreading().setListenerDispatchPreserveOrder(false);

    conf.addEventTypeAutoName(Main.class.getPackage().getName());

    init(conf);

    EPServiceProvider epService = EPServiceProviderManager.getDefaultProvider(conf);
    String statement = "CREATE WINDOW trainSet.win:length(1000) as select * from InputTuple";
    epService.getEPAdministrator().createEPL(statement);

    statement = "INSERT INTO trainSet SELECT * FROM InputTuple";
    epService.getEPAdministrator().createEPL(statement);

    ////////// TASK 1. Performing Naive Bayes Classification over a data stream

    StreamClassifier classifier = new StreamClassifier(conf);
    classifier.verticalizeTuples(_fieldNames);
    EPStatement stmt = classifier.run(_fieldNames.length + 1);

    /////////// TASK 2. Periodically check quality of the classifier

    PeriodicChecker checker = new PeriodicChecker(conf, stmt);
    checker.run(
        "2 seconds", 100, 0.9); // every two seconds test last 100 tuples to satisfy threshold 0.7

    //////////

    _log.info("started");

    // emulate a continuous input
    AdapterInputSource adapterInputSource = new AdapterInputSource(new File("simulation.csv"));

    CSVInputAdapterSpec spec = new CSVInputAdapterSpec(adapterInputSource, "InputTuple");
    spec.setEventsPerSec(400);
    spec.setLooping(true);
    spec.setUsingEngineThread(true);

    (new CSVInputAdapter(epService, spec)).start();

    try {
      Thread.sleep(10000);
    } catch (InterruptedException e) {
      e.printStackTrace();
    }

    _log.info("stopped");
  }
  public void afterPropertiesSet() throws Exception {

    Assert.hasText(eventTypePackageName, "eventTypePackageName is must be specified");
    Assert.notEmpty(statement, "statement is empty");

    configuration = new Configuration();
    configuration.addEventTypeAutoName(eventTypePackageName);

    _instance = EPServiceProviderManager.getDefaultProvider(configuration);

    for (EPStatementContext stmt : statement) {
      final String epl = stmt.epl();
      log.info("EPL: {}", epl);
      EPStatement epstmt = _instance.getEPAdministrator().createEPL(epl);
      if (null != stmt.subscriber()) {
        epstmt.setSubscriber(stmt.subscriber());
      }

      if (null != stmt.listeners()) {
        for (Object listener : stmt.listeners()) {
          if (!(listener instanceof StatementAwareUpdateListener)
              && !(listener instanceof UpdateListener)) {
            throw new IllegalStateException("statement listener illegal");
          }

          if (listener instanceof StatementAwareUpdateListener) {
            epstmt.addListener((StatementAwareUpdateListener) listener);
          }

          if (listener instanceof UpdateListener) {
            epstmt.addListener((UpdateListener) listener);
          }

          /*
           * TODO: support addListenerWithReply
           */
          // epstmt.addListenerWithReplay((UpdateListener)listener);
        }
      }
    }
  }
 @Override
 public void addEventTypeAutoName(String packageName) {
   m_esperconfig.addEventTypeAutoName(packageName);
 }