Search in sources :

Example 1 with SiddhiAppContextException

use of io.siddhi.query.api.exception.SiddhiAppContextException in project siddhi by wso2.

the class SiddhiAppRuntimeImpl method query.

private Event[] query(OnDemandQuery onDemandQuery, String onDemandQueryString) {
    try {
        if (Level.BASIC.compareTo(siddhiAppContext.getRootMetricsLevel()) <= 0 && onDemandQueryLatencyTracker != null) {
            onDemandQueryLatencyTracker.markIn();
        }
        OnDemandQueryRuntime onDemandQueryRuntime;
        synchronized (this) {
            onDemandQueryRuntime = onDemandQueryRuntimeMap.remove(onDemandQuery);
            if (onDemandQueryRuntime == null) {
                onDemandQueryRuntime = OnDemandQueryParser.parse(onDemandQuery, onDemandQueryString, siddhiAppContext, tableMap, windowMap, aggregationMap);
            } else {
                onDemandQueryRuntime.reset();
            }
            onDemandQueryRuntimeMap.put(onDemandQuery, onDemandQueryRuntime);
            if (onDemandQueryRuntimeMap.size() > 50) {
                Iterator i = onDemandQueryRuntimeMap.entrySet().iterator();
                if (i.hasNext()) {
                    i.next();
                    i.remove();
                }
            }
        }
        return onDemandQueryRuntime.execute();
    } catch (RuntimeException e) {
        if (e instanceof SiddhiAppContextException) {
            throw new OnDemandQueryCreationException(((SiddhiAppContextException) e).getMessageWithOutContext(), e, ((SiddhiAppContextException) e).getQueryContextStartIndex(), ((SiddhiAppContextException) e).getQueryContextEndIndex(), null, onDemandQueryString);
        }
        throw new OnDemandQueryCreationException(e.getMessage(), e);
    } finally {
        if (Level.BASIC.compareTo(siddhiAppContext.getRootMetricsLevel()) <= 0 && onDemandQueryLatencyTracker != null) {
            onDemandQueryLatencyTracker.markOut();
        }
    }
}
Also used : SiddhiAppRuntimeException(io.siddhi.core.exception.SiddhiAppRuntimeException) OnDemandQueryRuntime(io.siddhi.core.query.OnDemandQueryRuntime) Iterator(java.util.Iterator) SiddhiAppContextException(io.siddhi.query.api.exception.SiddhiAppContextException) OnDemandQueryCreationException(io.siddhi.core.exception.OnDemandQueryCreationException)

Example 2 with SiddhiAppContextException

use of io.siddhi.query.api.exception.SiddhiAppContextException in project siddhi by wso2.

the class SiddhiAppRuntimeImpl method getOnDemandQueryOutputAttributes.

/**
 * This method get the onDemandQuery and return the corresponding output and its types.
 *
 * @param onDemandQuery       this onDemandQuery is processed and get the output attributes.
 * @param onDemandQueryString this passed to report errors with context if there are any.
 * @return List of output attributes
 */
private Attribute[] getOnDemandQueryOutputAttributes(OnDemandQuery onDemandQuery, String onDemandQueryString) {
    try {
        OnDemandQueryRuntime onDemandQueryRuntime = onDemandQueryRuntimeMap.get(onDemandQuery);
        if (onDemandQueryRuntime == null) {
            onDemandQueryRuntime = OnDemandQueryParser.parse(onDemandQuery, onDemandQueryString, siddhiAppContext, tableMap, windowMap, aggregationMap);
            onDemandQueryRuntimeMap.put(onDemandQuery, onDemandQueryRuntime);
        }
        return onDemandQueryRuntime.getOnDemandQueryOutputAttributes();
    } catch (RuntimeException e) {
        if (e instanceof SiddhiAppContextException) {
            throw new OnDemandQueryCreationException(((SiddhiAppContextException) e).getMessageWithOutContext(), e, ((SiddhiAppContextException) e).getQueryContextStartIndex(), ((SiddhiAppContextException) e).getQueryContextEndIndex(), null, siddhiAppContext.getSiddhiAppString());
        }
        throw new OnDemandQueryCreationException(e.getMessage(), e);
    }
}
Also used : SiddhiAppRuntimeException(io.siddhi.core.exception.SiddhiAppRuntimeException) OnDemandQueryRuntime(io.siddhi.core.query.OnDemandQueryRuntime) SiddhiAppContextException(io.siddhi.query.api.exception.SiddhiAppContextException) OnDemandQueryCreationException(io.siddhi.core.exception.OnDemandQueryCreationException)

Aggregations

OnDemandQueryCreationException (io.siddhi.core.exception.OnDemandQueryCreationException)2 SiddhiAppRuntimeException (io.siddhi.core.exception.SiddhiAppRuntimeException)2 OnDemandQueryRuntime (io.siddhi.core.query.OnDemandQueryRuntime)2 SiddhiAppContextException (io.siddhi.query.api.exception.SiddhiAppContextException)2 Iterator (java.util.Iterator)1