use of org.wso2.siddhi.core.config.SiddhiAppContext in project siddhi by wso2.
the class DefinitionParserHelper method addTable.
public static void addTable(TableDefinition tableDefinition, ConcurrentMap<String, Table> tableMap, SiddhiAppContext siddhiAppContext) {
if (!tableMap.containsKey(tableDefinition.getId())) {
MetaStreamEvent tableMetaStreamEvent = new MetaStreamEvent();
tableMetaStreamEvent.addInputDefinition(tableDefinition);
for (Attribute attribute : tableDefinition.getAttributeList()) {
tableMetaStreamEvent.addOutputData(attribute);
}
StreamEventPool tableStreamEventPool = new StreamEventPool(tableMetaStreamEvent, 10);
StreamEventCloner tableStreamEventCloner = new StreamEventCloner(tableMetaStreamEvent, tableStreamEventPool);
Annotation annotation = AnnotationHelper.getAnnotation(SiddhiConstants.ANNOTATION_STORE, tableDefinition.getAnnotations());
Table table;
ConfigReader configReader = null;
RecordTableHandlerManager recordTableHandlerManager = null;
RecordTableHandler recordTableHandler = null;
if (annotation != null) {
annotation = updateAnnotationRef(annotation, SiddhiConstants.NAMESPACE_STORE, siddhiAppContext);
String tableType = annotation.getElement(SiddhiConstants.ANNOTATION_ELEMENT_TYPE);
Extension extension = new Extension() {
@Override
public String getNamespace() {
return SiddhiConstants.NAMESPACE_STORE;
}
@Override
public String getName() {
return tableType;
}
};
recordTableHandlerManager = siddhiAppContext.getSiddhiContext().getRecordTableHandlerManager();
if (recordTableHandlerManager != null) {
recordTableHandler = recordTableHandlerManager.generateRecordTableHandler();
}
table = (Table) SiddhiClassLoader.loadExtensionImplementation(extension, TableExtensionHolder.getInstance(siddhiAppContext));
configReader = siddhiAppContext.getSiddhiContext().getConfigManager().generateConfigReader(extension.getNamespace(), extension.getName());
} else {
table = new InMemoryTable();
}
table.initTable(tableDefinition, tableStreamEventPool, tableStreamEventCloner, configReader, siddhiAppContext, recordTableHandler);
if (recordTableHandler != null) {
recordTableHandlerManager.registerRecordTableHandler(recordTableHandler.getElementId(), recordTableHandler);
}
tableMap.putIfAbsent(tableDefinition.getId(), table);
}
}
use of org.wso2.siddhi.core.config.SiddhiAppContext in project siddhi by wso2.
the class DefinitionParserHelper method addWindow.
public static void addWindow(WindowDefinition windowDefinition, ConcurrentMap<String, Window> eventWindowMap, SiddhiAppContext siddhiAppContext) {
if (!eventWindowMap.containsKey(windowDefinition.getId())) {
Window table = new Window(windowDefinition, siddhiAppContext);
eventWindowMap.putIfAbsent(windowDefinition.getId(), table);
}
}
use of org.wso2.siddhi.core.config.SiddhiAppContext in project siddhi by wso2.
the class DefinitionParserHelper method addFunction.
public static void addFunction(SiddhiAppContext siddhiAppContext, final FunctionDefinition functionDefinition) {
Extension extension = new Extension() {
@Override
public String getNamespace() {
return "script";
}
@Override
public String getName() {
return functionDefinition.getLanguage().toLowerCase();
}
};
try {
Script script = (Script) SiddhiClassLoader.loadExtensionImplementation(extension, ScriptExtensionHolder.getInstance(siddhiAppContext));
ConfigReader configReader = siddhiAppContext.getSiddhiContext().getConfigManager().generateConfigReader(extension.getNamespace(), extension.getName());
script.setReturnType(functionDefinition.getReturnType());
script.init(functionDefinition.getId(), functionDefinition.getBody(), configReader);
siddhiAppContext.getScriptFunctionMap().put(functionDefinition.getId(), script);
} catch (Throwable t) {
ExceptionUtil.populateQueryContext(t, functionDefinition, siddhiAppContext);
throw t;
}
}
use of org.wso2.siddhi.core.config.SiddhiAppContext in project siddhi by wso2.
the class QueryParserHelper method createLatencyTracker.
public static LatencyTracker createLatencyTracker(SiddhiAppContext siddhiAppContext, String name, String type, String function) {
LatencyTracker latencyTracker = null;
if (siddhiAppContext.getStatisticsManager() != null) {
String metricName = siddhiAppContext.getSiddhiContext().getStatisticsConfiguration().getMetricPrefix() + SiddhiConstants.METRIC_DELIMITER + SiddhiConstants.METRIC_INFIX_SIDDHI_APPS + SiddhiConstants.METRIC_DELIMITER + siddhiAppContext.getName() + SiddhiConstants.METRIC_DELIMITER + SiddhiConstants.METRIC_INFIX_SIDDHI + SiddhiConstants.METRIC_DELIMITER + type + SiddhiConstants.METRIC_DELIMITER + name;
if (function != null) {
metricName += SiddhiConstants.METRIC_DELIMITER + function;
}
metricName += SiddhiConstants.METRIC_DELIMITER + "latency";
boolean matchExist = false;
for (String regex : siddhiAppContext.getIncludedMetrics()) {
if (metricName.matches(regex)) {
matchExist = true;
break;
}
}
if (matchExist) {
latencyTracker = siddhiAppContext.getSiddhiContext().getStatisticsConfiguration().getFactory().createLatencyTracker(metricName, siddhiAppContext.getStatisticsManager());
}
}
return latencyTracker;
}
use of org.wso2.siddhi.core.config.SiddhiAppContext in project siddhi by wso2.
the class SnapshotService method restore.
public void restore(byte[] snapshot) throws CannotRestoreSiddhiAppStateException {
Map<String, Map<String, Object>> snapshots = (Map<String, Map<String, Object>>) ByteSerializer.byteToObject(snapshot, siddhiAppContext);
List<Snapshotable> snapshotableList;
try {
threadBarrier.lock();
List<Snapshotable> partitionSnapshotables = snapshotableMap.get("partition");
try {
if (partitionSnapshotables != null) {
for (Snapshotable snapshotable : partitionSnapshotables) {
snapshotable.restoreState(snapshots.get(snapshotable.getElementId()));
}
}
} catch (Throwable t) {
throw new CannotRestoreSiddhiAppStateException("Restoring of Siddhi app " + siddhiAppContext.getName() + " not completed properly because content of Siddhi app has changed since " + "last state persistence. Clean persistence store for a fresh deployment.", t);
}
for (Map.Entry<String, List<Snapshotable>> entry : snapshotableMap.entrySet()) {
if (entry.getKey().equals("partition")) {
continue;
}
snapshotableList = entry.getValue();
try {
for (Snapshotable snapshotable : snapshotableList) {
snapshotable.restoreState(snapshots.get(snapshotable.getElementId()));
}
} catch (Throwable t) {
throw new CannotRestoreSiddhiAppStateException("Restoring of Siddhi app " + siddhiAppContext.getName() + " not completed properly because content of Siddhi app has changed since " + "last state persistence. Clean persistence store for a fresh deployment.", t);
}
}
} finally {
threadBarrier.unlock();
}
}
Aggregations