add OHLC plugin
This commit is contained in:
@ -1,17 +1,24 @@
|
||||
import ats.plugin.OHLCPlugInViewFactory;
|
||||
import ats.plugin.OHLCTick;
|
||||
import ats.plugin.OHLCUpdateListener;
|
||||
import ats.plugin.OHLCValue;
|
||||
import com.espertech.esper.client.Configuration;
|
||||
import com.espertech.esper.client.EPServiceProvider;
|
||||
import com.espertech.esper.client.EPServiceProviderManager;
|
||||
import com.espertech.esper.client.EPStatement;
|
||||
import java.math.BigDecimal;
|
||||
import java.io.File;
|
||||
import com.espertech.esper.client.EventBean;
|
||||
import com.espertech.esper.client.StatementAwareUpdateListener;
|
||||
import com.espertech.esper.client.UpdateListener;
|
||||
import com.espertech.esper.client.time.CurrentTimeEvent;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import java.io.File;
|
||||
import java.lang.reflect.Array;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Arrays;
|
||||
import java.util.stream.Stream;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
import org.joda.time.DateTime;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
||||
public class EsperProcessor implements TickProcessor {
|
||||
@ -36,12 +43,6 @@ public class EsperProcessor implements TickProcessor {
|
||||
|
||||
addStatements(epl);
|
||||
|
||||
// Map<String,ConfigurationVariable> vars = config.getVariables();
|
||||
// log.debug("VAR MAP: {}", vars);
|
||||
// for (Map.Entry<String, ConfigurationVariable> entry : vars.entrySet()) {
|
||||
// log.debug("VAR: {} = {}", entry.getKey(), entry.getValue());
|
||||
// }
|
||||
|
||||
addStatement("select * from TickEvent",
|
||||
(newData, oldData) -> {
|
||||
log.debug("Tick: {}", newData[0].getUnderlying());
|
||||
@ -110,6 +111,13 @@ public class EsperProcessor implements TickProcessor {
|
||||
return str.startsWith("//") || str.startsWith("--");
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if the given string is only whitespace.
|
||||
*/
|
||||
private static boolean isEmpty(String str) {
|
||||
return str.matches("^\\s*$");
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove comment lines from the string.
|
||||
*/
|
||||
@ -119,15 +127,38 @@ public class EsperProcessor implements TickProcessor {
|
||||
.collect(Collectors.joining("\n"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a string with (possibly) multiple statements, split and
|
||||
* add individually.
|
||||
*/
|
||||
private void addStatements(String epl) {
|
||||
for (String s : splitStatements(filterComments(epl))) {
|
||||
addStatement(s);
|
||||
if (!isEmpty(s))
|
||||
addStatement(s);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a single EPL statement to the Esper engine.
|
||||
*/
|
||||
private EPStatement addStatement(String epl) {
|
||||
logger.debug("Adding statement: {}", epl);
|
||||
return engine.getEPAdministrator().createEPL(epl);
|
||||
return addStatement(epl, (UpdateListener)null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a single EPL statement to the Esper engine with a listener
|
||||
* to respond to the Statement.
|
||||
*/
|
||||
private EPStatement addStatement(String epl, UpdateListener listener) {
|
||||
// log.debug("Adding statement: {}", epl);
|
||||
|
||||
EPStatement statement = engine.getEPAdministrator().createEPL(epl);
|
||||
|
||||
if (listener != null) {
|
||||
statement.addListener(listener);
|
||||
}
|
||||
|
||||
return statement;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user