public Sample() { try { EventHeap eh = new EventHeap("localhost"); Event e = new Event("MyEventType"); e.addField("AGE", new Integer(27)); e.addField("NAME", "Tico Ballagas"); Event templates[] = new Event[1]; templates[0] = e; // register for a specific event template // this will only be matched when EventType = MyEventType and Age = 27 and Name = Tico // Ballagas eh.registerForEvents(templates, this); // send an event - commented out for template demonstration // uncomment to see both templates match // eh.putEvent(e); Event template = new Event("MyEventType"); template.addField("AGE", Integer.class, FieldValueTypes.FORMAL, FieldValueTypes.FORMAL); template.addField("NAME", String.class, FieldValueTypes.FORMAL, FieldValueTypes.FORMAL); // register for a generic event template // this template will be matched for any event that has EventType = MyEventType // and contains the Age and Name fields with correct type // the values of Age and Name can be any value // (run the c tutorial app as a test, waitForEvent should print and registerForEvents should // not) Event received = eh.waitForEvent(template); System.out.println("waitForEvent: " + received.getEventType()); } catch (Exception e) { e.printStackTrace(); } }
public Shake(String ip, String proxyID, String cmprt) { try { eventHeap = new EventHeap(ip); template = new Event[1]; template[0] = new Event("Shake"); // the Events to be fetched should be of type Shake template[0].addField( "Command", String.class, FieldValueTypes.FORMAL, FieldValueTypes .FORMAL); // the events to be fetched should have a field Command of an Integer value // type this.proxyID = proxyID; this.comPort = cmprt; initSerial(); eventHeap.registerForEvents(template, this); // register to receive events of type template } catch (Exception ex) { ex.printStackTrace(); System.exit(-1); } }