0

I have a simple query like this:

define stream myEventStream (userId string, price int);  
define stream outputStream (avgPrice double, userId string);  

@info(name = 'aQuery')  
from myEventStream#window.time(5000)  
select avg(price) as avgPrice, userId group by userId  
insert into outputStream;

When I add the query callback I don't get any response from it.

    runtime.addCallback("aQuery", new QueryCallback() {
        @Override
        public void receive(long timeStamp, Event[] inEvents,  Event[] removeEvents) {
            EventPrinter.print(timeStamp, inEvents, removeEvents);
        }
    });

I'm producing messages in another thread:

    final AtomicInteger counter = new AtomicInteger(0);
    final Random rnd = new Random(System.currentTimeMillis());
    ExecutorService executor = Executors.newSingleThreadExecutor();
    executor.submit(() -> {
       while (counter.getAndIncrement() < 100) {
           try {
               handler.send(new Object[]{"user1", rnd.nextInt(100)});
               handler.send(new Object[]{"user2", rnd.nextInt(100)});
               handler.send(new Object[]{"user3", rnd.nextInt(100)});
               System.out.println("Sent: " + counter.get());
               Thread.sleep(1000);
           } catch (InterruptedException e) {
               Thread.currentThread().interrupt();
               throw new RuntimeException(e);
           }
       }
    });

I'm expecting result each 5 seconds. What am I missing here? Please help. Thank you.

yshadow
  • 77
  • 4

1 Answers1

0

Well the problem was that I've shut down the runtime right after the code which produces the event stream. Nevertheless I was able to send messages to runtime although it was shut down already. No exception.

yshadow
  • 77
  • 4