@Override public boolean equals(Object obj) { if (obj == this) { return true; } if (obj == null) { return false; } if (obj instanceof PartitionedEvent) { PartitionedEvent another = (PartitionedEvent) obj; return !(this.partitionKey != another.getPartitionKey() || !Objects.equals(this.event, another.getEvent()) || !Objects.equals(this.partition, another.getPartition()) || !Objects.equals(this.anchor, another.anchor)); } else { return false; } }
@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; } } }
private static boolean isAcceptedByPolicy(PartitionedEvent event, PolicyDefinition policy) { return policy.getPartitionSpec().contains(event.getPartition()) && (policy.getInputStreams().contains(event.getEvent().getStreamId()) || policy.getDefinition().getInputStreams().contains(event.getEvent().getStreamId())); }
@Override public void serialize(PartitionedEvent entity, DataOutput dataOutput) throws IOException { dataOutput.writeLong(entity.getPartitionKey()); streamEventSerializer.serialize(entity.getEvent(), dataOutput); streamPartitionSerializer.serialize(entity.getPartition(), dataOutput); }
@Override public void serialize(PartitionedEvent entity, DataOutput dataOutput) throws IOException { dataOutput.writeLong(entity.getPartitionKey()); streamEventSerializer.serialize(entity.getEvent(), dataOutput); streamPartitionSerializer.serialize(entity.getPartition(), dataOutput); }
/** * fixme make selection of PolicyStreamHandler to be more efficient. * * @param partitionedEvent PartitionedEvent */ private void dispatch(PartitionedEvent partitionedEvent) { boolean handled = false; for (Map.Entry<String, CompositePolicyHandler> policyStreamHandler : policyStreamHandlerMap.entrySet()) { if (isAcceptedByPolicy(partitionedEvent, policyDefinitionMap.get(policyStreamHandler.getKey()))) { try { handled = true; this.context.counter().incr("eval_count"); policyStreamHandler.getValue().send(partitionedEvent.getEvent()); } catch (Exception e) { this.context.counter().incr("fail_count"); LOG.error("{} failed to handle {}", policyStreamHandler.getValue(), partitionedEvent.getEvent(), e); } } } if (!handled) { this.context.counter().incr("drop_count"); LOG.warn("Drop stream non-matched event {}, which should not be sent to evaluator", partitionedEvent); } else { this.context.counter().incr("accept_count"); } }
long timestamp = event.getEvent().getTimestamp(); if (accept(timestamp)) { boolean absent = btreeMap.putIfAbsentBoolean(timestamp, new PartitionedEvent[] {event});
public PartitionedEvent copy() { PartitionedEvent copied = new PartitionedEvent(); copied.setEvent(this.getEvent()); copied.setPartition(this.partition); copied.setPartitionKey(this.partitionKey); return copied; }
private void writePartitionedEvent(DataOutput2 out, PartitionedEvent event) throws IOException { out.packLong(event.getPartitionKey()); int partitionHashCode = 0; if (event.getPartition() != null) { partitionHashCode = event.getPartition().hashCode(); if (!hashCodePartitionDict.containsKey(partitionHashCode)) { hashCodePartitionDict.put(partitionHashCode, event.getPartition()); } } out.packInt(partitionHashCode); if (event.getEvent() != null) { byte[] eventBytes = SerializableUtils.serializeToCompressedByteArray(event.getEvent()); out.packInt(eventBytes.length); out.write(eventBytes); } else { out.packInt(0); } }
PartitionedEvent pe = deserialize(input.getValueByField(AlertConstants.FIELD_0)); if (logEventEnabled) { LOG.info("Alert bolt {} received event: {}", boltId, pe.getEvent()); String streamEventVersion = pe.getEvent().getMetaVersion(); pe.getEvent().setMetaVersion(specVersion); } else if (streamEventVersion != null && !streamEventVersion.equals(specVersion)) { if (specVersion != null && streamEventVersion != null specVersionOutofdate = timestampOfSpecVersion < timestampOfStreamEventVersion; if (!specVersionOutofdate) { pe.getEvent().setMetaVersion(specVersion);
final long eventTime = event.getEvent().getTimestamp(); boolean handled = false;
StreamEvent newEvent = event.getEvent().copy();
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); }