Java Code Examples for io.siddhi.core.event.Event#setTimestamp()
The following examples show how to use
io.siddhi.core.event.Event#setTimestamp() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SiddhiPolicyTest.java From eagle with Apache License 2.0 | 6 votes |
@Test public void testStrConcat() throws Exception { String ql = " define stream log(timestamp long, switchLabel string, port string, message string); " + " from log select timestamp, str:concat(switchLabel, '===', port) as alertKey, message insert into output; "; SiddhiManager manager = new SiddhiManager(); SiddhiAppRuntime runtime = manager.createSiddhiAppRuntime(ql); runtime.addCallback("output", new StreamCallback() { @Override public void receive(Event[] events) { EventPrinter.print(events); } }); runtime.start(); InputHandler logInput = runtime.getInputHandler("log"); Event e = new Event(); e.setTimestamp(System.currentTimeMillis()); e.setData(new Object[] {System.currentTimeMillis(), "switch-ra-slc-01", "port01", "log-message...."}); logInput.send(e); Thread.sleep(1000); runtime.shutdown(); }
Example 2
Source File: StringSubtractFunctionExtensionTest.java From eagle with Apache License 2.0 | 5 votes |
@Test public void testStringSubtract() throws Exception { Semaphore semp = new Semaphore(1); String ql = " define stream log(timestamp long, switchLabel string, port string, message string); " + " from log select str:subtract(switchLabel, message) as alertKey insert into output; "; SiddhiManager manager = new SiddhiManager(); SiddhiAppRuntime runtime = manager.createSiddhiAppRuntime(ql); runtime.addCallback("output", new StreamCallback() { @Override public void receive(Event[] events) { EventPrinter.print(events); Assert.assertTrue(events.length == 1); Assert.assertTrue(events[0].getData(0).toString().equals("a\nc\ne")); semp.release(); } }); runtime.start(); InputHandler logInput = runtime.getInputHandler("log"); semp.acquire(); Event e = new Event(); e.setTimestamp(System.currentTimeMillis()); String ths = "[\"a\", \"b\", \"c\", \"d\", \"e\"]"; String rhs = "[\"b\", \"d\"]"; e.setData(new Object[] {System.currentTimeMillis(), ths, "port01", rhs}); logInput.send(e); semp.acquire(); runtime.shutdown(); }
Example 3
Source File: StringListSizeFunctionExtensionTest.java From eagle with Apache License 2.0 | 5 votes |
@Test public void testStringListSize() throws Exception { Semaphore semp = new Semaphore(1); String ql = " define stream log(timestamp long, switchLabel string, port string, message string); " + " from log select str:listSize(switchLabel) as alertKey insert into output; "; SiddhiManager manager = new SiddhiManager(); SiddhiAppRuntime runtime = manager.createSiddhiAppRuntime(ql); runtime.addCallback("output", new StreamCallback() { @Override public void receive(Event[] events) { EventPrinter.print(events); Assert.assertTrue(events.length == 1); Assert.assertTrue(Integer.parseInt(events[0].getData(0).toString()) == 5); semp.release(); } }); runtime.start(); InputHandler logInput = runtime.getInputHandler("log"); semp.acquire(); Event e = new Event(); e.setTimestamp(System.currentTimeMillis()); String ths = "[\"a\", \"b\", \"c\", \"d\", \"e\"]"; String rhs = "[\"b\", \"d\"]"; e.setData(new Object[] {System.currentTimeMillis(), ths, "port01", rhs}); logInput.send(e); semp.acquire(); runtime.shutdown(); }
Example 4
Source File: InputEventHandler.java From siddhi with Apache License 2.0 | 5 votes |
public void sendEvent(Event event) throws InterruptedException { try { if (latencyTracker != null && Level.BASIC.compareTo(siddhiAppContext.getRootMetricsLevel()) <= 0) { latencyTracker.markOut(); } Object[] transportProperties = trpProperties.get(); trpProperties.remove(); String[] transportSyncProperties = trpSyncProperties.get(); trpSyncProperties.remove(); if (event.getTimestamp() == -1) { long currentTimestamp = timestampGenerator.currentTime(); event.setTimestamp(currentTimestamp); } for (int i = 0; i < transportMapping.size(); i++) { AttributeMapping attributeMapping = transportMapping.get(i); event.getData()[attributeMapping.getPosition()] = AttributeConverter.getPropertyValue( transportProperties[i], attributeMapping.getType()); } inputEventHandlerCallback.sendEvent(event, transportSyncProperties); eventCount++; } catch (RuntimeException e) { LOG.error(ExceptionUtil.getMessageWithContext(e, siddhiAppContext) + " Error in applying transport property mapping for '" + sourceType + "' source at '" + inputHandler.getStreamId() + "' stream.", e); } finally { trpProperties.remove(); trpSyncProperties.remove(); } }
Example 5
Source File: InputEventHandler.java From siddhi with Apache License 2.0 | 5 votes |
public void sendEvents(Event[] events) throws InterruptedException { try { if (latencyTracker != null && Level.BASIC.compareTo(siddhiAppContext.getRootMetricsLevel()) <= 0) { latencyTracker.markOut(); } Object[] transportProperties = trpProperties.get(); trpProperties.remove(); String[] transportSyncProperties = trpSyncProperties.get(); trpSyncProperties.remove(); long currentTimestamp = timestampGenerator.currentTime(); for (Event event : events) { if (event.getTimestamp() == -1) { event.setTimestamp(currentTimestamp); } for (int i = 0; i < transportMapping.size(); i++) { AttributeMapping attributeMapping = transportMapping.get(i); event.getData()[attributeMapping.getPosition()] = AttributeConverter.getPropertyValue( transportProperties[i], attributeMapping.getType()); } } inputEventHandlerCallback.sendEvents(events, transportSyncProperties); eventCount += events.length; } catch (RuntimeException e) { LOG.error(ExceptionUtil.getMessageWithContext(e, siddhiAppContext) + " Error in applying transport property mapping for '" + sourceType + "' source at '" + inputHandler.getStreamId() + "' stream.", e); } finally { trpProperties.remove(); trpSyncProperties.remove(); } }
Example 6
Source File: TestSiddhiExternalTimeBatch.java From eagle with Apache License 2.0 | 4 votes |
Event createEvent(String host, long timestamp) { Event e = new Event(); e.setTimestamp(timestamp); e.setData(new Object[] {host, timestamp, "missingblocks", "site1", 14.0}); return e; }
Example 7
Source File: TestSiddhiAggregator.java From eagle with Apache License 2.0 | 4 votes |
Event createEvent(String host, long timestamp) { Event e = new Event(); e.setTimestamp(timestamp); e.setData(new Object[] {host, timestamp, "missingblocks", "site1", 14.0}); return e; }
Example 8
Source File: StringListSizeFunctionExtensionTest.java From eagle with Apache License 2.0 | 4 votes |
@Test public void testStringListSize2() throws Exception { Semaphore semp = new Semaphore(1); String ql = " define stream log(timestamp long, site string, component string, resource string, host string, value string); " + " from a = log[resource == \"hadoop.namenode.namenodeinfo.corruptfiles\"],\n" + "b = log[component == a.component and resource == a.resource and host == a.host and a.value != b.value]\n" + "select b.site as site, b.host as host, b.component as component, b.resource as resource, " + "b.timestamp as timestamp, str:listSize(b.value) as newMissingBlocksNumber, str:listSize(a.value) as oldMissingBlocksNumber, str:subtract(b.value, a.value) as missingBlocks\n" + "insert into output;"; SiddhiManager manager = new SiddhiManager(); SiddhiAppRuntime runtime = manager.createSiddhiAppRuntime(ql); runtime.addCallback("output", new StreamCallback() { @Override public void receive(Event[] events) { EventPrinter.print(events); Assert.assertTrue(events.length == 1); Assert.assertTrue(Integer.parseInt(events[0].getData(5).toString()) == 5); Assert.assertTrue(Integer.parseInt(events[0].getData(6).toString()) == 2); Assert.assertTrue(events[0].getData(7).toString().equals("a\nc\ne")); semp.release(); } }); runtime.start(); InputHandler logInput = runtime.getInputHandler("log"); semp.acquire(); Event e = new Event(); e.setTimestamp(System.currentTimeMillis()); String rhs = "[\"b\", \"d\"]"; e.setData(new Object[] {System.currentTimeMillis(), "a", "a", "hadoop.namenode.namenodeinfo.corruptfiles", "port01", rhs}); logInput.send(e); e.setTimestamp(System.currentTimeMillis()); String ths = "[\"a\", \"b\", \"c\", \"d\", \"e\"]"; e.setData(new Object[] {System.currentTimeMillis(), "a", "a", "hadoop.namenode.namenodeinfo.corruptfiles", "port01", ths}); logInput.send(e); semp.acquire(); runtime.shutdown(); }