public void run() {
   try {
     for (int i = 0; i < 1000; i++) {
       runtime.sendEvent(new MyEventA("key1", (int) (Math.random() * 1000000)));
       runtime.sendEvent(new MyEventA("key2", (int) (Math.random() * 1000000)));
       runtime.sendEvent(new MyEventB("key1", (int) (Math.random() * 1000000)));
       runtime.sendEvent(new MyEventB("key2", (int) (Math.random() * 1000000)));
     }
   } catch (Exception ex) {
     this.exception = ex;
   }
 }
  public void update(EventBean[] newData, EventBean[] oldData) {

    //    	numRuns++;
    //    	if(numRuns % 1000 == 0)
    //        	System.out.println("PHONE CALL LISTENER: " + numRuns);

    if (!dc.stats.isStarted()) {
      dc.stats.start();
      StatsHolder.start();
    }

    Vote v = null;
    PhoneCall pc = (PhoneCall) newData[0].getUnderlying();
    LOG.debug("exec VoteSP\t" + pc.toParams());

    // IF WE'RE USING VOLT SPs
    if (dc instanceof VoltDBSPConnector) {
      v = ((VoltDBSPConnector) dc).runSP1(pc);
    }
    // OTHERWISE
    else {
      boolean exists = dc.realContestant(pc.contestantNumber);
      long numVotes = dc.numTimesVoted(pc.phoneNumber);
      String state = dc.getState(pc.phoneNumber);

      if (!exists) {
        dc.stats.addStat(VoterConstants.VOTE_KEY, pc);
        dc.closeWorkflow(pc);
        return;
      }

      if (numVotes >= VoterConstants.MAX_VOTES) {
        dc.stats.addStat(VoterConstants.VOTE_KEY, pc);
        dc.closeWorkflow(pc);
        return;
      }

      v = new Vote(pc, state, System.nanoTime());
      dc.insertVote(v);
    }

    dc.stats.addStat(VoterConstants.VOTE_KEY, pc);
    if (v != null) {
      v.startTime = System.nanoTime();

      EPRuntime cepRT = epService.getEPRuntime();
      cepRT.sendEvent(v);
    } else {
      dc.closeWorkflow(pc);
    }
  }
  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);
  }
示例#4
0
 private void sendTimer(long timeInMSec) {
   CurrentTimeEvent theEvent = new CurrentTimeEvent(timeInMSec);
   EPRuntime runtime = epService.getEPRuntime();
   runtime.sendEvent(theEvent);
 }
示例#5
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());
    }
  }
示例#6
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);
  }
示例#7
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);
  }