use of org.wso2.siddhi.core.exception.ConnectionUnavailableException in project siddhi by wso2.
the class AbstractRecordTable method find.
@Override
public StreamEvent find(CompiledCondition compiledCondition, StateEvent matchingEvent) throws ConnectionUnavailableException {
RecordStoreCompiledCondition recordStoreCompiledCondition = ((RecordStoreCompiledCondition) compiledCondition);
Map<String, Object> findConditionParameterMap = new HashMap<>();
for (Map.Entry<String, ExpressionExecutor> entry : recordStoreCompiledCondition.variableExpressionExecutorMap.entrySet()) {
findConditionParameterMap.put(entry.getKey(), entry.getValue().execute(matchingEvent));
}
Iterator<Object[]> records;
if (recordTableHandler != null) {
records = recordTableHandler.find(matchingEvent.getTimestamp(), findConditionParameterMap, recordStoreCompiledCondition.compiledCondition);
} else {
records = find(findConditionParameterMap, recordStoreCompiledCondition.compiledCondition);
}
ComplexEventChunk<StreamEvent> streamEventComplexEventChunk = new ComplexEventChunk<>(true);
if (records != null) {
while (records.hasNext()) {
Object[] record = records.next();
StreamEvent streamEvent = storeEventPool.borrowEvent();
System.arraycopy(record, 0, streamEvent.getOutputData(), 0, record.length);
streamEventComplexEventChunk.add(streamEvent);
}
}
return streamEventComplexEventChunk.getFirst();
}
use of org.wso2.siddhi.core.exception.ConnectionUnavailableException in project siddhi by wso2.
the class MultiClientDistributedSink method connect.
/**
* Will be called to connect to the backend before events are published
*
* @throws ConnectionUnavailableException if it cannot connect to the backend
*/
@Override
public void connect() throws ConnectionUnavailableException {
StringBuilder errorMessages = null;
int errorCount = 0;
for (int i = 0; i < transports.size(); i++) {
try {
Sink transport = transports.get(i);
if (!transport.isConnected()) {
transport.connect();
transport.setConnected(true);
strategy.destinationAvailable(i);
log.info("Connected to destination Id " + i);
}
} catch (ConnectionUnavailableException e) {
errorCount++;
if (errorMessages == null) {
errorMessages = new StringBuilder();
}
errorMessages.append("[Destination").append(i).append("]:").append(e.getMessage());
log.warn(ExceptionUtil.getMessageWithContext(e, siddhiAppContext) + " Failed to Connect to destination ID " + i);
}
}
if (errorCount > 0) {
throw new ConnectionUnavailableException("Error on '" + siddhiAppContext.getName() + "'. " + errorCount + "/" + transports.size() + " connections failed while trying to connect with following error " + "messages:" + errorMessages.toString());
}
}
use of org.wso2.siddhi.core.exception.ConnectionUnavailableException in project siddhi by wso2.
the class InMemoryTransportTestCase method inMemoryWithFailingSource.
@Test
public void inMemoryWithFailingSource() throws InterruptedException {
log.info("Test failing inMemorySource");
String streams = "" + "@app:name('TestSiddhiApp')" + "@source(type='testFailingInMemory', topic='WSO2', @map(type='passThrough')) " + "define stream FooStream (symbol string, price float, volume long); " + "define stream BarStream (symbol string, price float, volume long); ";
String query = "" + "from FooStream " + "select * " + "insert into BarStream; ";
SiddhiManager siddhiManager = new SiddhiManager();
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query);
siddhiAppRuntime.addCallback("BarStream", new StreamCallback() {
@Override
public void receive(Event[] events) {
EventPrinter.print(events);
for (Event event : events) {
wso2Count.incrementAndGet();
}
}
});
siddhiAppRuntime.start();
InMemoryBroker.publish("WSO2", new Event(System.currentTimeMillis(), new Object[] { "WSO2", 55.6f, 100L }));
InMemoryBroker.publish("IBM", new Event(System.currentTimeMillis(), new Object[] { "IBM", 75.6f, 100L }));
TestFailingInMemorySource.fail = true;
TestFailingInMemorySource.connectionCallback.onError(new ConnectionUnavailableException("Connection Lost"));
Thread.sleep(500);
InMemoryBroker.publish("WSO2", new Event(System.currentTimeMillis(), new Object[] { "WSO2", 57.6f, 100L }));
InMemoryBroker.publish("WSO2", new Event(System.currentTimeMillis(), new Object[] { "WSO2", 57.6f, 100L }));
InMemoryBroker.publish("WSO2", new Event(System.currentTimeMillis(), new Object[] { "WSO2", 57.6f, 100L }));
TestFailingInMemorySource.fail = false;
Thread.sleep(5500);
InMemoryBroker.publish("WSO2", new Event(System.currentTimeMillis(), new Object[] { "WSO2", 55.6f, 100L }));
InMemoryBroker.publish("IBM", new Event(System.currentTimeMillis(), new Object[] { "IBM", 75.6f, 100L }));
// assert event count
AssertJUnit.assertEquals("Number of WSO2 events", 2, wso2Count.get());
AssertJUnit.assertEquals("Number of errors", 1, TestFailingInMemorySource.numberOfErrorOccurred);
siddhiAppRuntime.shutdown();
}
use of org.wso2.siddhi.core.exception.ConnectionUnavailableException in project siddhi by wso2.
the class Sink method publish.
@Override
public final void publish(Object payload) {
if (mapperLatencyTracker != null && siddhiAppContext.isStatsEnabled()) {
mapperLatencyTracker.markOut();
}
if (isConnected.get()) {
try {
DynamicOptions dynamicOptions = trpDynamicOptions.get();
publish(payload, dynamicOptions);
if (throughputTracker != null && siddhiAppContext.isStatsEnabled()) {
throughputTracker.eventIn();
}
} catch (ConnectionUnavailableException e) {
isConnected.set(false);
LOG.error(ExceptionUtil.getMessageWithContext(e, siddhiAppContext) + " Connection unavailable at Sink '" + type + "' at '" + streamDefinition.getId() + "', will retry connection immediately.", e);
connectWithRetry();
publish(payload);
}
} else if (isTryingToConnect.get()) {
LOG.error("Error on '" + siddhiAppContext.getName() + "'. Dropping event at Sink '" + type + "' at '" + streamDefinition.getId() + "' as its still trying to reconnect!, events dropped '" + payload + "'");
} else {
connectWithRetry();
publish(payload);
}
}
use of org.wso2.siddhi.core.exception.ConnectionUnavailableException in project siddhi by wso2.
the class AbstractQueryableRecordTable method query.
@Override
public StreamEvent query(StateEvent matchingEvent, CompiledCondition compiledCondition, CompiledSelection compiledSelection) throws ConnectionUnavailableException {
RecordStoreCompiledSelection recordStoreCompiledSelection = ((RecordStoreCompiledSelection) compiledSelection);
RecordStoreCompiledCondition recordStoreCompiledCondition = ((RecordStoreCompiledCondition) compiledCondition);
Map<String, Object> parameterMap = new HashMap<>();
for (Map.Entry<String, ExpressionExecutor> entry : recordStoreCompiledCondition.variableExpressionExecutorMap.entrySet()) {
parameterMap.put(entry.getKey(), entry.getValue().execute(matchingEvent));
}
for (Map.Entry<String, ExpressionExecutor> entry : recordStoreCompiledSelection.variableExpressionExecutorMap.entrySet()) {
parameterMap.put(entry.getKey(), entry.getValue().execute(matchingEvent));
}
Iterator<Object[]> records;
if (recordTableHandler != null) {
records = recordTableHandler.query(matchingEvent.getTimestamp(), parameterMap, recordStoreCompiledCondition.compiledCondition, recordStoreCompiledSelection.compiledSelection);
} else {
records = query(parameterMap, recordStoreCompiledCondition.compiledCondition, recordStoreCompiledSelection.compiledSelection);
}
ComplexEventChunk<StreamEvent> streamEventComplexEventChunk = new ComplexEventChunk<>(true);
if (records != null) {
while (records.hasNext()) {
Object[] record = records.next();
StreamEvent streamEvent = storeEventPool.borrowEvent();
System.arraycopy(record, 0, streamEvent.getOutputData(), 0, record.length);
streamEventComplexEventChunk.add(streamEvent);
}
}
return streamEventComplexEventChunk.getFirst();
}
Aggregations