Search in sources :

Example 1 with OutputDispenser

use of io.engineblock.activityapi.output.OutputDispenser 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);
}
Also used : TargetRateInput(io.engineblock.activityimpl.input.TargetRateInput) SimpleActivity(io.engineblock.activityimpl.SimpleActivity) CoreInputDispenser(io.engineblock.activityimpl.input.CoreInputDispenser) ActivityDef(io.engineblock.activityimpl.ActivityDef) CoreMotorDispenser(io.engineblock.activityimpl.motor.CoreMotorDispenser) CoreInputDispenser(io.engineblock.activityimpl.input.CoreInputDispenser) InputDispenser(io.engineblock.activityapi.input.InputDispenser) CoreActionDispenser(io.engineblock.activityimpl.action.CoreActionDispenser) TargetRateInput(io.engineblock.activityimpl.input.TargetRateInput) Input(io.engineblock.activityapi.input.Input) SimpleActivity(io.engineblock.activityimpl.SimpleActivity) CoreMotorDispenser(io.engineblock.activityimpl.motor.CoreMotorDispenser) CoreActionDispenser(io.engineblock.activityimpl.action.CoreActionDispenser) OutputDispenser(io.engineblock.activityapi.output.OutputDispenser) Test(org.testng.annotations.Test)

Example 2 with OutputDispenser

use of io.engineblock.activityapi.output.OutputDispenser 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();
}
Also used : SimpleActivity(io.engineblock.activityimpl.SimpleActivity) CoreInputDispenser(io.engineblock.activityimpl.input.CoreInputDispenser) ActivityDef(io.engineblock.activityimpl.ActivityDef) CoreMotorDispenser(io.engineblock.activityimpl.motor.CoreMotorDispenser) CoreInputDispenser(io.engineblock.activityimpl.input.CoreInputDispenser) InputDispenser(io.engineblock.activityapi.input.InputDispenser) CoreActionDispenser(io.engineblock.activityimpl.action.CoreActionDispenser) CoreActionDispenser(io.engineblock.activityimpl.action.CoreActionDispenser) CoreMotorDispenser(io.engineblock.activityimpl.motor.CoreMotorDispenser) OutputDispenser(io.engineblock.activityapi.output.OutputDispenser) Test(org.testng.annotations.Test)

Example 3 with OutputDispenser

use of io.engineblock.activityapi.output.OutputDispenser 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;
}
Also used : CoreActionDispenser(io.engineblock.activityimpl.action.CoreActionDispenser) CoreMotorDispenser(io.engineblock.activityimpl.motor.CoreMotorDispenser) OutputDispenser(io.engineblock.activityapi.output.OutputDispenser) InputDispenser(io.engineblock.activityapi.input.InputDispenser)

Example 4 with OutputDispenser

use of io.engineblock.activityapi.output.OutputDispenser in project engineblock by engineblock.

the class CoreServices method getOutputDispenser.

public static <A extends Activity> Optional<OutputDispenser> getOutputDispenser(A activity) {
    OutputDispenser outputDispenser = new SimpleConfig(activity, "output").getString("type").flatMap(OutputType.FINDER::get).map(mt -> mt.getOutputDispenser(activity)).orElse(null);
    if (outputDispenser == null) {
        return Optional.empty();
    }
    Optional<Predicate<ResultReadable>> outputFilterDispenser = getOutputFilter(activity);
    if (outputFilterDispenser.isPresent()) {
        outputDispenser = new FilteringOutputDispenser(outputDispenser, outputFilterDispenser.get());
    }
    return Optional.ofNullable(outputDispenser);
}
Also used : SimpleConfig(io.engineblock.util.SimpleConfig) InputType(io.engineblock.activityapi.input.InputType) Activity(io.engineblock.activityapi.core.Activity) ResultValueFilterType(io.engineblock.activityapi.cyclelog.filters.ResultValueFilterType) OutputType(io.engineblock.activityapi.output.OutputType) Predicate(java.util.function.Predicate) OutputDispenser(io.engineblock.activityapi.output.OutputDispenser) SimpleConfig(io.engineblock.util.SimpleConfig) Optional(java.util.Optional) ResultReadable(io.engineblock.activityapi.cyclelog.buffers.results.ResultReadable) ResultFilterDispenser(io.engineblock.activityapi.cyclelog.filters.ResultFilterDispenser) InputDispenser(io.engineblock.activityapi.input.InputDispenser) OutputDispenser(io.engineblock.activityapi.output.OutputDispenser) Predicate(java.util.function.Predicate)

Aggregations

InputDispenser (io.engineblock.activityapi.input.InputDispenser)4 OutputDispenser (io.engineblock.activityapi.output.OutputDispenser)4 CoreActionDispenser (io.engineblock.activityimpl.action.CoreActionDispenser)3 CoreMotorDispenser (io.engineblock.activityimpl.motor.CoreMotorDispenser)3 ActivityDef (io.engineblock.activityimpl.ActivityDef)2 SimpleActivity (io.engineblock.activityimpl.SimpleActivity)2 CoreInputDispenser (io.engineblock.activityimpl.input.CoreInputDispenser)2 Test (org.testng.annotations.Test)2 Activity (io.engineblock.activityapi.core.Activity)1 ResultReadable (io.engineblock.activityapi.cyclelog.buffers.results.ResultReadable)1 ResultFilterDispenser (io.engineblock.activityapi.cyclelog.filters.ResultFilterDispenser)1 ResultValueFilterType (io.engineblock.activityapi.cyclelog.filters.ResultValueFilterType)1 Input (io.engineblock.activityapi.input.Input)1 InputType (io.engineblock.activityapi.input.InputType)1 OutputType (io.engineblock.activityapi.output.OutputType)1 TargetRateInput (io.engineblock.activityimpl.input.TargetRateInput)1 SimpleConfig (io.engineblock.util.SimpleConfig)1 Optional (java.util.Optional)1 Predicate (java.util.function.Predicate)1