示例#1
0
  public static void main(String[] args) {
    EPServiceProvider epService = EPServiceProviderManager.getDefaultProvider();
    EPAdministrator admin = epService.getEPAdministrator();

    // Apple定义
    Map<String, Object> apple = new HashMap<String, Object>();
    apple.put("id", int.class);
    apple.put("price", int.class);

    // 注册Apple到Esper
    admin.getConfiguration().addEventType("Apple", apple);

    String epl = "select avg(price) from Apple.win:length_batch(3)";

    EPStatement state = admin.createEPL(epl);
    state.addListener(new AppleListener());

    EPRuntime runtime = epService.getEPRuntime();

    Map<String, Object> apple1 = new HashMap<String, Object>();
    apple1.put("id", 1);
    apple1.put("price", 5);
    runtime.sendEvent(apple1, "Apple");

    Map<String, Object> apple2 = new HashMap<String, Object>();
    apple2.put("id", 2);
    apple2.put("price", 2);
    runtime.sendEvent(apple2, "Apple");

    Map<String, Object> apple3 = new HashMap<String, Object>();
    apple3.put("id", 3);
    apple3.put("price", 5);
    runtime.sendEvent(apple3, "Apple");
  }
示例#2
0
文件: Test.java 项目: shiwenna/esper
  public static void main(String[] args) throws InterruptedException {
    EPServiceProvider epService = EPServiceProviderManager.getDefaultProvider();

    EPAdministrator admin = epService.getEPAdministrator();

    //        String epl1 = "select (select sum(price), sum(size) from " + Apple.class.getName() +
    // ".std:lastevent()) from " + Fruit.class.getName();
    /*
     * 当然,对不同的属性使用不同的聚合函数也是可以的
     */
    // String epl1 = "select (select sum(price), avg(size) from " + Apple.class.getName() +
    // ".std:lastevent()) from " + Fruit.class.getName();

    /*
     * 注意:size没有使用聚合函数,会导致创建epl失败。文档中注明了“The properties of the subselect stream must all be within aggregation functions”.
     * 即子查询中的select子句使用聚合函数时,所查询的属性都要使用聚合函数
     */
    String epl1 =
        "select (select sum(price), size from "
            + Apple.class.getName()
            + ".std:lastevent()) from "
            + Fruit.class.getName();

    admin.createEPL(epl1);
    System.out.println("Create epl successfully!");
  }
示例#3
0
  public void testCorrel() {
    // further math tests can be found in the view unit test
    EPAdministrator admin = epService.getEPAdministrator();
    admin.getConfiguration().addEventType("Market", SupportMarketDataBean.class);
    EPStatement statement =
        admin.createEPL(
            "select * from Market.std:groupwin(symbol).win:length(1000000).stat:correl(price, volume, feed)");
    SupportUpdateListener listener = new SupportUpdateListener();
    statement.addListener(listener);

    assertEquals(Double.class, statement.getEventType().getPropertyType("correlation"));

    String[] fields = new String[] {"symbol", "correlation", "feed"};

    epService.getEPRuntime().sendEvent(new SupportMarketDataBean("ABC", 10.0, 1000L, "f1"));
    EPAssertionUtil.assertProps(
        listener.assertOneGetNewAndReset(), fields, new Object[] {"ABC", Double.NaN, "f1"});

    epService.getEPRuntime().sendEvent(new SupportMarketDataBean("DEF", 1.0, 2L, "f2"));
    EPAssertionUtil.assertProps(
        listener.assertOneGetNewAndReset(), fields, new Object[] {"DEF", Double.NaN, "f2"});

    epService.getEPRuntime().sendEvent(new SupportMarketDataBean("DEF", 2.0, 4L, "f3"));
    EPAssertionUtil.assertProps(
        listener.assertOneGetNewAndReset(), fields, new Object[] {"DEF", 1.0, "f3"});

    epService.getEPRuntime().sendEvent(new SupportMarketDataBean("ABC", 20.0, 2000L, "f4"));
    EPAssertionUtil.assertProps(
        listener.assertOneGetNewAndReset(), fields, new Object[] {"ABC", 1.0, "f4"});
  }
示例#4
0
  private void registerEventStream(EventDefinition def) {
    log.info("registering event type stream %s", def.getEventType());
    for (String ns : namespaces) {
      EPAdministrator admin = EsperProvider.getProvider(ns).getEPAdministrator();

      HashMap<String, Object> m = new HashMap<String, Object>();
      for (Map.Entry<String, Class> entry : def.getProperties().entrySet()) {
        m.put(entry.getKey(), entry.getValue());
      }

      admin.getConfiguration().addEventType(def.getEventType(), m);
      inputEventRegistrationsValid.add(def.getEventType());
    }
    notifyEventRegistered(def);
  }
  public static void main(String[] args) {
    EPServiceProvider esProvider = EPServiceProviderManager.getDefaultProvider();
    EPAdministrator admin = esProvider.getEPAdministrator();
    EPRuntime er = esProvider.getEPRuntime();

    Review r1 = new Review();
    r1.setReviewId(1);
    r1.setComment("r1");

    Book b1 = new Book();
    b1.setAuthor("b1");
    b1.setBookId(1);
    b1.setReview(r1);

    Book b2 = new Book();
    b2.setAuthor("b2");
    b2.setBookId(2);

    Item i1 = new Item();
    i1.setItemId(1);
    i1.setProductId(1);
    i1.setPrice(1.11);
    i1.setAmount(2);

    // 添加Bean对象
    MediaOrder mo1 = new MediaOrder();
    Books bs = new Books();
    Items is = new Items();
    List<Item> items = new ArrayList<Item>();
    List<Book> books = new ArrayList<Book>();
    items.add(i1);
    books.add(b1);
    books.add(b2);
    mo1.setOrderId(1);
    bs.setBook(books);
    is.setItem(items);
    mo1.setItems(is);
    mo1.setBooks(bs);

    String mediaOrder = MediaOrder.class.getName();
    String epl = "select * from " + mediaOrder + "[books.book]";
    EPStatement stat1 = admin.createEPL(epl);
    stat1.addListener(new SelectContainedListener());

    er.sendEvent(mo1);
  }
示例#6
0
  void Activate(String className, int roomId, String roomName, String roomInstance) {

    EPAdministrator admin = service.getEPAdministrator();
    System.out.println("-- Activating " + className);
    Iterator<Rule> safeIter = rules.iterator();

    while (safeIter.hasNext()) {
      Rule r = safeIter.next();
      if (r.className.equals(className)) {
        if (r.statement == null) {
          log.info("+ " + r.description + " = " + r.epl);
          r.statement = admin.createEPL(r.epl);
          r.statement.addListener(new GenericListener(service, this, r));
        }
        r.statement.start();
      }
    }

    // G�n�re un event pour initialiser la rule
    MyEvent ev = new MyEvent(0, roomId, roomName, roomInstance, "start", className, null);
    System.out.println(">>" + ev.toString());
    this.service.getEPRuntime().sendEvent(ev);
    // feed.addRoom(roomId);
  }
  public MsgCountOverThresholdWindowStatement(EPAdministrator admin) {

    // Query with use of Batch window
    String stmt =
        "select msg, count(*) as cnt from IncommingEvent.win:time_batch(20 sec) "
            + "group by msg having count(*) >= 5";

    // Query with use of Sliding window
    // String stmt =
    // "select msg, count(*) as cnt from IncommingEvent.win:time(1 sec) "
    // + "group by msg "
    // + "having count(*) >= 60000";

    statement = admin.createEPL(stmt);
  }
示例#8
0
  public GoalStatement(EPAdministrator epAdministrator, UpdateListener listener) {

    String query2 =
        "insert into GoalEvent "
            + "select playerName,ts, x,y,abs_v from BallTouchEvent where isTowardGoal = 1";

    //		//timer:interval(10 sec)
    //		 String query1 = "insert into GoalEvent "
    //		 + "select * from ContactEvent b where b.isTowardGoal = 1";
    //
    //		 String query2 = "select sid, player_ts, player_x, player_y from GoalEvent";

    // this.epsStatement1 = epAdministrator.createEPL(query1);
    this.epsStatement2 = epAdministrator.createEPL(query2);
    this.epsStatement2.addListener(listener);
  }
  public PlayerBallContactStatement(EPAdministrator epAdministrator, UpdateListener listener) {
    String query =
        "on BallTouchEvent as ball "
            + "insert into PlayerBallContactEvent select  "
            + "win.x as player_x, win.y as player_y, win.z as player_z, "
            + "win.playerName as playerName, win.PosInField as PosInField, "
            + "win.vx as player_vx, win.vy as player_vy, win.vz as player_vz, "
            + "win.ts as player_ts,  "
            + "ball.ballId as ball_id, ball.ts as ball_ts, "
            + "eplab.anfragen.Game.GetEuclideanDistance(win.x , win.y , win.z , ball.x , ball.y , ball.z) as distance "
            + "from PlayerWindow as win where "
            + "eplab.anfragen.Game.GetEuclideanDistance(win.x , win.y , win.z , ball.x , ball.y , ball.z) < 10000 "
            + "order by distance, player_ts limit 1";

    this.epStatement = epAdministrator.createEPL(query);
    this.epStatement.addListener(listener);
  }
示例#10
0
  public void testLinest() {
    // further math tests can be found in the view unit test
    EPAdministrator admin = epService.getEPAdministrator();
    admin.getConfiguration().addEventType("Market", SupportMarketDataBean.class);
    EPStatement statement =
        admin.createEPL(
            "select * from Market.std:groupwin(symbol).win:length(1000000).stat:linest(price, volume, feed)");
    SupportUpdateListener listener = new SupportUpdateListener();
    statement.addListener(listener);

    assertEquals(Double.class, statement.getEventType().getPropertyType("slope"));
    assertEquals(Double.class, statement.getEventType().getPropertyType("YIntercept"));
    assertEquals(Double.class, statement.getEventType().getPropertyType("XAverage"));
    assertEquals(Double.class, statement.getEventType().getPropertyType("XStandardDeviationPop"));
    assertEquals(
        Double.class, statement.getEventType().getPropertyType("XStandardDeviationSample"));
    assertEquals(Double.class, statement.getEventType().getPropertyType("XSum"));
    assertEquals(Double.class, statement.getEventType().getPropertyType("XVariance"));
    assertEquals(Double.class, statement.getEventType().getPropertyType("YAverage"));
    assertEquals(Double.class, statement.getEventType().getPropertyType("YStandardDeviationPop"));
    assertEquals(
        Double.class, statement.getEventType().getPropertyType("YStandardDeviationSample"));
    assertEquals(Double.class, statement.getEventType().getPropertyType("YSum"));
    assertEquals(Double.class, statement.getEventType().getPropertyType("YVariance"));
    assertEquals(Long.class, statement.getEventType().getPropertyType("dataPoints"));
    assertEquals(Long.class, statement.getEventType().getPropertyType("n"));
    assertEquals(Double.class, statement.getEventType().getPropertyType("sumX"));
    assertEquals(Double.class, statement.getEventType().getPropertyType("sumXSq"));
    assertEquals(Double.class, statement.getEventType().getPropertyType("sumXY"));
    assertEquals(Double.class, statement.getEventType().getPropertyType("sumY"));
    assertEquals(Double.class, statement.getEventType().getPropertyType("sumYSq"));

    String[] fields = new String[] {"symbol", "slope", "YIntercept", "feed"};

    epService.getEPRuntime().sendEvent(new SupportMarketDataBean("ABC", 10.0, 50000L, "f1"));
    EPAssertionUtil.assertProps(
        listener.assertOneGetNewAndReset(),
        fields,
        new Object[] {"ABC", Double.NaN, Double.NaN, "f1"});

    epService.getEPRuntime().sendEvent(new SupportMarketDataBean("DEF", 1.0, 1L, "f2"));
    EventBean theEvent = listener.assertOneGetNewAndReset();
    EPAssertionUtil.assertProps(
        theEvent, fields, new Object[] {"DEF", Double.NaN, Double.NaN, "f2"});
    assertEquals(1d, theEvent.get("XAverage"));
    assertEquals(0d, theEvent.get("XStandardDeviationPop"));
    assertEquals(Double.NaN, theEvent.get("XStandardDeviationSample"));
    assertEquals(1d, theEvent.get("XSum"));
    assertEquals(Double.NaN, theEvent.get("XVariance"));
    assertEquals(1d, theEvent.get("YAverage"));
    assertEquals(0d, theEvent.get("YStandardDeviationPop"));
    assertEquals(Double.NaN, theEvent.get("YStandardDeviationSample"));
    assertEquals(1d, theEvent.get("YSum"));
    assertEquals(Double.NaN, theEvent.get("YVariance"));
    assertEquals(1L, theEvent.get("dataPoints"));
    assertEquals(1L, theEvent.get("n"));
    assertEquals(1d, theEvent.get("sumX"));
    assertEquals(1d, theEvent.get("sumXSq"));
    assertEquals(1d, theEvent.get("sumXY"));
    assertEquals(1d, theEvent.get("sumY"));
    assertEquals(1d, theEvent.get("sumYSq"));
    // above computed values tested in more detail in RegressionBean test

    epService.getEPRuntime().sendEvent(new SupportMarketDataBean("DEF", 2.0, 2L, "f3"));
    EPAssertionUtil.assertProps(
        listener.assertOneGetNewAndReset(), fields, new Object[] {"DEF", 1.0, 0.0, "f3"});

    epService.getEPRuntime().sendEvent(new SupportMarketDataBean("ABC", 11.0, 50100L, "f4"));
    EPAssertionUtil.assertProps(
        listener.assertOneGetNewAndReset(), fields, new Object[] {"ABC", 100.0, 49000.0, "f4"});
  }
示例#11
0
  public void testStats() {
    EPAdministrator epAdmin = epService.getEPAdministrator();
    String filter = "select * from " + SupportMarketDataBean.class.getName();

    EPStatement priceLast3Stats =
        epAdmin.createEPL(filter + ".std:groupwin(symbol).win:length(3).stat:uni(price)");
    priceLast3Stats.addListener(priceLast3StatsListener);

    EPStatement volumeLast3Stats =
        epAdmin.createEPL(filter + ".std:groupwin(symbol).win:length(3).stat:uni(volume)");
    volumeLast3Stats.addListener(volumeLast3StatsListener);

    EPStatement priceAllStats = epAdmin.createEPL(filter + ".std:groupwin(symbol).stat:uni(price)");
    priceAllStats.addListener(priceAllStatsListener);

    EPStatement volumeAllStats =
        epAdmin.createEPL(filter + ".std:groupwin(symbol).stat:uni(volume)");
    volumeAllStats.addListener(volumeAllStatsListener);

    Vector<Map<String, Object>> expectedList = new Vector<Map<String, Object>>();
    for (int i = 0; i < 3; i++) {
      expectedList.add(new HashMap<String, Object>());
    }

    sendEvent(SYMBOL_CISCO, 25, 50000);
    sendEvent(SYMBOL_CISCO, 26, 60000);
    sendEvent(SYMBOL_IBM, 10, 8000);
    sendEvent(SYMBOL_IBM, 10.5, 8200);
    sendEvent(SYMBOL_GE, 88, 1000);

    EPAssertionUtil.assertPropsPerRow(
        priceLast3StatsListener.getLastNewData(), makeMap(SYMBOL_GE, 88));
    EPAssertionUtil.assertPropsPerRow(
        priceAllStatsListener.getLastNewData(), makeMap(SYMBOL_GE, 88));
    EPAssertionUtil.assertPropsPerRow(
        volumeLast3StatsListener.getLastNewData(), makeMap(SYMBOL_GE, 1000));
    EPAssertionUtil.assertPropsPerRow(
        volumeAllStatsListener.getLastNewData(), makeMap(SYMBOL_GE, 1000));

    sendEvent(SYMBOL_CISCO, 27, 70000);
    sendEvent(SYMBOL_CISCO, 28, 80000);

    EPAssertionUtil.assertPropsPerRow(
        priceAllStatsListener.getLastNewData(), makeMap(SYMBOL_CISCO, 26.5d));
    EPAssertionUtil.assertPropsPerRow(
        volumeAllStatsListener.getLastNewData(), makeMap(SYMBOL_CISCO, 65000d));
    EPAssertionUtil.assertPropsPerRow(
        priceLast3StatsListener.getLastNewData(), makeMap(SYMBOL_CISCO, 27d));
    EPAssertionUtil.assertPropsPerRow(
        volumeLast3StatsListener.getLastNewData(), makeMap(SYMBOL_CISCO, 70000d));

    sendEvent(SYMBOL_IBM, 11, 8700);
    sendEvent(SYMBOL_IBM, 12, 8900);

    EPAssertionUtil.assertPropsPerRow(
        priceAllStatsListener.getLastNewData(), makeMap(SYMBOL_IBM, 10.875d));
    EPAssertionUtil.assertPropsPerRow(
        volumeAllStatsListener.getLastNewData(), makeMap(SYMBOL_IBM, 8450d));
    EPAssertionUtil.assertPropsPerRow(
        priceLast3StatsListener.getLastNewData(), makeMap(SYMBOL_IBM, 11d + 1 / 6d));
    EPAssertionUtil.assertPropsPerRow(
        volumeLast3StatsListener.getLastNewData(), makeMap(SYMBOL_IBM, 8600d));

    sendEvent(SYMBOL_GE, 85.5, 950);
    sendEvent(SYMBOL_GE, 85.75, 900);
    sendEvent(SYMBOL_GE, 89, 1250);
    sendEvent(SYMBOL_GE, 86, 1200);
    sendEvent(SYMBOL_GE, 85, 1150);

    double averageGE = (88d + 85.5d + 85.75d + 89d + 86d + 85d) / 6d;
    EPAssertionUtil.assertPropsPerRow(
        priceAllStatsListener.getLastNewData(), makeMap(SYMBOL_GE, averageGE));
    EPAssertionUtil.assertPropsPerRow(
        volumeAllStatsListener.getLastNewData(), makeMap(SYMBOL_GE, 1075d));
    EPAssertionUtil.assertPropsPerRow(
        priceLast3StatsListener.getLastNewData(), makeMap(SYMBOL_GE, 86d + 2d / 3d));
    EPAssertionUtil.assertPropsPerRow(
        volumeLast3StatsListener.getLastNewData(), makeMap(SYMBOL_GE, 1200d));

    // Check iterator results
    expectedList.get(0).put("symbol", SYMBOL_CISCO);
    expectedList.get(0).put("average", 26.5d);
    expectedList.get(1).put("symbol", SYMBOL_IBM);
    expectedList.get(1).put("average", 10.875d);
    expectedList.get(2).put("symbol", SYMBOL_GE);
    expectedList.get(2).put("average", averageGE);
    EPAssertionUtil.assertPropsPerRow(priceAllStats.iterator(), expectedList);

    expectedList.get(0).put("symbol", SYMBOL_CISCO);
    expectedList.get(0).put("average", 27d);
    expectedList.get(1).put("symbol", SYMBOL_IBM);
    expectedList.get(1).put("average", 11d + 1 / 6d);
    expectedList.get(2).put("symbol", SYMBOL_GE);
    expectedList.get(2).put("average", 86d + 2d / 3d);
    EPAssertionUtil.assertPropsPerRow(priceLast3Stats.iterator(), expectedList);
  }
示例#12
0
  public static void main(String[] args) {
    EPServiceProvider epService = EPServiceProviderManager.getDefaultProvider();
    EPAdministrator admin = epService.getEPAdministrator();
    EPRuntime runtime = epService.getEPRuntime();

    String SelectEvents = SelectEvents.class.getName();

    String epl1 = "create window SelectWindow.win:keepall() as select * from " + SelectEvents;
    String epl2 = "insert into SelectWindow select * from " + SelectEvents;

    // 注册EPL语句
    admin.createEPL(epl1);
    admin.createEPL(epl2);

    // 事件1
    SelectEvents se1 = new SelectEvents("se1", 1);
    runtime.sendEvent(se1);
    System.out.println("Send SelectEvent 1: " + se1);

    // 事件2
    SelectEvents se2 = new SelectEvents("se2", 2);
    runtime.sendEvent(se2);
    System.out.println("Send SelectEvent 2: " + se2);

    /* 操作语句
     * 1. 查找窗体中的所有事件
     * 2. 更新size = 2事件的name = "update1"
     * 3. 删除所有size < 2的事件
     */
    String select = "select * from SelectWindow";
    String update = "update SelectWindow set name='update1' where size = 2";
    String delete = "delete from SelectWindow where size < 2";

    System.out.println("\nSelect SelectWindow!");
    // 类似于数据库的查询操作,返回结果集
    EPOnDemandQueryResult selectResult = epService.getEPRuntime().executeQuery(select);
    EventBean[] events = selectResult.getArray();
    for (EventBean eb : events) {
      System.out.println(eb.getUnderlying());
    }

    // 更新size=2的事件,将name改为'update1'
    System.out.println("\nUpdate SelectEvent(size = 2) in SelectWindow!");
    EPOnDemandQueryResult updateResult = epService.getEPRuntime().executeQuery(update);
    events = updateResult.getArray();
    for (EventBean eb : events) {
      System.out.println(eb.getUnderlying());
    }

    System.out.println("\nSelect SelectWindow!");
    selectResult = epService.getEPRuntime().executeQuery(select);
    events = selectResult.getArray();
    for (EventBean eb : events) {
      System.out.println(eb.getUnderlying());
    }

    // 删除size<2的事件
    System.out.println("\nDelete SelectEvent(size < 2) in SelectWindow!");
    EPOnDemandQueryResult deleteResult = epService.getEPRuntime().executeQuery(delete);
    events = deleteResult.getArray();
    for (EventBean eb : events) {
      System.out.println(eb.getUnderlying());
    }

    System.out.println("\nSelect SelectWindow!");
    selectResult = epService.getEPRuntime().executeQuery(select);
    events = selectResult.getArray();
    for (EventBean eb : events) {
      System.out.println(eb.getUnderlying());
    }
  }
示例#13
0
  /** @param args */
  public static void main(String[] args) {
    EPServiceProvider epService = EPServiceProviderManager.getDefaultProvider();

    EPAdministrator admin = epService.getEPAdministrator();

    Map<String, Object> mapDef = new HashMap<String, Object>();
    mapDef.put("p", Product.class);

    Map<String, Object> mapDef1 = new HashMap<String, Object>();
    mapDef1.put("count", int.class);

    admin.getConfiguration().addEventType("S", mapDef);
    admin.getConfiguration().addEventType("Scount", mapDef1);
    admin.getConfiguration().addEventType("Acount", mapDef1);

    EPRuntime runtime = epService.getEPRuntime();

    String product = Product.class.getName();
    String close = User.class.getName();

    String input = "select irstream *, prevwindow(i) from " + product + ".win:time(5 sec) as i";
    String window = "create window ABC.win:keepall() as select * from S";
    String output =
        "insert into ABC select * from pattern[every a=S -[1]> b=S(b.p.price>=(a.p.price*1.05))]";
    String acount = "on " + close + " select and delete count(*) from ABC";
    String result = "every b=Acount -> every a=Scount(b.count+1=a.count)";

    EPStatement state1 = admin.createEPL(input);
    state1.addListener(new InputListener(runtime));
    admin.createEPL(window);
    admin.createEPL(output);
    EPStatement state2 = admin.createEPL(acount);
    state2.addListener(new AcountListener(runtime));
    EPStatement state3 = admin.createPattern(result);
    state3.addListener(new Result3Listener());

    Product esb = new Product();
    esb.setPrice(1);
    esb.setType("esb");
    runtime.sendEvent(esb);

    Product eos = new Product();
    eos.setPrice(2);
    eos.setType("eos");
    runtime.sendEvent(eos);

    Product esb1 = new Product();
    esb1.setPrice(3);
    esb1.setType("esb");
    runtime.sendEvent(esb1);

    Product eos1 = new Product();
    eos1.setPrice(5);
    eos1.setType("eos");
    runtime.sendEvent(eos1);

    Product esb2 = new Product();
    esb2.setPrice(6);
    esb2.setType("esb");
    runtime.sendEvent(esb2);

    Product eos3 = new Product();
    eos3.setPrice(7);
    eos3.setType("eos");
    runtime.sendEvent(eos3);

    System.out.println();
  }
示例#14
0
  public static void main(String[] args) {

    EPServiceProvider epService = EPServiceProviderManager.getDefaultProvider();
    EPAdministrator admin = epService.getEPAdministrator();
    EPRuntime runtime = epService.getEPRuntime();

    String triggerEvent = OnUpdateTrigger.class.getName();
    String updateEvent = OnUpdateEvent.class.getName();

    // 创建窗口
    String epl1 = "create window OnUpdateWindow.win:keepall() as select * from " + updateEvent;
    String epl2 = "insert into OnUpdateWindow select * from " + updateEvent;

    /* 触发条件 trigger>0
     * 获取更新前数值,initial是关键字,所以不能省略
     */
    String epl3 =
        "on "
            + triggerEvent
            + "(trigger>0) as out update OnUpdateWindow as ouw set size=out.trigger, price=initial.size where out.trigger<ouw.price";
    String epl4 = "on " + triggerEvent + "(trigger=0) select ouw.* from OnUpdateWindow as ouw";

    System.out.println("Create Window: " + epl1);
    System.out.println("Update Trigger sentence: " + epl3);
    System.out.println();

    admin.createEPL(epl1);
    admin.createEPL(epl2);
    EPStatement state3 = admin.createEPL(epl3);
    state3.addListener(new OnUpdateWindowListener());

    EPStatement state4 = admin.createEPL(epl4);
    state4.addListener(new OnUpdateSelectWindowListener());

    /* 事件1
     * size=1,price=2
     */
    OnUpdateEvent oue1 = new OnUpdateEvent("oue1", 1, 2);
    runtime.sendEvent(oue1);
    System.out.println("Send OnUpdateEvent 1: " + oue1);

    /* 事件2
     * size=2,price=3
     */
    OnUpdateEvent oue2 = new OnUpdateEvent("oue2", 2, 3);
    runtime.sendEvent(oue2);
    System.out.println("Send OnUpdateEvent 2: " + oue2);

    /* 事件3
     * size=3,price=4
     */
    OnUpdateEvent oue3 = new OnUpdateEvent("oue3", 3, 4);
    runtime.sendEvent(oue3);
    System.out.println("Send OnUpdateEvent 3: " + oue3);

    /*
     * 触发1
     * trigger = 0
     * 对应epl4
     * 查看所有事件
     */
    OnUpdateTrigger ost1 = new OnUpdateTrigger(0);
    System.out.println("\nSend OnUpdateTrigger " + ost1);
    runtime.sendEvent(ost1);

    /*
     * 触发2
     * trigger = 2
     * 对应epl3
     * 只输出out.trigger<ouw.price的事件2、3
     * 然后被更新
     *     事件2: size = 2, price = 2
     *     事件3: size = 2, price = 3
     */
    OnUpdateTrigger ost2 = new OnUpdateTrigger(2);
    System.out.println("\nSend OnUpdateTrigger " + ost2);
    runtime.sendEvent(ost2);

    /*
     * 触发3
     * trigger = 2
     * 对应epl4
     * 输出所有事件
     *     事件1: size = 1, price = 2(没有更新过)
     *     事件2: size = 2, price = 2
     *     事件3: size = 2, price = 3
     */
    OnUpdateTrigger ost3 = new OnUpdateTrigger(0);
    System.out.println("\nSend OnUpdateTrigger " + ost3);
    runtime.sendEvent(ost3);
  }
示例#15
0
  public static void main(String[] args) {
    EPServiceProvider esProvider = EPServiceProviderManager.getDefaultProvider();
    EPAdministrator admin = esProvider.getEPAdministrator();
    EPRuntime er = esProvider.getEPRuntime();

    String limit = LimitEvent.class.getName();
    String follow = FollowedEvent.class.getName();

    /* 在每次触发完成前最多只保留2个a事件,触发条件为b的size值大于a的age */
    String epl = "every a=" + limit + " -[2]> b=" + follow + "(size > a.age)";
    System.out.println("EPL: " + epl + "\n");

    // 注册EPL语句
    EPStatement statement = admin.createPattern(epl);
    statement.addListener(new LimitFollowedListener());

    System.out.println("First Send!\n");

    // 事件1,age = 1
    LimitEvent l1 = new LimitEvent(1);
    System.out.println("Send Event: " + l1);
    er.sendEvent(l1);

    // 事件2,age = 2
    LimitEvent l2 = new LimitEvent(2);
    System.out.println("Send Event: " + l2);
    er.sendEvent(l2);

    // 事件3,age = 0
    LimitEvent l3 = new LimitEvent(0);
    System.out.println("Send Event: " + l3);
    er.sendEvent(l3);

    // 事件4,size = 3
    /*
     * 满足触发条件,但由于[2]的限制
     * 只能有age = 1,age = 2,两个事件
     */
    FollowedEvent f1 = new FollowedEvent();
    f1.setSize(3);
    System.out.println("Send Event: " + f1);
    er.sendEvent(f1);

    FollowedEvent f2 = new FollowedEvent();
    f2.setSize(4);
    System.out.println("Send Event: " + f2);
    er.sendEvent(f2);

    System.out.println();
    System.out.println("Second Send!\n");
    /*
    System.out.println("Send Event: " + l1);
    er.sendEvent(l1);
    System.out.println("Send Event: " + l2);
    er.sendEvent(l2);
    */
    /*
     * 由于当第一次触发时,[2]已经满足
     * 所以当第二次触发时,不用等待直接触发
     */
    System.out.println("Send Event: " + l3);
    er.sendEvent(l3);
    System.out.println("Send Event: " + f1);
    er.sendEvent(f1);
  }