package cz.cuni.mff.d3s.spl.core.formula;

import cz.cuni.mff.d3s.spl.core.data.DataSource;

/** Wrapper for creating service-level-agreement based SPL formulas. */
public class SlaFormula {
	/**
	 * Create SLA formula where measured samples ought to be smaller than given
	 * limit.
	 * 
	 * @param source
	 *            Data source to use.
	 * @param limitNanos
	 *            Limit in nanoseconds.
	 * @return SPL formula representing the SLA.
	 */
	public static Formula createSimple(DataSource source, long limitNanos) {
		return null;
	}
}

@@ -47,48 +47,139 @@
 ort 
-cz.cuni.mff.d3s.spl.core.data.DataSource
+java.util.NoSuchElementException;%0A%0Aimport cz.cuni.mff.d3s.spl.core.data.DataSource;%0Aimport cz.cuni.mff.d3s.spl.core.data.Statistics
 ;%0A%0A/
@@ -624,12 +624,703 @@
 rn n
-ull;
+ew SimpleSla(source, limitNanos);%0A%09%7D%0A%0A%09private static class SimpleSla implements Formula %7B%0A%0A%09%09private DataSource source;%0A%09%09private long limitNanos;%0A%0A%09%09public SimpleSla(DataSource datasource, long limitNanosec) %7B%0A%09%09%09source = datasource;%0A%09%09%09limitNanos = limitNanosec;%0A%09%09%7D%0A%0A%09%09@Override%0A%09%09public void bind(String variable, DataSource data)%0A%09%09%09%09throws NoSuchElementException %7B%0A%09%09%09throw new UnsupportedOperationException(%0A%09%09%09%09%09%22It is not possible to bind source to simple SLA formula.%22);%0A%09%09%7D%0A%0A%09%09@Override%0A%09%09public Result evaluate() %7B%0A%09%09%09Statistics stats = source.get();%0A%09%09%09if (stats.getArithmeticMean() * 1.1 %3E limitNanos) %7B%0A%09%09%09%09return Result.VIOLATES;%0A%09%09%09%7D else %7B%0A%09%09%09%09return Result.COMPLIES;%0A%09%09%09%7D%0A%09%09%7D
 %0A%09%7D%0A

Implement simple SLA formula