-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
86f7a0b
commit bff7711
Showing
7 changed files
with
200 additions
and
2 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
...-execution/src/main/java/com/fluxtion/example/reference/libraryfunction/AuditExample.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...le/reference/execution/BufferTrigger.java → ...erence/libraryfunction/BufferTrigger.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
...-execution/src/main/java/com/fluxtion/example/reference/libraryfunction/ClockExample.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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")); | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
...ution/src/main/java/com/fluxtion/example/reference/libraryfunction/ContextParamInput.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
...rc/main/java/com/fluxtion/example/reference/libraryfunction/DirtyStateMonitorExample.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<Integer> intDataFlow; | ||
|
||
public TriggeredChild(FlowSupplier<Integer> 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(); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
...src/main/java/com/fluxtion/example/reference/libraryfunction/FixedRateTriggerExample.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...ample/reference/execution/OutputSink.java → ...reference/libraryfunction/OutputSink.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters