All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.yahoo.vespa.indexinglanguage.expressions.SleepExpression Maven / Gradle / Ivy

There is a newer version: 8.465.15
Show newest version
package com.yahoo.vespa.indexinglanguage.expressions;

import com.yahoo.document.DataType;
import com.yahoo.document.datatypes.FieldValue;
import com.yahoo.document.datatypes.NumericFieldValue;

/**
 * Utility expression that will sleep the amount of time given in the numeric field.
 * Non-numeric fields will be ignored.
 *
 * @author baldersheim
 */
public final class SleepExpression extends Expression {

    public SleepExpression() {
        super(UnresolvedDataType.INSTANCE);
    }

    @Override
    protected void doVerify(VerificationContext context) { }

    @Override
    protected void doExecute(ExecutionContext context) {
        FieldValue value = context.getCurrentValue();
        if (value instanceof NumericFieldValue num) {
            double napSecs = num.getNumber().doubleValue();
            long nanos = (long)(napSecs*1_000_000_000.0);
            try {
                Thread.sleep(nanos / 1_000_000, (int) (nanos % 1_000_000));
            } catch (InterruptedException e) {
                // Do nothing
            }
        }
    }

    @Override public DataType createdOutputType() { return null; }
    @Override public String toString() { return "sleep"; }
    @Override public boolean equals(Object obj) { return obj instanceof SleepExpression; }
    @Override public int hashCode() { return getClass().hashCode(); }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy