com.google.cloud.dataflow.sdk.transforms.windowing

## Class AfterDelayFromFirstElement<W extends BoundedWindow>

- java.lang.Object
- - com.google.cloud.dataflow.sdk.transforms.windowing.Trigger<W>
  - - com.google.cloud.dataflow.sdk.transforms.windowing.Trigger.OnceTrigger<W>
    - - com.google.cloud.dataflow.sdk.transforms.windowing.AfterDelayFromFirstElement<W>

All Implemented Interfaces:
  TriggerBuilder<W>, Serializable

Direct Known Subclasses:
  AfterProcessingTime

    @Experimental(value=TRIGGER)
    public abstract class AfterDelayFromFirstElement<W extends BoundedWindow>
    extends Trigger.OnceTrigger<W>

A base class for triggers that happen after a processing time delay from the arrival of the first element in a pane.

This class is for internal use only and may change at any time.

See Also:
  Serialized Form

### Nested Class Summary

### Nested classes/interfaces inherited from class com.google.cloud.dataflow.sdk.transforms.windowing.Trigger

`Trigger.MergingTriggerInfo<W extends BoundedWindow>, Trigger.OnceTrigger<W extends BoundedWindow>, Trigger.OnElementContext, Trigger.OnMergeContext, Trigger.TriggerContext, Trigger.TriggerInfo<W extends BoundedWindow>`

### Field Summary

Fields
`protected static com.google.cloud.dataflow.sdk.util.state.StateTag<Object,com.google.cloud.dataflow.sdk.util.state.AccumulatorCombiningState<Instant,Combine.Holder<Instant>,Instant>>` `DELAYED_UNTIL_TAG`
`protected static List<SerializableFunction<Instant,Instant>>` `IDENTITY`
`protected List<SerializableFunction<Instant,Instant>>` `timestampMappers` A list of timestampMappers m1, m2, m3, ...

### Fields inherited from class com.google.cloud.dataflow.sdk.transforms.windowing.Trigger

`subTriggers`

### Constructor Summary

Constructors
Constructor and Description
`AfterDelayFromFirstElement(com.google.cloud.dataflow.sdk.util.TimeDomain timeDomain, List<SerializableFunction<Instant,Instant>> timestampMappers)`

### Method Summary

All Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods
`AfterDelayFromFirstElement<W>` `alignedTo(Duration size)` Aligns the time to be the smallest multiple of `size` greater than the timestamp since the epoch.
`AfterDelayFromFirstElement<W>` `alignedTo(Duration size, Instant offset)` Aligns timestamps to the smallest multiple of `size` since the `offset` greater than the timestamp.
`void` `clear(Trigger.TriggerContext c)` Clear any state associated with this trigger in the given window.
`protected Instant` `computeTargetTimestamp(Instant time)`
`abstract Instant` `getCurrentTime(Trigger.TriggerContext context)` To complete an implementation, return the desired time from the TriggerContext.
`Instant` `getWatermarkThatGuaranteesFiring(W window)` Returns a bound in watermark time by which this trigger would have fired at least once for a given window had there been input data.
`boolean` `isCompatible(Trigger<?> other)` Returns whether this performs the same triggering as the given `Trigger`.
`Trigger.OnceTrigger<W>` `mappedTo(SerializableFunction<Instant,Instant> timestampMapper)` Deprecated. This will be removed in the next major version. Please use only `plusDelayOf(org.joda.time.Duration)` and `alignedTo(org.joda.time.Duration, org.joda.time.Instant)`.
`protected abstract AfterDelayFromFirstElement<W>` `newWith(List<SerializableFunction<Instant,Instant>> transform)` To complete an implementation, return a new instance like this one, but incorporating the provided timestamp mapping functions.
`void` `onElement(Trigger.OnElementContext c)` Called immediately after an element is first incorporated into a window.
`void` `onMerge(Trigger.OnMergeContext c)` Called immediately after windows have been merged.
`protected void` `onOnlyFiring(Trigger.TriggerContext context)` Called exactly once by `Trigger.OnceTrigger.onFire(com.google.cloud.dataflow.sdk.transforms.windowing.Trigger<W>.TriggerContext)` when the trigger is fired.
`AfterDelayFromFirstElement<W>` `plusDelayOf(Duration delay)` Adds some delay to the original target time.
`void` `prefetchOnElement(com.google.cloud.dataflow.sdk.util.state.StateAccessor<?> state)` Called to allow the trigger to prefetch any state it will likely need to read from during an `Trigger.onElement(com.google.cloud.dataflow.sdk.transforms.windowing.Trigger<W>.OnElementContext)` call.
`void` `prefetchOnMerge(com.google.cloud.dataflow.sdk.util.state.MergingStateAccessor<?,W> state)` Called to allow the trigger to prefetch any state it will likely need to read from during an `Trigger.onMerge(com.google.cloud.dataflow.sdk.transforms.windowing.Trigger<W>.OnMergeContext)` call.
`void` `prefetchShouldFire(com.google.cloud.dataflow.sdk.util.state.StateAccessor<?> state)` Called to allow the trigger to prefetch any state it will likely need to read from during an `Trigger.shouldFire(com.google.cloud.dataflow.sdk.transforms.windowing.Trigger<W>.TriggerContext)` call.
`boolean` `shouldFire(Trigger.TriggerContext context)` Returns `true` if the current state of the trigger indicates that its condition is satisfied and it is ready to fire.

### Methods inherited from class com.google.cloud.dataflow.sdk.transforms.windowing.Trigger.OnceTrigger

`getContinuationTrigger, onFire`

### Methods inherited from class com.google.cloud.dataflow.sdk.transforms.windowing.Trigger

`buildTrigger, equals, getContinuationTrigger, hashCode, orFinally, prefetchOnFire, subTriggers, toString`

### Methods inherited from class java.lang.Object

`clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

### Field Detail

#### IDENTITY

    protected static final List<SerializableFunction<Instant,Instant>> IDENTITY

#### DELAYED_UNTIL_TAG

    protected static final com.google.cloud.dataflow.sdk.util.state.StateTag<Object,com.google.cloud.dataflow.sdk.util.state.AccumulatorCombiningState<Instant,Combine.Holder<Instant>,Instant>> DELAYED_UNTIL_TAG

#### timestampMappers

    protected final List<SerializableFunction<Instant,Instant>> timestampMappers

A list of timestampMappers m1, m2, m3, ... m_n considered to be composed in sequence. The overall mapping for an instance `instance` is `m_n(... m3(m2(m1(instant))`, implemented via #computeTargetTimestamp

### Constructor Detail

#### AfterDelayFromFirstElement

    public AfterDelayFromFirstElement(com.google.cloud.dataflow.sdk.util.TimeDomain timeDomain,
                                      List<SerializableFunction<Instant,Instant>> timestampMappers)

### Method Detail

#### getCurrentTime

    @Nullable
    public abstract Instant getCurrentTime(Trigger.TriggerContext context)

To complete an implementation, return the desired time from the TriggerContext.

#### newWith

    protected abstract AfterDelayFromFirstElement<W> newWith(List<SerializableFunction<Instant,Instant>> transform)

To complete an implementation, return a new instance like this one, but incorporating the provided timestamp mapping functions. Generally should be used by calling the constructor of this class from the constructor of the subclass.

#### alignedTo

    public AfterDelayFromFirstElement<W> alignedTo(Duration size,
                                                   Instant offset)

Aligns timestamps to the smallest multiple of `size` since the `offset` greater than the timestamp.

TODO: Consider sharing this with FixedWindows, and bring over the equivalent of CalendarWindows.

#### alignedTo

    public AfterDelayFromFirstElement<W> alignedTo(Duration size)

Aligns the time to be the smallest multiple of `size` greater than the timestamp since the epoch.

#### plusDelayOf

    public AfterDelayFromFirstElement<W> plusDelayOf(Duration delay)

Adds some delay to the original target time.

Parameters:
  `delay` - the delay to add
Returns:
  An updated time trigger that will wait the additional time before firing.

#### mappedTo

    @Deprecated
    public Trigger.OnceTrigger<W> mappedTo(SerializableFunction<Instant,Instant> timestampMapper)

Deprecated. This will be removed in the next major version. Please use only `plusDelayOf(org.joda.time.Duration)` and `alignedTo(org.joda.time.Duration, org.joda.time.Instant)`.

#### isCompatible

    public boolean isCompatible(Trigger<?> other)

Description copied from class: `Trigger`
Returns whether this performs the same triggering as the given `Trigger`.

Overrides:
  `isCompatible` in class `Trigger<W extends BoundedWindow>`

#### prefetchOnElement

    public void prefetchOnElement(com.google.cloud.dataflow.sdk.util.state.StateAccessor<?> state)

Description copied from class: `Trigger`
Called to allow the trigger to prefetch any state it will likely need to read from during an `Trigger.onElement(com.google.cloud.dataflow.sdk.transforms.windowing.Trigger<W>.OnElementContext)` call.

Overrides:
  `prefetchOnElement` in class `Trigger<W extends BoundedWindow>`

#### onElement

    public void onElement(Trigger.OnElementContext c)
                   throws Exception

Description copied from class: `Trigger`
Called immediately after an element is first incorporated into a window.

Specified by:
  `onElement` in class `Trigger<W extends BoundedWindow>`
Throws:
  `Exception`

#### prefetchOnMerge

    public void prefetchOnMerge(com.google.cloud.dataflow.sdk.util.state.MergingStateAccessor<?,W> state)

Description copied from class: `Trigger`
Called to allow the trigger to prefetch any state it will likely need to read from during an `Trigger.onMerge(com.google.cloud.dataflow.sdk.transforms.windowing.Trigger<W>.OnMergeContext)` call.

Overrides:
  `prefetchOnMerge` in class `Trigger<W extends BoundedWindow>`

#### onMerge

    public void onMerge(Trigger.OnMergeContext c)
                 throws Exception

Description copied from class: `Trigger`
Called immediately after windows have been merged.

Leaf triggers should update their state by inspecting their status and any state in the merging windows. Composite triggers should update their state by calling `ExecutableTrigger.invokeOnMerge(com.google.cloud.dataflow.sdk.transforms.windowing.Trigger<W>.OnMergeContext)` on their sub-triggers, and applying appropriate logic.

A trigger such as `AfterWatermark.pastEndOfWindow()` may no longer be finished; it is the responsibility of the trigger itself to record this fact. It is forbidden for a trigger to become finished due to `Trigger.onMerge(com.google.cloud.dataflow.sdk.transforms.windowing.Trigger<W>.OnMergeContext)`, as it has not yet fired the pending elements that led to it being ready to fire.

The implementation does not need to clear out any state associated with the old windows.

Specified by:
  `onMerge` in class `Trigger<W extends BoundedWindow>`
Throws:
  `Exception`

#### prefetchShouldFire

    public void prefetchShouldFire(com.google.cloud.dataflow.sdk.util.state.StateAccessor<?> state)

Description copied from class: `Trigger`
Called to allow the trigger to prefetch any state it will likely need to read from during an `Trigger.shouldFire(com.google.cloud.dataflow.sdk.transforms.windowing.Trigger<W>.TriggerContext)` call.

Overrides:
  `prefetchShouldFire` in class `Trigger<W extends BoundedWindow>`

#### clear

    public void clear(Trigger.TriggerContext c)
               throws Exception

Description copied from class: `Trigger`
Clear any state associated with this trigger in the given window.

This is called after a trigger has indicated it will never fire again. The trigger system keeps enough information to know that the trigger is finished, so this trigger should clear all of its state.

Overrides:
  `clear` in class `Trigger<W extends BoundedWindow>`
Throws:
  `Exception`

#### getWatermarkThatGuaranteesFiring

    public Instant getWatermarkThatGuaranteesFiring(W window)

Description copied from class: `Trigger`
Returns a bound in watermark time by which this trigger would have fired at least once for a given window had there been input data. This is a static property of a trigger that does not depend on its state.

For triggers that do not fire based on the watermark advancing, returns `BoundedWindow.TIMESTAMP_MAX_VALUE`.

This estimate is used to determine that there are no elements in a side-input window, which causes the default value to be used instead.

Specified by:
  `getWatermarkThatGuaranteesFiring` in class `Trigger<W extends BoundedWindow>`

#### shouldFire

    public boolean shouldFire(Trigger.TriggerContext context)
                       throws Exception

Description copied from class: `Trigger`
Returns `true` if the current state of the trigger indicates that its condition is satisfied and it is ready to fire.

Specified by:
  `shouldFire` in class `Trigger<W extends BoundedWindow>`
Throws:
  `Exception`

#### onOnlyFiring

    protected void onOnlyFiring(Trigger.TriggerContext context)
                         throws Exception

Description copied from class: `Trigger.OnceTrigger`
Called exactly once by `Trigger.OnceTrigger.onFire(com.google.cloud.dataflow.sdk.transforms.windowing.Trigger<W>.TriggerContext)` when the trigger is fired. By default, invokes `Trigger.OnceTrigger.onFire(com.google.cloud.dataflow.sdk.transforms.windowing.Trigger<W>.TriggerContext)` on all subtriggers for which `Trigger.shouldFire(com.google.cloud.dataflow.sdk.transforms.windowing.Trigger<W>.TriggerContext)` is `true`.

Specified by:
  `onOnlyFiring` in class `Trigger.OnceTrigger<W extends BoundedWindow>`
Throws:
  `Exception`

#### computeTargetTimestamp

    protected Instant computeTargetTimestamp(Instant time)