-
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.
add aot helloworld, change original helloworld to be interpreted
- Loading branch information
1 parent
8d9f303
commit 86ffe70
Showing
13 changed files
with
193 additions
and
22 deletions.
There are no files selected for viewing
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 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>com.fluxtion.example</groupId> | ||
<artifactId>example.master</artifactId> | ||
<version>1.0.0-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>imperative-helloworld-aot</artifactId> | ||
<name>imperative :: hello world - AOT</name> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>com.fluxtion</groupId> | ||
<artifactId>fluxtion-maven-plugin</artifactId> | ||
<version>3.0.14</version> | ||
<executions> | ||
<execution> | ||
<goals> | ||
<goal>scan</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
</project> |
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
24 changes: 24 additions & 0 deletions
24
...lloworld-aot/src/main/java/com/fluxtion/example/imperative/helloworld/BreachNotifier.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,24 @@ | ||
package com.fluxtion.example.imperative.helloworld; | ||
|
||
import com.fluxtion.runtime.annotations.OnTrigger; | ||
|
||
/** | ||
* The trigger method, printWarning on this class is invoked when a change is propagated from the parent node | ||
*/ | ||
public class BreachNotifier { | ||
private final DataSumCalculator dataAddition; | ||
|
||
public BreachNotifier(DataSumCalculator dataAddition) { | ||
this.dataAddition = dataAddition; | ||
} | ||
|
||
public BreachNotifier() { | ||
this(new DataSumCalculator()); | ||
} | ||
|
||
@OnTrigger | ||
public boolean printWarning() { | ||
System.out.println("WARNING DataSumCalculator value is greater than 100 sum = " + dataAddition.getSum()); | ||
return true; | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
...world-aot/src/main/java/com/fluxtion/example/imperative/helloworld/DataSumCalculator.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,38 @@ | ||
package com.fluxtion.example.imperative.helloworld; | ||
|
||
import com.fluxtion.runtime.annotations.OnTrigger; | ||
import lombok.Getter; | ||
|
||
/** | ||
* Aggregates two event sources and calculates the sum of their values, whenever either changes. The calculate method | ||
* notifies a propagation of a change when the sum is > 100 | ||
*/ | ||
public class DataSumCalculator { | ||
|
||
private final Event_A_Handler eventAHandler; | ||
private final Event_B_Handler eventBHandler; | ||
@Getter | ||
private double sum; | ||
|
||
public DataSumCalculator(Event_A_Handler eventAHandler, Event_B_Handler eventBHandler) { | ||
this.eventAHandler = eventAHandler; | ||
this.eventBHandler = eventBHandler; | ||
} | ||
|
||
public DataSumCalculator() { | ||
this(new Event_A_Handler(), new Event_B_Handler()); | ||
} | ||
|
||
/** | ||
* The {@link OnTrigger} annotation marks this method to be called if any parents have changed | ||
* | ||
* @return flag indicating a change and a propagation of the event wave to child dependencies if the sum > 100 | ||
*/ | ||
@OnTrigger | ||
public boolean calculate() { | ||
sum = eventAHandler.getValue() + eventBHandler.getValue(); | ||
System.out.println("sum:" + sum); | ||
return sum > 100; | ||
} | ||
|
||
} |
4 changes: 4 additions & 0 deletions
4
...tive-helloworld-aot/src/main/java/com/fluxtion/example/imperative/helloworld/Event_A.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,4 @@ | ||
package com.fluxtion.example.imperative.helloworld; | ||
|
||
public record Event_A(double value) { | ||
} |
28 changes: 28 additions & 0 deletions
28
...loworld-aot/src/main/java/com/fluxtion/example/imperative/helloworld/Event_A_Handler.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,28 @@ | ||
package com.fluxtion.example.imperative.helloworld; | ||
|
||
import com.fluxtion.runtime.annotations.OnEventHandler; | ||
import lombok.Getter; | ||
|
||
/** | ||
* An entry point to {@link com.fluxtion.runtime.EventProcessor} for {@link Event_A} events. The {@link OnEventHandler} | ||
* defines a method as an entry point. | ||
* | ||
*/ | ||
@Getter | ||
public class Event_A_Handler { | ||
private double value; | ||
|
||
/** | ||
* The {@link OnEventHandler} annotation marks this method as the start of an execution path with a {@link Event_A}. | ||
* Invoked when the {@link com.fluxtion.runtime.EventProcessor} receives a {@link Event_A} event. | ||
* | ||
* @param eventA the input event | ||
* @return flag indicating a change and a propagation of the event wave to child dependencies | ||
*/ | ||
@OnEventHandler | ||
public boolean data1Update(Event_A eventA) { | ||
value = eventA.value(); | ||
return true; | ||
} | ||
|
||
} |
4 changes: 4 additions & 0 deletions
4
...tive-helloworld-aot/src/main/java/com/fluxtion/example/imperative/helloworld/Event_B.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,4 @@ | ||
package com.fluxtion.example.imperative.helloworld; | ||
|
||
public record Event_B(double value) { | ||
} |
28 changes: 28 additions & 0 deletions
28
...loworld-aot/src/main/java/com/fluxtion/example/imperative/helloworld/Event_B_Handler.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,28 @@ | ||
package com.fluxtion.example.imperative.helloworld; | ||
|
||
import com.fluxtion.runtime.annotations.OnEventHandler; | ||
import lombok.Getter; | ||
|
||
/** | ||
* An entry point to {@link com.fluxtion.runtime.EventProcessor} for {@link Event_B} events. The {@link OnEventHandler} | ||
* defines a method as an entry point. | ||
* | ||
*/ | ||
@Getter | ||
public class Event_B_Handler { | ||
private double value; | ||
|
||
/** | ||
* The {@link OnEventHandler} annotation marks this method as the start of an execution path with a {@link Event_B}. | ||
* Invoked when the {@link com.fluxtion.runtime.EventProcessor} receives a {@link Event_B} event. | ||
* | ||
* @param eventB the input event | ||
* @return flag indicating a change and a propagation of the event wave to child dependencies | ||
*/ | ||
@OnEventHandler | ||
public boolean data1Update(Event_B eventB) { | ||
value = eventB.value(); | ||
return true; | ||
} | ||
|
||
} |
30 changes: 30 additions & 0 deletions
30
imperative-helloworld-aot/src/main/java/com/fluxtion/example/imperative/helloworld/Main.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,30 @@ | ||
package com.fluxtion.example.imperative.helloworld; | ||
|
||
import com.fluxtion.compiler.Fluxtion; | ||
import com.fluxtion.example.imperative.helloworld.generated.BreachNotifierProcessor; | ||
import com.fluxtion.runtime.annotations.OnEventHandler; | ||
import com.fluxtion.runtime.annotations.OnTrigger; | ||
|
||
|
||
/** | ||
* creates a processing graph imperatively, extracts double values from events, calculates the sum and prints a | ||
* message to console if the sum is greater than a 100. | ||
* <p> | ||
* Uses @{@link OnEventHandler} annotation to declare the entry point of an execution path | ||
* {@link OnTrigger} annotated methods indicate call back methods to be invoked if a parent propagates a change. | ||
* The return flag from the {@link OnTrigger} method indicates if the event should be propagated. In this case | ||
* the event is only propagated if the sum > 100. | ||
*/ | ||
public class Main { | ||
private static final boolean USE_AOT = true; | ||
|
||
public static void main(String[] args) { | ||
var eventProcessor = USE_AOT ? new BreachNotifierProcessor() : Fluxtion.interpret(new BreachNotifier()); | ||
eventProcessor.init(); | ||
eventProcessor.onEvent(new Event_A(34.4)); | ||
eventProcessor.onEvent(new Event_B(52.1)); | ||
eventProcessor.onEvent(new Event_A(105));//should create a breach warning | ||
eventProcessor.onEvent(new Event_A(12.4)); | ||
} | ||
|
||
} |
File renamed without changes.
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
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
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