use of io.mantisrx.runtime.computation.ScalarComputation in project mantis by Netflix.
the class TestJobParameterized method getJobInstance.
@Override
public Job<Integer> getJobInstance() {
return MantisJob.<Integer>source(new Source<Integer>() {
@Override
public Observable<Observable<Integer>> call(Context context, Index index) {
Integer start = (Integer) context.getParameters().get("start-range");
Integer end = (Integer) context.getParameters().get("end-range");
return Observable.just(Observable.range(start, end));
}
}).stage(new ScalarComputation<Integer, Integer>() {
@Override
public Observable<Integer> call(Context context, Observable<Integer> t1) {
final Integer scale = (Integer) context.getParameters().get("scale-by");
return t1.map(new Func1<Integer, Integer>() {
@Override
public Integer call(Integer t1) {
return t1 * scale;
}
});
}
}, new ScalarToScalar.Config<Integer, Integer>().codec(Codecs.integer())).sink(new Sink<Integer>() {
@Override
public void init(Context context) {
System.out.println("sink init called");
}
@Override
public void call(Context context, PortRequest p, Observable<Integer> o) {
final String message = (String) context.getParameters().get("sink-message");
o.toBlocking().forEach(new Action1<Integer>() {
@Override
public void call(Integer t1) {
System.out.println(message + t1);
itemsWritten.add(t1);
}
});
}
}).metadata(new Metadata.Builder().name("test job").description("showcase parameters").build()).parameterDefinition(new IntParameter().name("start-range").validator(Validators.range(0, 100)).build()).parameterDefinition(new IntParameter().name("end-range").validator(Validators.range(100, 1000)).build()).parameterDefinition(new IntParameter().name("scale-by").description("scale each value from the range").validator(Validators.range(1, 10)).build()).parameterDefinition(new StringParameter().name("sink-message").defaultValue("hello: ").description("concat with results").validator(Validators.notNullOrEmpty()).build()).create();
}
Aggregations