diff --git a/reference-examples/runtime-execution/src/main/java/com/fluxtion/example/reference/libraryfunction/AuditExample.java b/reference-examples/runtime-execution/src/main/java/com/fluxtion/example/reference/libraryfunction/AuditExample.java new file mode 100644 index 0000000..36a2337 --- /dev/null +++ b/reference-examples/runtime-execution/src/main/java/com/fluxtion/example/reference/libraryfunction/AuditExample.java @@ -0,0 +1,33 @@ +package com.fluxtion.example.reference.libraryfunction; + +import com.fluxtion.compiler.Fluxtion; +import com.fluxtion.runtime.annotations.Initialise; +import com.fluxtion.runtime.annotations.OnEventHandler; +import com.fluxtion.runtime.audit.EventLogNode; + +public class AuditExample { + public static class MyAuditingNode extends EventLogNode { + + @Initialise + public void init(){ + auditLog.info("MyAuditingNode", "init"); + auditLog.info("MyAuditingNode_debug", "some debug message"); + } + + @OnEventHandler + public boolean stringEvent(String event) { + auditLog.info("event", event); + auditLog.debug("charCount", event.length()); + return true; + } + } + public static void main(String[] args) { + var processor = Fluxtion.interpret(c ->{ + c.addNode(new MyAuditingNode()); + c.addEventAudit(); + }); + processor.init(); + //AUDIT IS INFO BY DEFAULT + processor.onEvent("detailed message 1"); + } +} diff --git a/reference-examples/runtime-execution/src/main/java/com/fluxtion/example/reference/execution/BufferTrigger.java b/reference-examples/runtime-execution/src/main/java/com/fluxtion/example/reference/libraryfunction/BufferTrigger.java similarity index 97% rename from reference-examples/runtime-execution/src/main/java/com/fluxtion/example/reference/execution/BufferTrigger.java rename to reference-examples/runtime-execution/src/main/java/com/fluxtion/example/reference/libraryfunction/BufferTrigger.java index f2ba3fe..22829df 100644 --- a/reference-examples/runtime-execution/src/main/java/com/fluxtion/example/reference/execution/BufferTrigger.java +++ b/reference-examples/runtime-execution/src/main/java/com/fluxtion/example/reference/libraryfunction/BufferTrigger.java @@ -1,4 +1,4 @@ -package com.fluxtion.example.reference.execution; +package com.fluxtion.example.reference.libraryfunction; import com.fluxtion.compiler.Fluxtion; import com.fluxtion.runtime.annotations.OnEventHandler; diff --git a/reference-examples/runtime-execution/src/main/java/com/fluxtion/example/reference/libraryfunction/ClockExample.java b/reference-examples/runtime-execution/src/main/java/com/fluxtion/example/reference/libraryfunction/ClockExample.java new file mode 100644 index 0000000..3c3bdce --- /dev/null +++ b/reference-examples/runtime-execution/src/main/java/com/fluxtion/example/reference/libraryfunction/ClockExample.java @@ -0,0 +1,34 @@ +package com.fluxtion.example.reference.libraryfunction; + +import com.fluxtion.compiler.Fluxtion; +import com.fluxtion.runtime.annotations.OnEventHandler; +import com.fluxtion.runtime.time.Clock; + +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.concurrent.atomic.LongAdder; + +public class ClockExample { + + public static class TimeLogger { + public Clock wallClock = Clock.DEFAULT_CLOCK; + + @OnEventHandler + public boolean publishTime(DateFormat dateFormat) { + System.out.println("time " + dateFormat.format(new Date(wallClock.getWallClockTime()))); + return true; + } + } + + public static void main(String[] args) throws InterruptedException { + var processor = Fluxtion.interpret(new TimeLogger()); + processor.init(); + //PRINT CURRENT TIME + processor.onEvent(new SimpleDateFormat("HH:mm:ss.SSS")); + + //SLEEP AND PRINT TIME + Thread.sleep(100); + processor.onEvent(new SimpleDateFormat("HH:mm:ss.SSS")); + } +} diff --git a/reference-examples/runtime-execution/src/main/java/com/fluxtion/example/reference/libraryfunction/ContextParamInput.java b/reference-examples/runtime-execution/src/main/java/com/fluxtion/example/reference/libraryfunction/ContextParamInput.java new file mode 100644 index 0000000..dc9ee82 --- /dev/null +++ b/reference-examples/runtime-execution/src/main/java/com/fluxtion/example/reference/libraryfunction/ContextParamInput.java @@ -0,0 +1,32 @@ +package com.fluxtion.example.reference.libraryfunction; + +import com.fluxtion.compiler.Fluxtion; +import com.fluxtion.runtime.EventProcessorContext; +import com.fluxtion.runtime.annotations.Start; +import com.fluxtion.runtime.annotations.builder.Inject; + +public class ContextParamInput { + public static class ContextParamReader { + @Inject + public EventProcessorContext context; + + @Start + public void start() { + System.out.println("myContextParam1 -> " + context.getContextProperty("myContextParam1")); + System.out.println("myContextParam2 -> " + context.getContextProperty("myContextParam2")); + System.out.println(); + } + } + + public static void main(String[] args) { + var processor = Fluxtion.interpret(new ContextParamReader()); + processor.init(); + + processor.addContextParameter("myContextParam1", "[param1: update 1]"); + processor.start(); + + processor.addContextParameter("myContextParam1", "[param1: update 2]"); + processor.addContextParameter("myContextParam2", "[param2: update 1]"); + processor.start(); + } +} diff --git a/reference-examples/runtime-execution/src/main/java/com/fluxtion/example/reference/libraryfunction/DirtyStateMonitorExample.java b/reference-examples/runtime-execution/src/main/java/com/fluxtion/example/reference/libraryfunction/DirtyStateMonitorExample.java new file mode 100644 index 0000000..0ac55fc --- /dev/null +++ b/reference-examples/runtime-execution/src/main/java/com/fluxtion/example/reference/libraryfunction/DirtyStateMonitorExample.java @@ -0,0 +1,59 @@ +package com.fluxtion.example.reference.libraryfunction; + +import com.fluxtion.compiler.Fluxtion; +import com.fluxtion.compiler.builder.dataflow.DataFlow; +import com.fluxtion.runtime.annotations.OnTrigger; +import com.fluxtion.runtime.annotations.builder.Inject; +import com.fluxtion.runtime.callback.DirtyStateMonitor; +import com.fluxtion.runtime.dataflow.FlowSupplier; +import com.fluxtion.runtime.node.NamedNode; + +public class DirtyStateMonitorExample { + + public static class TriggeredChild implements NamedNode { + @Inject + public DirtyStateMonitor dirtyStateMonitor; + private final FlowSupplier intDataFlow; + + public TriggeredChild(FlowSupplier intDataFlow) { + this.intDataFlow = intDataFlow; + } + + @OnTrigger + public boolean triggeredChild() { + System.out.println("TriggeredChild -> " + intDataFlow.get()); + return true; + } + + public void printDirtyStat() { + System.out.println("\nintDataFlow dirtyState:" + dirtyStateMonitor.isDirty(intDataFlow)); + } + + public void markDirty() { + dirtyStateMonitor.markDirty(intDataFlow); + System.out.println("\nmark dirty intDataFlow dirtyState:" + dirtyStateMonitor.isDirty(intDataFlow)); + } + + @Override + public String getName() { + return "triggeredChild"; + } + } + + public static void main(String[] args) throws NoSuchFieldException { + var processor = Fluxtion.interpret(new TriggeredChild(DataFlow.subscribe(Integer.class).flowSupplier())); + processor.init(); + TriggeredChild triggeredChild = processor.getNodeById("triggeredChild"); + + processor.onEvent(2); + processor.onEvent(4); + + //NOTHING HAPPENS + triggeredChild.printDirtyStat(); + processor.triggerCalculation(); + + //MARK DIRTY + triggeredChild.markDirty(); + processor.triggerCalculation(); + } +} diff --git a/reference-examples/runtime-execution/src/main/java/com/fluxtion/example/reference/libraryfunction/FixedRateTriggerExample.java b/reference-examples/runtime-execution/src/main/java/com/fluxtion/example/reference/libraryfunction/FixedRateTriggerExample.java new file mode 100644 index 0000000..dba13df --- /dev/null +++ b/reference-examples/runtime-execution/src/main/java/com/fluxtion/example/reference/libraryfunction/FixedRateTriggerExample.java @@ -0,0 +1,40 @@ +package com.fluxtion.example.reference.libraryfunction; + +import com.fluxtion.compiler.Fluxtion; +import com.fluxtion.runtime.EventProcessor; +import com.fluxtion.runtime.annotations.OnTrigger; +import com.fluxtion.runtime.time.FixedRateTrigger; + +public class FixedRateTriggerExample { + public static class RegularTrigger { + + private final FixedRateTrigger fixedRateTrigger; + + public RegularTrigger(FixedRateTrigger fixedRateTrigger) { + this.fixedRateTrigger = fixedRateTrigger; + } + + public RegularTrigger(int sleepMilliseconds) { + fixedRateTrigger = new FixedRateTrigger(sleepMilliseconds); + } + + @OnTrigger + public boolean trigger() { + System.out.println("RegularTrigger::triggered"); + return true; + } + } + + public static void main(String... args) throws InterruptedException { + var processor = Fluxtion.interpret(new RegularTrigger(100)); + processor.init(); + + //NO TRIGGER - 10MS NEEDS TO ELAPSE + processor.onEvent(new Object()); + processor.onEvent("xxx"); + + //WILL TRIGGER - 10MS HAS ELAPSED + Thread.sleep(100); + processor.onEvent("xxx"); + } +} diff --git a/reference-examples/runtime-execution/src/main/java/com/fluxtion/example/reference/execution/OutputSink.java b/reference-examples/runtime-execution/src/main/java/com/fluxtion/example/reference/libraryfunction/OutputSink.java similarity index 91% rename from reference-examples/runtime-execution/src/main/java/com/fluxtion/example/reference/execution/OutputSink.java rename to reference-examples/runtime-execution/src/main/java/com/fluxtion/example/reference/libraryfunction/OutputSink.java index 369162e..3969123 100644 --- a/reference-examples/runtime-execution/src/main/java/com/fluxtion/example/reference/execution/OutputSink.java +++ b/reference-examples/runtime-execution/src/main/java/com/fluxtion/example/reference/libraryfunction/OutputSink.java @@ -1,4 +1,4 @@ -package com.fluxtion.example.reference.execution; +package com.fluxtion.example.reference.libraryfunction; import com.fluxtion.compiler.Fluxtion; import com.fluxtion.compiler.builder.dataflow.DataFlow;