Skip to content

Commit

Permalink
Merge pull request #181 from thiliA/master
Browse files Browse the repository at this point in the history
Fixing exception handling and interface usage for siddhi try it ui component
  • Loading branch information
lasanthafdo committed Oct 2, 2015
2 parents c85c2e3 + 528a410 commit 31577f1
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import org.wso2.siddhi.query.compiler.SiddhiCompiler;

import javax.sql.DataSource;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.regex.Matcher;
Expand All @@ -55,6 +56,8 @@ public class SiddhiTryItClient {
private static Log log = LogFactory.getLog(SiddhiTryItClient.class);
private static Gson gson = new GsonBuilder().setPrettyPrinting().disableHtmlEscaping().create();
private SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
private static Pattern eventPattern = Pattern.compile("(\\S+)=\\[(.*)\\]");
private static Pattern delayPattern = Pattern.compile("(delay\\()(\\d+)+");
private String errMsg;

/**
Expand Down Expand Up @@ -111,9 +114,8 @@ public Map<String, StringBuilder> processData(String executionPlan, String event
* @param executionPlanRuntime execution plan runtime object
* @throws Exception
*/
private Map<String, StringBuilder> processEventStream(String eventStream, Map<String, StringBuilder> map, Map<String, InputHandler> inputHandlerMap, long startSetTime, long startSystemTime, ExecutionPlanRuntime executionPlanRuntime) throws Exception {
Pattern eventPattern = Pattern.compile("(\\S+)=\\[(.*)\\]");
Pattern delayPattern = Pattern.compile("(delay\\()(\\d+)+");
private Map<String, StringBuilder> processEventStream(String eventStream, Map<String, StringBuilder> map, Map<String,
InputHandler> inputHandlerMap, long startSetTime, long startSystemTime, ExecutionPlanRuntime executionPlanRuntime) throws Exception {
String[] inputStreamEventArray = eventStream.split("\\r?\\n");
executionPlanRuntime.start();

Expand Down Expand Up @@ -171,7 +173,7 @@ private Map<String, StringBuilder> processEventStream(String eventStream, Map<St
inputStreamEventArray[i] +
"\n\"." +
" Expected format: &lt;eventStreamName&gt;=[&lt;attribute1&gt;,&lt;attribute2&gt;]";
throw new Exception(errMsg);
throw new IllegalArgumentException(errMsg);
}
}
}
Expand All @@ -186,7 +188,8 @@ private Map<String, StringBuilder> processEventStream(String eventStream, Map<St
* @param inputHandlerMap input handler object map
* @param executionPlanRuntime execution plan runtime object
*/
private void processStreamCallback(Map<String, StringBuilder> map, Map<String, InputHandler> inputHandlerMap, ExecutionPlanRuntime executionPlanRuntime) {
private void processStreamCallback(Map<String, StringBuilder> map, Map<String, InputHandler> inputHandlerMap,
ExecutionPlanRuntime executionPlanRuntime) {
for (AbstractDefinition abstractDefinition : executionPlanRuntime.getStreamDefinitionMap().values()) {
String streamId = abstractDefinition.getId();

Expand Down Expand Up @@ -214,8 +217,7 @@ public void receive(Event[] events) {
* @param executionPlanRuntime execution plan runtime object
*/
private void processQueryCallback(Map<String, StringBuilder> map, ExecutionPlan newExecutionPlan, ExecutionPlanRuntime executionPlanRuntime) {
for (int i = 0; i < newExecutionPlan.getExecutionElementList().size(); i++) {
ExecutionElement executionElement = newExecutionPlan.getExecutionElementList().get(i);
for (ExecutionElement executionElement : newExecutionPlan.getExecutionElementList()) {
if (executionElement instanceof Query) {
Query query = (Query) executionElement;
Element element = AnnotationHelper
Expand Down Expand Up @@ -243,14 +245,14 @@ public void receive(long timeStamp, Event[] inEvents,
*
* @param dateTime date and time to begin the process
*/
private long createTimeStamp(String dateTime) throws Exception {
private long createTimeStamp(String dateTime) throws ParseException {
Date date;
try {
date = dateFormatter.parse(dateTime);
} catch (Exception e) {
} catch (ParseException e) {
errMsg = "Error occurred while parsing date " + e.getMessage();
log.error(errMsg, e);
throw new Exception(errMsg, e);
throw new ParseException(errMsg, e.getErrorOffset());
}
long timeStamp = date.getTime();
return timeStamp;
Expand All @@ -269,12 +271,8 @@ public static void loadDataSourceConfiguration(SiddhiManager siddhiManager) thro
}
List<CarbonDataSource> dataSources = SiddhiTryItValueHolder.getDataSourceService().getAllDataSources();
for (CarbonDataSource cds : dataSources) {
try {
if (cds.getDSObject() instanceof DataSource) {
siddhiManager.setDataSource(cds.getDSMInfo().getName(), (DataSource) cds.getDSObject());
}
} catch (Exception e) {
log.error("Unable to add the datasource" + cds.getDSMInfo().getName(), e);
if (cds.getDSObject() instanceof DataSource) {
siddhiManager.setDataSource(cds.getDSMInfo().getName(), (DataSource) cds.getDSObject());
}
}
} catch (DataSourceException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,19 @@

package org.wso2.carbon.siddhi.tryit.ui;

public interface UIConstants {
String ANNOTATION_PLAN = "Plan";
public class UIConstants {
public static final String ANNOTATION_PLAN = "Plan";

String ANNOTATION_NAME_NAME = "name";
String ANNOTATION_TOKEN_AT = "@";
String ANNOTATION_TOKEN_COLON = ":";
String ANNOTATION_TOKEN_OPENING_BRACKET = "(";
String ANNOTATION_TOKEN_CLOSING_BRACKET = ")";
public static final String ANNOTATION_NAME_NAME = "name";
public static final String ANNOTATION_TOKEN_AT = "@";
public static final String ANNOTATION_TOKEN_COLON = ":";
public static final String ANNOTATION_TOKEN_OPENING_BRACKET = "(";
public static final String ANNOTATION_TOKEN_CLOSING_BRACKET = ")";

String SIDDHI_LINE_SEPARATER = "\n";
String SIDDHI_SINGLE_QUOTE = "'";
public static final String SIDDHI_LINE_SEPARATER = "\n";
public static final String SIDDHI_SINGLE_QUOTE = "'";

String EXECUTION_PLAN_BASIC_TEMPLATE = ANNOTATION_TOKEN_AT + ANNOTATION_PLAN +
public static final String EXECUTION_PLAN_BASIC_TEMPLATE = ANNOTATION_TOKEN_AT + ANNOTATION_PLAN +
ANNOTATION_TOKEN_COLON +
ANNOTATION_NAME_NAME +
ANNOTATION_TOKEN_OPENING_BRACKET +
Expand All @@ -39,14 +39,14 @@ public interface UIConstants {
SIDDHI_SINGLE_QUOTE +
ANNOTATION_TOKEN_CLOSING_BRACKET +
SIDDHI_LINE_SEPARATER + SIDDHI_LINE_SEPARATER;
String EXECUTION_PLAN_SAMPLE =
public static final String EXECUTION_PLAN_SAMPLE =
"define stream sensorStream (sensorId string, temperature float);\n" +
"\n" +
"@info(name = 'query1') \n" +
"from sensorStream[temperature>98.6] \n" +
"select sensorId \n" +
"insert into outputStream;";
String EVENT_STREAM_SAMPLE = "sensorStream=[tempID1,99.8]\n" +
public static final String EVENT_STREAM_SAMPLE = "sensorStream=[tempID1,99.8]\n" +
"delay(100)\n" +
"sensorStream=[tempID2,80.6]";
}

0 comments on commit 31577f1

Please sign in to comment.