use of io.engineblock.activityapi.input.Input 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.Input in project engineblock by engineblock.
the class ActivityExecutor method getProgress.
@Override
public synchronized double getProgress() {
ArrayList<Input> inputs = motors.stream().map(Motor::getInput).distinct().collect(Collectors.toCollection(ArrayList::new));
double startCycle = getActivityDef().getStartCycle();
double endCycle = getActivityDef().getEndCycle();
double totalCycles = endCycle - startCycle;
double total = 0.0D;
double progress = 0.0D;
for (Input input : inputs) {
if (input instanceof ProgressCapable) {
ProgressCapable progressInput = (ProgressCapable) input;
total += progressInput.getTotal();
progress += progressInput.getProgress();
} else {
logger.warn("input does not support activity progress: " + input);
return Double.NaN;
}
}
return progress / total;
}
use of io.engineblock.activityapi.input.Input 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.Input in project engineblock by engineblock.
the class CoreMotorDispenser method getMotor.
@Override
public Motor getMotor(ActivityDef activityDef, int slotId) {
Action action = actionDispenser.getAction(slotId);
Input input = inputDispenser.getInput(slotId);
Output output = null;
if (outputDispenser != null) {
output = outputDispenser.getOutput(slotId);
}
IntPredicate resultFilter = null;
Motor am = new CoreMotor(activity, slotId, input, action, output);
return am;
}
Aggregations