private static List<Trigger> protosToTriggers(List<RunnerApi.Trigger> triggers) { List<Trigger> result = Lists.newArrayList(); for (RunnerApi.Trigger trigger : triggers) { result.add(fromProto(trigger)); } return result; }
@Test public void testToProtoAndBack() throws Exception { Trigger trigger = toProtoAndBackSpec.getTrigger(); Trigger toProtoAndBackTrigger = TriggerTranslation.fromProto(TriggerTranslation.toProto(trigger)); assertThat(toProtoAndBackTrigger, equalTo(trigger)); } }
.withEarlyFirings( (OnceTrigger) fromProto(triggerProto.getAfterEndOfWindow().getEarlyFirings())); (OnceTrigger) fromProto(triggerProto.getAfterEndOfWindow().getLateFirings())); .withLateFirings((OnceTrigger) fromProto(eowProto.getLateFirings())); return Never.ever(); case OR_FINALLY: return fromProto(triggerProto.getOrFinally().getMain()) .orFinally((OnceTrigger) fromProto(triggerProto.getOrFinally().getFinally())); case REPEAT: return Repeatedly.forever(fromProto(triggerProto.getRepeat().getSubtrigger())); case DEFAULT: return DefaultTrigger.of();
/** * Converts from {@link RunnerApi.WindowingStrategy} to the SDK's {@link WindowingStrategy} using * the provided components to dereferences identifiers found in the proto. */ public static WindowingStrategy<?, ?> fromProto( RunnerApi.WindowingStrategy proto, RehydratedComponents components) throws InvalidProtocolBufferException { SdkFunctionSpec windowFnSpec = proto.getWindowFn(); WindowFn<?, ?> windowFn = windowFnFromProto(windowFnSpec); TimestampCombiner timestampCombiner = timestampCombinerFromProto(proto.getOutputTime()); AccumulationMode accumulationMode = fromProto(proto.getAccumulationMode()); Trigger trigger = TriggerTranslation.fromProto(proto.getTrigger()); ClosingBehavior closingBehavior = fromProto(proto.getClosingBehavior()); Duration allowedLateness = Duration.millis(proto.getAllowedLateness()); OnTimeBehavior onTimeBehavior = fromProto(proto.getOnTimeBehavior()); return WindowingStrategy.of(windowFn) .withAllowedLateness(allowedLateness) .withMode(accumulationMode) .withTrigger(trigger) .withTimestampCombiner(timestampCombiner) .withClosingBehavior(closingBehavior) .withOnTimeBehavior(onTimeBehavior); }