public long getTimestamp() { return (event != null) ? event.getTimestamp() : 0L; }
@SuppressWarnings("rawtypes") private void compareAndEmit(Set wisb, Set wiri, StreamEvent event) { // compare with wisbValues if wisbValues are already there for dynamic type Collection noDataValues = CollectionUtils.subtract(wisb, wiri); LOG.debug("nodatavalues:" + noDataValues + ", wisb: " + wisb + ", wiri: " + wiri); if (noDataValues != null && noDataValues.size() > 0) { LOG.info("No data alert is triggered with no data values {} and wisb {}", noDataValues, wisbValues); AlertStreamEvent alertEvent = createAlertEvent(event.getTimestamp(), event.getData()); collector.emit(alertEvent); } }
@Override public boolean add(PartitionedEvent partitionedEvent) { synchronized (treeMultisetCache) { if (accept(partitionedEvent.getEvent().getTimestamp())) { treeMultisetCache.add(partitionedEvent); return true; } else { if (LOG.isDebugEnabled()) { LOG.debug("{} is not acceptable, ignored", partitionedEvent); } return false; } } }
@Override public void send(StreamEvent event) throws Exception { Object[] data = event.getData(); List<Object> columnValues = new ArrayList<>(); for (int i = 0; i < expectFieldIndices.size(); i++) { Object o = data[expectFieldIndices.get(i)]; // convert value to string columnValues.add(o.toString()); } boolean isAbsenceAlert = driver.process(columnValues, event.getTimestamp()); // Publishing alerts. if (isAbsenceAlert) { AlertStreamEvent alertEvent = AlertStreamUtils.createAlertEvent(event, context, sds); collector.emit(alertEvent); } }
@Override public String toString() { List<String> dataStrings = new ArrayList<>(); if (this.getData() != null) { for (Object obj : this.getData()) { if (obj != null) { dataStrings.add(obj.toString()); } else { dataStrings.add(null); } } } return String.format("StreamEvent[stream=%S,timestamp=%s,data=[%s],metaVersion=%s]", this.getStreamId(), DateTimeUtil.millisecondsToHumanDateWithMilliseconds(this.getTimestamp()), StringUtils.join(dataStrings, ","), this.getMetaVersion()); }
@SuppressWarnings( {"rawtypes", "unchecked"}) @Override public void send(StreamEvent event) throws Exception { Object[] data = event.getData(); List<Object> columnValues = new ArrayList<>(); for (int i = 0; i < wisbFieldIndices.size(); i++) { Object o = data[wisbFieldIndices.get(i)]; // convert value to string columnValues.add(o.toString()); } distinctWindow.send(columnValues, event.getTimestamp()); Set wiriValues = distinctWindow.distinctValues().keySet(); LOG.debug("window slided: {}, with wiri: {}", distinctWindow.windowSlided(), distinctWindow.distinctValues()); if (distinctWindow.windowSlided()) { compareAndEmit(wisbValues, wiriValues, event); } if (wisbType == NoDataWisbType.dynamic) { // deep copy wisbValues = new HashSet<>(wiriValues); } }
AlertStreamEvent alertEvent = createAlertEvent(sd, event.getTimestamp(), triggerEvent); LOG.info(String.format("Nodata alert %s generated and will be emitted", Joiner.on(",").join(triggerEvent))); collector.emit(alertEvent);
long timestamp = event.getEvent().getTimestamp(); if (accept(timestamp)) { boolean absent = btreeMap.putIfAbsentBoolean(timestamp, new PartitionedEvent[] {event});
public void send(StreamEvent event) throws Exception { context.getPolicyCounter().incr(String.format("%s.%s", this.context.getPolicyDefinition().getName(), "receive_count")); String streamId = event.getStreamId(); InputHandler inputHandler = executionRuntime.getInputHandler(streamId); if (inputHandler != null) { context.getPolicyCounter().incr(String.format("%s.%s", this.context.getPolicyDefinition().getName(), "eval_count")); inputHandler.send(event.getTimestamp(), event.getData()); if (LOG.isDebugEnabled()) { LOG.debug("sent event to siddhi stream {} ", streamId); } } else { context.getPolicyCounter().incr(String.format("%s.%s", this.context.getPolicyDefinition().getName(), "drop_count")); LOG.warn("No input handler found for stream {}", streamId); } }
dataOutput.writeLong(event.getTimestamp()); if (event.getData() == null || event.getData().length == 0) { dataOutput.writeInt(0);
final long eventTime = event.getEvent().getTimestamp(); boolean handled = false;
public void copyFrom(StreamEvent event) { this.setTimestamp(event.getTimestamp()); this.setData(event.getData()); this.setStreamId(event.getStreamId()); this.setMetaVersion(event.getMetaVersion()); }
/** * @return cloned new event object. */ public StreamEvent copy() { StreamEvent newEvent = new StreamEvent(); newEvent.setTimestamp(this.getTimestamp()); newEvent.setData(this.getData()); newEvent.setStreamId(this.getStreamId()); newEvent.setMetaVersion(this.getMetaVersion()); return newEvent; }
/** * Create alert stream event for publisher. */ public static AlertStreamEvent createAlertEvent(StreamEvent event, PolicyHandlerContext context, Map<String, StreamDefinition> sds) { PolicyDefinition policyDef = context.getPolicyDefinition(); AlertStreamEvent alertStreamEvent = new AlertStreamEvent(); alertStreamEvent.setTimestamp(event.getTimestamp()); alertStreamEvent.setData(event.getData()); alertStreamEvent.setStreamId(policyDef.getOutputStreams().get(0)); alertStreamEvent.setPolicyId(policyDef.getName()); if (context.getPolicyEvaluator() != null) { alertStreamEvent.setCreatedBy(context.getPolicyEvaluator().getName()); } alertStreamEvent.setCreatedTime(System.currentTimeMillis()); String is = policyDef.getInputStreams().get(0); StreamDefinition sd = sds.get(is); alertStreamEvent.setSchema(sd); return alertStreamEvent; } }
public void testWithUnsortedEventsIn1hWindow(int count) throws InterruptedException { MockPartitionedCollector mockCollector = new MockPartitionedCollector(); StreamTimeClockInLocalMemory timeClock = new StreamTimeClockInLocalMemory("sampleStream_1"); Ordering<PartitionedEvent> timeOrdering = Ordering.from(PartitionedEventTimeOrderingComparator.INSTANCE); StreamSortWindowHandlerImpl sortHandler = new StreamSortWindowHandlerImpl(); sortHandler.prepare("sampleStream_1", MockSampleMetadataFactory.createSampleStreamSortSpec("sampleStream_1", "PT1h", 5000), mockCollector); List<PartitionedEvent> unsortedList = new LinkedList<>(); StopWatch stopWatch = new StopWatch(); stopWatch.start(); int i = 0; while (i < count) { PartitionedEvent event = MockSampleMetadataFactory.createRandomOutOfTimeOrderEventGroupedByName("sampleStream_1"); sortHandler.nextEvent(event); unsortedList.add(event); if (event.getEvent().getTimestamp() > timeClock.getTime()) { timeClock.moveForward(event.getEvent().getTimestamp()); } sortHandler.onTick(timeClock, System.currentTimeMillis()); i++; } stopWatch.stop(); LOG.info("Produced {} events in {} ms", count, stopWatch.getTime()); sortHandler.close(); Assert.assertFalse(timeOrdering.isOrdered(unsortedList)); Assert.assertTrue(timeOrdering.isOrdered(mockCollector.get())); Assert.assertTrue(mockCollector.get().size() >= 0); }