@Override public void consume(BulletRecord data) { // Since Raw is the only strategy that can close and is really a special case, it should check before // consumption. Otherwise, Windows will need to expose the fact that the aggregation should not be fed more data // in order to prevent Raw from accidentally consuming/combining till only the Window is closed. if (data == null || isClosed()) { return; } consumed++; aggregate.add(data); }
/** * Since {@link #getData()} returns a {@link List} of {@link BulletRecord}, this method consumes * that list. If the deserialized List has a size that takes the aggregated records above the aggregation size, only * the first X records in the List will be combined till the size is reached. * * @param data A serialized {@link List} of {@link BulletRecord}. */ @Override public void combine(byte[] data) { // See the comment in consume on why the check for isClosed. if (data == null || isClosed()) { return; } ArrayList<BulletRecord> batch = SerializerDeserializer.fromBytes(data); if (batch == null || batch.isEmpty()) { return; } int batchSize = batch.size(); int maximumLeft = size - aggregate.size(); if (batchSize <= maximumLeft) { aggregate.addAll(batch); combined += batchSize; } else { aggregate.addAll(batch.subList(0, maximumLeft)); combined += maximumLeft; } }