diff --git a/components/siddhi-tryit/org.wso2.carbon.siddhi.tryit.ui/src/main/java/org/wso2/carbon/siddhi/tryit/ui/SiddhiTryItClient.java b/components/siddhi-tryit/org.wso2.carbon.siddhi.tryit.ui/src/main/java/org/wso2/carbon/siddhi/tryit/ui/SiddhiTryItClient.java index 593d88695..89ee9556b 100644 --- a/components/siddhi-tryit/org.wso2.carbon.siddhi.tryit.ui/src/main/java/org/wso2/carbon/siddhi/tryit/ui/SiddhiTryItClient.java +++ b/components/siddhi-tryit/org.wso2.carbon.siddhi.tryit.ui/src/main/java/org/wso2/carbon/siddhi/tryit/ui/SiddhiTryItClient.java @@ -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; @@ -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; /** @@ -111,9 +114,8 @@ public Map processData(String executionPlan, String event * @param executionPlanRuntime execution plan runtime object * @throws Exception */ - private Map processEventStream(String eventStream, Map map, Map inputHandlerMap, long startSetTime, long startSystemTime, ExecutionPlanRuntime executionPlanRuntime) throws Exception { - Pattern eventPattern = Pattern.compile("(\\S+)=\\[(.*)\\]"); - Pattern delayPattern = Pattern.compile("(delay\\()(\\d+)+"); + private Map processEventStream(String eventStream, Map map, Map inputHandlerMap, long startSetTime, long startSystemTime, ExecutionPlanRuntime executionPlanRuntime) throws Exception { String[] inputStreamEventArray = eventStream.split("\\r?\\n"); executionPlanRuntime.start(); @@ -171,7 +173,7 @@ private Map processEventStream(String eventStream, Map processEventStream(String eventStream, Map map, Map inputHandlerMap, ExecutionPlanRuntime executionPlanRuntime) { + private void processStreamCallback(Map map, Map inputHandlerMap, + ExecutionPlanRuntime executionPlanRuntime) { for (AbstractDefinition abstractDefinition : executionPlanRuntime.getStreamDefinitionMap().values()) { String streamId = abstractDefinition.getId(); @@ -214,8 +217,7 @@ public void receive(Event[] events) { * @param executionPlanRuntime execution plan runtime object */ private void processQueryCallback(Map 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 @@ -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; @@ -269,12 +271,8 @@ public static void loadDataSourceConfiguration(SiddhiManager siddhiManager) thro } List 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) { diff --git a/components/siddhi-tryit/org.wso2.carbon.siddhi.tryit.ui/src/main/java/org/wso2/carbon/siddhi/tryit/ui/UIConstants.java b/components/siddhi-tryit/org.wso2.carbon.siddhi.tryit.ui/src/main/java/org/wso2/carbon/siddhi/tryit/ui/UIConstants.java index 53f06be4c..a5daaebcd 100644 --- a/components/siddhi-tryit/org.wso2.carbon.siddhi.tryit.ui/src/main/java/org/wso2/carbon/siddhi/tryit/ui/UIConstants.java +++ b/components/siddhi-tryit/org.wso2.carbon.siddhi.tryit.ui/src/main/java/org/wso2/carbon/siddhi/tryit/ui/UIConstants.java @@ -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 + @@ -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]"; }