use of org.wso2.siddhi.query.api.expression.condition.In in project siddhi by wso2.
the class SiddhiDebuggerClient method start.
/**
* Start the {@link SiddhiDebuggerClient} and configure the breakpoints.
*
* @param siddhiApp the Siddhi query
* @param input the user input as a whole text
*/
public void start(final String siddhiApp, String input) {
SiddhiManager siddhiManager = new SiddhiManager();
info("Deploying the siddhi app");
final SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);
// Add callbacks for all the streams
final Set<String> streamNames = SiddhiCompiler.parse(siddhiApp).getStreamDefinitionMap().keySet();
for (String streamName : streamNames) {
final String stream = streamName;
siddhiAppRuntime.addCallback(stream, new StreamCallback() {
@Override
public void receive(Event[] events) {
info("@Receive: Stream: " + stream + ", Event: " + Arrays.deepToString(events));
}
});
}
SiddhiDebugger siddhiDebugger = siddhiAppRuntime.debug();
final InputFeeder inputFeeder = new InputFeeder(siddhiAppRuntime, input);
System.out.println("Configure the breakpoints.\nYou can use the following commands:\n - " + ADD_BREAKPOINT + "<query name>:<IN/OUT>\n - " + REMOVE_BREAKPOINT + "<query name>:<IN/OUT>\n - " + START + "\n - " + STOP);
printNextLine();
final Scanner scanner = new Scanner(System.in, "UTF-8");
while (scanner.hasNextLine()) {
String userInput = scanner.nextLine().trim();
String command = userInput.toLowerCase();
if (command.startsWith(ADD_BREAKPOINT)) {
if (!command.contains(QUERY_DELIMITER)) {
error("Invalid add query. The query must be " + ADD_BREAKPOINT + "<query " + "name>:<IN/OUT>. Please try again");
printNextLine();
continue;
}
String[] components = userInput.substring(ADD_BREAKPOINT.length(), userInput.length()).split(QUERY_DELIMITER);
String queryName = components[0];
String terminal = components[1].toLowerCase();
if (IN.equals(terminal)) {
siddhiDebugger.acquireBreakPoint(queryName, SiddhiDebugger.QueryTerminal.IN);
info("Added a breakpoint at the IN terminal of " + queryName);
printNextLine();
} else if (OUT.equals(terminal)) {
siddhiDebugger.acquireBreakPoint(queryName, SiddhiDebugger.QueryTerminal.OUT);
info("Added a breakpoint at the OUT terminal of " + queryName);
printNextLine();
} else {
error("The terminal must be either IN or OUT but found: " + terminal.toUpperCase() + ". Please try again");
printNextLine();
}
} else if (command.startsWith(REMOVE_BREAKPOINT)) {
if (!command.contains(QUERY_DELIMITER)) {
error("Invalid add query. The query must be " + REMOVE_BREAKPOINT + "<query " + "name>:<IN/OUT>. Please try again");
printNextLine();
continue;
}
String[] components = command.substring(ADD_BREAKPOINT.length(), command.length()).split(QUERY_DELIMITER);
String queryName = components[0];
String terminal = components[1];
if (IN.equals(terminal)) {
siddhiDebugger.releaseBreakPoint(queryName, SiddhiDebugger.QueryTerminal.IN);
info("Removed the breakpoint at the IN terminal of " + queryName);
printNextLine();
} else if (OUT.equals(terminal)) {
siddhiDebugger.releaseBreakPoint(queryName, SiddhiDebugger.QueryTerminal.OUT);
info("Removed the breakpoint at the OUT terminal of " + queryName);
printNextLine();
} else {
error("The terminal must be either IN or OUT but found: " + terminal.toUpperCase());
printNextLine();
}
} else if (STOP.equals(command)) {
inputFeeder.stop();
siddhiAppRuntime.shutdown();
break;
} else if (START.equals(command)) {
inputFeeder.start();
info("Siddhi Debugger starts sending input to Siddhi");
System.out.println("You can use the following commands:\n - " + NEXT + "\n - " + PLAY + "\n - " + STATE + ":<query name>\n - " + STOP);
break;
} else {
error("Invalid command: " + command);
printNextLine();
}
}
siddhiDebugger.setDebuggerCallback(new SiddhiDebuggerCallback() {
@Override
public void debugEvent(ComplexEvent event, String queryName, SiddhiDebugger.QueryTerminal queryTerminal, SiddhiDebugger debugger) {
info("@Debug: Query: " + queryName + ", Terminal: " + queryTerminal + ", Event: " + event);
printNextLine();
while (scanner.hasNextLine()) {
String command = scanner.nextLine().trim().toLowerCase();
if (STOP.equals(command)) {
debugger.releaseAllBreakPoints();
debugger.play();
inputFeeder.stop();
siddhiAppRuntime.shutdown();
break;
} else if (NEXT.equals(command)) {
debugger.next();
break;
} else if (PLAY.equals(command)) {
debugger.play();
break;
} else if (command.startsWith(STATE)) {
if (!command.contains(QUERY_DELIMITER)) {
error("Invalid get state request. The query must be " + STATE + ":<query " + "name>. Please try again");
printNextLine();
continue;
}
String[] components = command.split(QUERY_DELIMITER);
String requestQueryName = components[1];
Map<String, Object> state = debugger.getQueryState(requestQueryName.trim());
System.out.println("Query '" + requestQueryName + "' state : ");
for (Map.Entry<String, Object> entry : state.entrySet()) {
System.out.println(" '" + entry.getKey() + "' : " + entry.getValue());
}
printNextLine();
continue;
} else {
error("Invalid command: " + command);
printNextLine();
}
}
}
});
inputFeeder.join();
if (inputFeeder.isRunning()) {
info("Input feeder has sopped sending all inputs. If you want to stop the execution, use " + "the STOP command");
printNextLine();
while (scanner.hasNextLine()) {
String command = scanner.nextLine().trim().toLowerCase();
if (STOP.equals(command)) {
inputFeeder.stop();
siddhiAppRuntime.shutdown();
break;
} else {
error("Invalid command: " + command);
printNextLine();
}
}
}
scanner.close();
info("Siddhi Debugger is stopped successfully");
}
use of org.wso2.siddhi.query.api.expression.condition.In in project siddhi by wso2.
the class FunctionExecutor method cloneExecutor.
@Override
public ExpressionExecutor cloneExecutor(String key) {
try {
FunctionExecutor functionExecutor = this.getClass().newInstance();
ExpressionExecutor[] innerExpressionExecutors = new ExpressionExecutor[attributeSize];
for (int i = 0; i < attributeSize; i++) {
innerExpressionExecutors[i] = attributeExpressionExecutors[i].cloneExecutor(key);
}
functionExecutor.elementId = elementId + "-" + key;
functionExecutor.functionId = functionId;
functionExecutor.initExecutor(innerExpressionExecutors, siddhiAppContext, queryName, configReader);
return functionExecutor;
} catch (Exception e) {
throw new SiddhiAppRuntimeException("Exception in cloning " + this.getClass().getCanonicalName(), e);
}
}
use of org.wso2.siddhi.query.api.expression.condition.In in project siddhi by wso2.
the class AbstractStreamProcessor method cloneProcessor.
@Override
public Processor cloneProcessor(String key) {
try {
AbstractStreamProcessor abstractStreamProcessor = this.getClass().newInstance();
abstractStreamProcessor.inputDefinition = inputDefinition;
ExpressionExecutor[] innerExpressionExecutors = new ExpressionExecutor[attributeExpressionLength];
ExpressionExecutor[] attributeExpressionExecutors1 = this.attributeExpressionExecutors;
for (int i = 0; i < attributeExpressionLength; i++) {
innerExpressionExecutors[i] = attributeExpressionExecutors1[i].cloneExecutor(key);
}
abstractStreamProcessor.attributeExpressionExecutors = innerExpressionExecutors;
abstractStreamProcessor.attributeExpressionLength = attributeExpressionLength;
abstractStreamProcessor.additionalAttributes = additionalAttributes;
abstractStreamProcessor.complexEventPopulater = complexEventPopulater;
abstractStreamProcessor.siddhiAppContext = siddhiAppContext;
abstractStreamProcessor.elementId = elementId + "-" + key;
abstractStreamProcessor.configReader = configReader;
abstractStreamProcessor.outputExpectsExpiredEvents = outputExpectsExpiredEvents;
abstractStreamProcessor.queryName = queryName;
abstractStreamProcessor.siddhiAppContext.getSnapshotService().addSnapshotable(queryName, abstractStreamProcessor);
abstractStreamProcessor.siddhiAppContext.addEternalReferencedHolder(abstractStreamProcessor);
abstractStreamProcessor.init(inputDefinition, attributeExpressionExecutors, configReader, siddhiAppContext, outputExpectsExpiredEvents);
abstractStreamProcessor.start();
return abstractStreamProcessor;
} catch (Exception e) {
throw new SiddhiAppRuntimeException("Exception in cloning " + this.getClass().getCanonicalName(), e);
}
}
use of org.wso2.siddhi.query.api.expression.condition.In in project siddhi by wso2.
the class LogStreamProcessor method init.
/**
* The init method of the StreamFunction
*
* @param inputDefinition the incoming stream definition
* @param attributeExpressionExecutors the executors for the function parameters
* @param siddhiAppContext siddhi app context
* @param configReader this hold the {@link LogStreamProcessor} configuration reader.
* @return the additional output attributes introduced by the function
*/
@Override
protected List<Attribute> init(AbstractDefinition inputDefinition, ExpressionExecutor[] attributeExpressionExecutors, ConfigReader configReader, SiddhiAppContext siddhiAppContext) {
int inputExecutorLength = attributeExpressionExecutors.length;
if (inputExecutorLength == 1) {
if (attributeExpressionExecutors[0].getReturnType() == Attribute.Type.STRING) {
logMessageExpressionExecutor = attributeExpressionExecutors[0];
} else if (attributeExpressionExecutors[0].getReturnType() == Attribute.Type.BOOL) {
isLogEventExpressionExecutor = attributeExpressionExecutors[0];
} else {
throw new SiddhiAppValidationException("Input attribute is expected to be 'isEventLogged (Bool)' " + "or 'logMessage (String)' or 'isEventLogged (Bool), logMessage (String)' or 'priority " + "(String), isEventLogged (Bool), logMessage (String)', but its 1st attribute is " + attributeExpressionExecutors[0].getReturnType());
}
} else if (inputExecutorLength == 2) {
if (attributeExpressionExecutors[0].getReturnType() == Attribute.Type.STRING && attributeExpressionExecutors[1].getReturnType() == Attribute.Type.BOOL) {
logMessageExpressionExecutor = attributeExpressionExecutors[0];
isLogEventExpressionExecutor = attributeExpressionExecutors[1];
} else if (attributeExpressionExecutors[0].getReturnType() == Attribute.Type.STRING && attributeExpressionExecutors[1].getReturnType() == Attribute.Type.STRING) {
if (attributeExpressionExecutors[0] instanceof ConstantExpressionExecutor) {
logPriority = LogPriority.valueOf(((String) attributeExpressionExecutors[0].execute(null)).toUpperCase());
} else {
logPriorityExpressionExecutor = attributeExpressionExecutors[0];
}
logMessageExpressionExecutor = attributeExpressionExecutors[1];
} else {
throw new SiddhiAppValidationException("Input attribute is expected to be 'logMessage (String), " + "isEventLogged (Bool)' or 'priority (String), logMessage (String)', but its returning are '" + attributeExpressionExecutors[0].getReturnType() + ", " + attributeExpressionExecutors[1].getReturnType() + "'");
}
} else if (inputExecutorLength == 3) {
if (attributeExpressionExecutors[0].getReturnType() == Attribute.Type.STRING) {
if (attributeExpressionExecutors[0] instanceof ConstantExpressionExecutor) {
logPriority = LogPriority.valueOf(((String) attributeExpressionExecutors[0].execute(null)).toUpperCase());
} else {
logPriorityExpressionExecutor = attributeExpressionExecutors[0];
}
} else {
throw new SiddhiAppValidationException("Input attribute is expected to be 'priority (String), " + "logMessage (String), isEventLogged (Bool)', but its 1st attribute is returning " + attributeExpressionExecutors[0].getReturnType());
}
if (attributeExpressionExecutors[1].getReturnType() == Attribute.Type.STRING) {
logMessageExpressionExecutor = attributeExpressionExecutors[1];
} else {
throw new SiddhiAppValidationException("Input attribute is expected to be 'priority (String), " + "logMessage (String), isEventLogged (Bool)', but its 2nd attribute is returning " + attributeExpressionExecutors[1].getReturnType());
}
if (attributeExpressionExecutors[2].getReturnType() == Attribute.Type.BOOL) {
isLogEventExpressionExecutor = attributeExpressionExecutors[2];
} else {
throw new SiddhiAppValidationException("Input attribute is expected to be 'priority (String), " + "logMessage (String), isEventLogged (Bool)', but its 3rd attribute is returning " + attributeExpressionExecutors[2].getReturnType());
}
} else if (inputExecutorLength > 3) {
throw new SiddhiAppValidationException("Input parameters for Log can be logMessage (String), " + "isEventLogged (Bool), but there are " + attributeExpressionExecutors.length + " in the input!");
}
logPrefix = siddhiAppContext.getName() + ": ";
return new ArrayList<Attribute>();
}
use of org.wso2.siddhi.query.api.expression.condition.In in project siddhi by wso2.
the class AggregateWindowProcessor method cloneProcessor.
@Override
public Processor cloneProcessor(String key) {
try {
AggregateWindowProcessor streamProcessor = new AggregateWindowProcessor(aggregationRuntime, within, per);
streamProcessor.inputDefinition = inputDefinition;
ExpressionExecutor[] innerExpressionExecutors = new ExpressionExecutor[attributeExpressionLength];
ExpressionExecutor[] attributeExpressionExecutors1 = this.attributeExpressionExecutors;
for (int i = 0; i < attributeExpressionLength; i++) {
innerExpressionExecutors[i] = attributeExpressionExecutors1[i].cloneExecutor(key);
}
streamProcessor.attributeExpressionExecutors = innerExpressionExecutors;
streamProcessor.attributeExpressionLength = attributeExpressionLength;
streamProcessor.additionalAttributes = additionalAttributes;
streamProcessor.complexEventPopulater = complexEventPopulater;
streamProcessor.init(inputDefinition, attributeExpressionExecutors, configReader, siddhiAppContext, outputExpectsExpiredEvents);
streamProcessor.start();
return streamProcessor;
} catch (Exception e) {
throw new SiddhiAppRuntimeException("Exception in cloning " + this.getClass().getCanonicalName(), e);
}
}
Aggregations