use of io.engineblock.activityapi.input.InputDispenser in project engineblock by engineblock.
the class ActivityExecutorTest method testNewActivityExecutor.
@Test(enabled = true)
public void testNewActivityExecutor() {
ActivityDef ad = ActivityDef.parseActivityDef("type=diag;alias=test;cycles=1000;");
Optional<ActivityType> activityType = ActivityType.FINDER.get(ad.getActivityType());
Input longSupplier = new TargetRateInput(ad);
MotorDispenser cmf = getActivityMotorFactory(ad, motorActionDelay(999), longSupplier);
Activity a = new SimpleActivity(ad);
InputDispenser idisp = new CoreInputDispenser(a);
ActionDispenser adisp = new CoreActionDispenser(a);
OutputDispenser tdisp = CoreServices.getOutputDispenser(a).orElse(null);
MotorDispenser mdisp = new CoreMotorDispenser(a, idisp, adisp, tdisp);
a.setActionDispenserDelegate(adisp);
a.setInputDispenserDelegate(idisp);
a.setMotorDispenserDelegate(mdisp);
ActivityExecutor ae = new ActivityExecutor(a);
ad.setThreads(5);
ae.startActivity();
int[] speeds = new int[] { 1, 2000, 5, 2000, 2, 2000 };
for (int offset = 0; offset < speeds.length; offset += 2) {
int threadTarget = speeds[offset];
int threadTime = speeds[offset + 1];
logger.info("Setting thread level to " + threadTarget + " for " + threadTime + " seconds.");
ad.setThreads(threadTarget);
try {
Thread.sleep(threadTime);
} catch (InterruptedException ignored) {
}
}
ad.setThreads(0);
}
use of io.engineblock.activityapi.input.InputDispenser in project engineblock by engineblock.
the class ActivityExecutorTest method testDelayedStartSanity.
@Test
public void testDelayedStartSanity() {
ActivityDef ad = ActivityDef.parseActivityDef("type=diag;alias=test;cycles=1000;initdelay=5000;");
Optional<ActivityType> activityType = ActivityType.FINDER.get(ad.getActivityType());
Activity a = new DelayedInitActivity(ad);
InputDispenser idisp = new CoreInputDispenser(a);
ActionDispenser adisp = new CoreActionDispenser(a);
OutputDispenser tdisp = CoreServices.getOutputDispenser(a).orElse(null);
MotorDispenser mdisp = new CoreMotorDispenser(a, idisp, adisp, tdisp);
a.setActionDispenserDelegate(adisp);
a.setOutputDispenserDelegate(tdisp);
a.setInputDispenserDelegate(idisp);
a.setMotorDispenserDelegate(mdisp);
ActivityExecutor ae = new ActivityExecutor(a);
ad.setThreads(1);
ae.startActivity();
ae.awaitCompletion(15000);
assertThat(idisp.getInput(10).getInputSegment(3)).isNull();
}
use of io.engineblock.activityapi.input.InputDispenser in project engineblock by engineblock.
the class CoreServices method getInputDispenser.
// public static <A extends Activity> Optional<IntPredicateDispenser> getResultFilterDispenser(A activity) {
// Optional<IntPredicateDispenser> intPredicateDispenser = new SimpleConfig(activity, "resultfilter")
// .getString("type")
// .flatMap(ExperimentalResultFilterType.FINDER::get)
// .map(rft -> rft.getFilterDispenser(activity));
// return intPredicateDispenser;
// }
//
public static <A extends Activity> InputDispenser getInputDispenser(A activity) {
String inputTypeName = new SimpleConfig(activity, "input").getString("type").orElse("targetrate");
InputType inputType = InputType.FINDER.getOrThrow(inputTypeName);
InputDispenser dispenser = inputType.getInputDispenser(activity);
Optional<Predicate<ResultReadable>> inputFilterDispenser = getInputFilter(activity);
if (inputFilterDispenser.isPresent()) {
dispenser = new FilteringInputDispenser(dispenser, inputFilterDispenser.get());
}
return dispenser;
}
use of io.engineblock.activityapi.input.InputDispenser in project engineblock by engineblock.
the class CoreInputDispenser method createInput.
private synchronized Input createInput(long slot) {
SimpleConfig conf = new SimpleConfig(activity, "input");
String inputType = conf.getString("type").orElse("targetrate");
InputType inputTypeImpl = InputType.FINDER.getOrThrow(inputType);
InputDispenser inputDispenser = inputTypeImpl.getInputDispenser(activity);
if (inputDispenser instanceof ActivitiesAware) {
((ActivitiesAware) inputDispenser).setActivitiesMap(activities);
}
Input input = inputDispenser.getInput(slot);
return input;
}
use of io.engineblock.activityapi.input.InputDispenser in project engineblock by engineblock.
the class ActivityType method getAssembledActivity.
/**
* Create an instance of an activity that ties together all the components into a usable
* activity instance. This is the method that should be called by executor classes.
*
* @param activityDef the definition that initializez and controlls the activity.
* @param activities a map of existing activities
* @return a distinct activity instance for each call
*/
default Activity getAssembledActivity(ActivityDef activityDef, Map<String, Activity> activities) {
A activity = getActivity(activityDef);
InputDispenser inputDispenser = getInputDispenser(activity);
if (inputDispenser instanceof ActivitiesAware) {
((ActivitiesAware) inputDispenser).setActivitiesMap(activities);
}
activity.setInputDispenserDelegate(inputDispenser);
ActionDispenser actionDispenser = getActionDispenser(activity);
if (actionDispenser instanceof ActivitiesAware) {
((ActivitiesAware) actionDispenser).setActivitiesMap(activities);
}
activity.setActionDispenserDelegate(actionDispenser);
OutputDispenser outputDispenser = getOutputDispenser(activity).orElse(null);
if (outputDispenser != null && outputDispenser instanceof ActivitiesAware) {
((ActivitiesAware) outputDispenser).setActivitiesMap(activities);
}
activity.setOutputDispenserDelegate(outputDispenser);
MotorDispenser motorDispenser = getMotorDispenser(activity, inputDispenser, actionDispenser, outputDispenser);
if (motorDispenser instanceof ActivitiesAware) {
((ActivitiesAware) motorDispenser).setActivitiesMap(activities);
}
activity.setMotorDispenserDelegate(motorDispenser);
return activity;
}
Aggregations