Skip to content

Commit

Permalink
Updated Temperature pojo and adjusted Esper statements accordingly
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianmilne committed Feb 27, 2013
1 parent 8b9b9a6 commit ce571b9
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 15 deletions.
42 changes: 35 additions & 7 deletions src/main/java/com/cor/cep/event/TemperatureEvent.java
@@ -1,24 +1,52 @@
package com.cor.cep.event;

import java.util.Date;

/**
* Immutable Temperature Event class. The process control system creates these events. The
* TemperatureEventHandler picks these up and processes them.
*/
public class TemperatureEvent {

private int value;

public TemperatureEvent(int value) {
this.value = value;
/** Temperature in Celcius. */
private int temperature;

/** Time temerature reading was taken. */
private Date timeOfReading;

/**
* Single value constructor.
* @param value Temperature in Celsius.
*/
/**
* Temeratur constructor.
* @param temperature Temperature in Celsius
* @param timeOfReading Time of Reading
*/
public TemperatureEvent(int temperature, Date timeOfReading) {
this.temperature = temperature;
this.timeOfReading = timeOfReading;
}

public int getValue() {
return value;
/**
* Get the Temperature.
* @return Temperature in Celsius
*/
public int getTemperature() {
return temperature;
}

/**
* Get time Temperature reading was taken.
* @return Time of Reading
*/
public Date getTimeOfReading() {
return timeOfReading;
}

@Override
public String toString() {
return "TemperatureEvent [" + value + "C]";
return "TemperatureEvent [" + temperature + "C]";
}

}
Expand Up @@ -37,10 +37,10 @@ public String getStatement() {
+ " measures A as temp1, B as temp2, C as temp3, D as temp4 "
+ " pattern (A B C D) "
+ " define "
+ " A as A.value > " + CRITICAL_EVENT_THRESHOLD + ", "
+ " B as (A.value < B.value), "
+ " C as (B.value < C.value), "
+ " D as (C.value < D.value) and D.value > (A.value * " + CRITICAL_EVENT_MULTIPLIER + ")" + ")";
+ " A as A.temperature > " + CRITICAL_EVENT_THRESHOLD + ", "
+ " B as (A.temperature < B.temperature), "
+ " C as (B.temperature < C.temperature), "
+ " D as (C.temperature < D.temperature) and D.temperature > (A.temperature * " + CRITICAL_EVENT_MULTIPLIER + ")" + ")";

return crtiticalEventExpression;
}
Expand Down
Expand Up @@ -21,7 +21,7 @@ public class MonitorEventSubscriber implements StatementSubscriber {
public String getStatement() {

// Example of simple EPL with a Time Window
return "select avg(value) as avg_val from TemperatureEvent.win:time_batch(5 sec)";
return "select avg(temperature) as avg_val from TemperatureEvent.win:time_batch(5 sec)";
}

/**
Expand Down
Expand Up @@ -32,8 +32,8 @@ public String getStatement() {
+ " measures A as temp1, B as temp2 "
+ " pattern (A B) "
+ " define "
+ " A as A.value > " + WARNING_EVENT_THRESHOLD + ", "
+ " B as B.value > " + WARNING_EVENT_THRESHOLD + ")";
+ " A as A.temperature > " + WARNING_EVENT_THRESHOLD + ", "
+ " B as B.temperature > " + WARNING_EVENT_THRESHOLD + ")";

return warningEventExpression;
}
Expand Down
@@ -1,5 +1,6 @@
package com.cor.cep.util;

import java.util.Date;
import java.util.Random;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
Expand Down Expand Up @@ -41,7 +42,7 @@ public void run() {

int count = 0;
while (count < noOfTemperatureEvents) {
TemperatureEvent ve = new TemperatureEvent(new Random().nextInt(500));
TemperatureEvent ve = new TemperatureEvent(new Random().nextInt(500), new Date());
temperatureEventHandler.handle(ve);
count++;
try {
Expand Down

0 comments on commit ce571b9

Please sign in to comment.