Skip to content
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
66 lines (53 sloc) 1.58 KB

Example - Class based Function Script


package examples;

import com.mackenziehigh.cascade.Cascade;
import com.mackenziehigh.cascade.Cascade.Stage;
import com.mackenziehigh.cascade.Cascade.Stage.Actor;

public final class Example
    public static void main (String[] args)
        final Example main = new Example();

    private void demo ()
        // Create a single-threaded stage.
        final Stage stage = Cascade.newStage();

        // Create the actor that is being demonstrated.
        final Actor<Integer, Double> actor = stage
                .withFunctionScript(new CustomScript())

        // Create an actor that merely prints the messages
        // that the previous actor produced.
        final Actor<Double, Double> printer = stage
                .withConsumerScript((Double msg) -> System.out.println("sqrt = " + msg))

        // Connect the actors to form a pipeline.

        // Send a message through the pipeline.

     * An instance of this script defines how the actor will behave.
    private static final class CustomScript
            implements Actor.FunctionScript<Integer, Double>
        public Double onInput (final Integer input)
                throws Throwable
            return Math.sqrt(input);


sqrt = 4.123105625617661
You can’t perform that action at this time.