@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 List<Integer> chooseTasks(int taskId, List<Object> values) { Object routingKeyObj = values.get(0); if (routingKeyObj != null) { PartitionedEvent partitionedEvent = (PartitionedEvent) routingKeyObj; if (partitionedEvent.getPartition().getType() == StreamPartition.Type.GLOBAL) { return globalGroupingDelegate.chooseTasks(taskId, values); } else if (partitionedEvent.getPartition().getType() == StreamPartition.Type.GROUPBY) { return Collections.singletonList(outdegreeTasks.get((int) (partitionedEvent.getPartitionKey() % this.outdegreeTasks.size()))); } // Shuffle by defaults return shuffleGroupingDelegate.chooseTasks(taskId, values); } LOG.warn("Illegal null StreamRoute, throw event"); return Collections.emptyList(); } }
@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); }
/** * This unit test is not to mock the end2end logic of correlation spout, * but simply generate some sample data for following bolts testing */ @Override public void nextTuple() { PartitionedEvent event = MockSampleMetadataFactory.createRandomOutOfTimeOrderEventGroupedByName("sampleStream_1"); LOG.info("Receive {}", event); collector.emit(outputStreamIds.get( // group by the first field in event i.e. name (int) (event.getPartitionKey() % outputStreamIds.size())), Collections.singletonList(event)); Utils.sleep(500); }
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); } }