title: Drools: Having trouble with drools event processing
body: <p>I am quite new to drools. </p>
  
  <p>I am working on an application where my drools engine will get a series of event every second. I need to see if all the events in last 10 seconds has attribute value below 10, if the condition is true, I have to do some processing. Here is the example code which I tried, Please help me understand and resolve the issue.</p>
  
  <p>My Rule file.....</p>
  
  <pre><code>import java.text.DateFormat;
  import java.text.SimpleDateFormat;
  import java.util.Date;
  
  
  declare Employee 
  @role (event)
  @expires(10s)
  end
  
  // Using timer to ensure rule processing starts only after 10 secs, 
  //else processing starts as soon as first event comes in
  rule "Test Timer"
  no-loop true
  10timer(int: 5s)
  when
  $E : Employee()
  $total : Number( doubleValue &lt; 1 ) 
      from accumulate( Employee( Age &gt; 10 ), count() )
  then 
     System.out.println(  $E.getName() + " is crossing the threshold of 20");
  retract($E);
  end
  </code></pre>
  
  <p>And Main class</p>
  
  <pre><code>// import classes removed from here...
  public class MainClass {
  
  /**
   * @param args
   */
  public static void main(String[] args){
  
      //Create KnowledgeBase...
      KnowledgeBase knowledgeBase = createKnowledgeBase();
  
      //Create a stateful session
      StatefulKnowledgeSession session = knowledgeBase.newStatefulKnowledgeSession();
  //  KnowledgeRuntimeLogger logger = KnowledgeRuntimeLoggerFactory.newConsoleLogger(session);
      try {
  
          // Using random generator to simulate the data.
          int randomInt=0;
          Random randomGenerator = new Random();
          DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
          Date date = null; 
  
          while (true) {
              Thread.sleep(1000);
              date = new Date();
              randomInt = randomGenerator.nextInt(12);
  
              //Create Facts and insert them      
              Employee emp = new Employee();
              emp.setName("Anurag" + randomInt);
              emp.setAge(randomInt);
  
              //LOAD THE FACT AND FIREEEEEEEEEEEEEEEEEEE............
              System.out.println(dateFormat.format(date)+ " =&gt; Random no " + randomInt);
              session.insert(emp);
              session.fireAllRules();
          } 
  
      } catch (Exception e) {
          e.printStackTrace();
      }finally {
          session.dispose();
      }
  }
  
      /**
      * Create new knowledge base
      */
  private static KnowledgeBase createKnowledgeBase() {
      KnowledgeBuilder builder = KnowledgeBuilderFactory.newKnowledgeBuilder();
              //Add drl file into builder
      File drl = new File("D:\\eclipse\\worspace\\Research\\misc\\testforall.drl");
      builder.add(ResourceFactory.newFileResource(drl), ResourceType.DRL);
      if (builder.hasErrors()) {
          System.out.println(builder.getErrors().toString());
          //throw new RuntimeException(builder.getErrors().toString());
      }
  
      KnowledgeBase knowledgeBase = KnowledgeBaseFactory.newKnowledgeBase();
              //Add to Knowledge Base packages from the builder which are actually the rules from the drl file.
      knowledgeBase.addKnowledgePackages(builder.getKnowledgePackages());
      KnowledgeBaseConfiguration config = KnowledgeBaseFactory.newKnowledgeBaseConfiguration();
  
      config.setOption( EventProcessingOption.STREAM );
      return knowledgeBase;
  }
  }
  
  public class Employee {
  private String Name;
  private int Age;
  // getter - setters
  }
  </code></pre>