-
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
735e16d
commit afd46a3
Showing
6 changed files
with
268 additions
and
1 deletion.
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
...time-execution/src/main/java/com/fluxtion/example/reference/execution/BatchCallbacks.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.execution; | ||
|
||
import com.fluxtion.compiler.Fluxtion; | ||
import com.fluxtion.runtime.annotations.OnBatchEnd; | ||
import com.fluxtion.runtime.annotations.OnBatchPause; | ||
import com.fluxtion.runtime.annotations.OnEventHandler; | ||
import com.fluxtion.runtime.lifecycle.BatchHandler; | ||
|
||
public class BatchCallbacks { | ||
|
||
public static class MyNode { | ||
@OnEventHandler | ||
public boolean handleStringEvent(String stringToProcess) { | ||
System.out.println("MyNode event received:" + stringToProcess); | ||
return true; | ||
} | ||
|
||
@OnBatchPause | ||
public void batchPause(){ | ||
System.out.println("MyNode::batchPause"); | ||
} | ||
|
||
@OnBatchEnd | ||
public void batchEnd(){ | ||
System.out.println("MyNode::batchEnd"); | ||
} | ||
} | ||
|
||
public static void main(String[] args) { | ||
var processor = Fluxtion.interpret(new MyNode()); | ||
processor.init(); | ||
|
||
processor.onEvent("test"); | ||
|
||
//use BatchHandler service | ||
BatchHandler batchHandler = (BatchHandler)processor; | ||
batchHandler.batchPause(); | ||
batchHandler.batchEnd(); | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
...me-execution/src/main/java/com/fluxtion/example/reference/execution/ExportingService.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,52 @@ | ||
package com.fluxtion.example.reference.execution; | ||
|
||
import com.fluxtion.compiler.Fluxtion; | ||
import com.fluxtion.runtime.annotations.ExportService; | ||
import com.fluxtion.runtime.annotations.OnTrigger; | ||
|
||
import java.util.function.IntSupplier; | ||
|
||
public class ExportingService { | ||
public interface MyService { | ||
void addNumbers(int a, int b); | ||
} | ||
|
||
public static class MyServiceImpl implements @ExportService MyService, IntSupplier { | ||
|
||
private int sum; | ||
|
||
@Override | ||
public void addNumbers(int a, int b) { | ||
System.out.printf("adding %d + %d %n", a, b); | ||
sum = a + b; | ||
} | ||
|
||
@Override | ||
public int getAsInt() { | ||
return sum; | ||
} | ||
} | ||
|
||
public static class ResultPublisher { | ||
private final IntSupplier intSupplier; | ||
|
||
public ResultPublisher(IntSupplier intSupplier) { | ||
this.intSupplier = intSupplier; | ||
} | ||
|
||
@OnTrigger | ||
public boolean printResult() { | ||
System.out.println("result - " + intSupplier.getAsInt()); | ||
return true; | ||
} | ||
} | ||
|
||
public static void main(String[] args) { | ||
var processor = Fluxtion.interpret(new ResultPublisher(new MyServiceImpl())); | ||
processor.init(); | ||
|
||
//get the exported service | ||
MyService myService = processor.getExportedService(); | ||
myService.addNumbers(30, 12); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
...time-execution/src/main/java/com/fluxtion/example/reference/execution/FilterVariable.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,35 @@ | ||
package com.fluxtion.example.reference.execution; | ||
|
||
import com.fluxtion.compiler.Fluxtion; | ||
import com.fluxtion.runtime.annotations.FilterId; | ||
import com.fluxtion.runtime.annotations.OnEventHandler; | ||
import com.fluxtion.runtime.annotations.OnParentUpdate; | ||
import com.fluxtion.runtime.annotations.OnTrigger; | ||
import com.fluxtion.runtime.event.Signal; | ||
|
||
public class FilterVariable { | ||
|
||
public static class MyNode { | ||
private final String name; | ||
|
||
public MyNode(String name) { | ||
this.name = name; | ||
} | ||
|
||
|
||
@OnEventHandler(filterVariable = "name") | ||
public boolean handleIntSignal(Signal.IntSignal intSignal) { | ||
System.out.printf("MyNode-%s::handleIntSignal - %s%n", name, intSignal.getValue()); | ||
return true; | ||
} | ||
} | ||
|
||
public static void main(String[] args) { | ||
var processor = Fluxtion.interpret(new MyNode("A"), new MyNode("B")); | ||
processor.init(); | ||
|
||
processor.publishIntSignal("A", 22); | ||
processor.publishIntSignal("B", 45); | ||
processor.publishIntSignal("C", 100); | ||
} | ||
} |
76 changes: 76 additions & 0 deletions
76
...time-execution/src/main/java/com/fluxtion/example/reference/execution/ForkingTrigger.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,76 @@ | ||
package com.fluxtion.example.reference.execution; | ||
|
||
import com.fluxtion.compiler.Fluxtion; | ||
import com.fluxtion.runtime.annotations.OnEventHandler; | ||
import com.fluxtion.runtime.annotations.OnTrigger; | ||
|
||
import java.time.Duration; | ||
import java.time.Instant; | ||
import java.util.Random; | ||
|
||
public class ForkingTrigger { | ||
|
||
public static class MyNode { | ||
@OnEventHandler | ||
public boolean handleStringEvent(String stringToProcess) { | ||
System.out.printf("%s MyNode::handleStringEvent %n", Thread.currentThread().getName()); | ||
return true; | ||
} | ||
} | ||
|
||
public static class ForkedChild { | ||
private final MyNode myNode; | ||
private final int id; | ||
|
||
public ForkedChild(MyNode myNode, int id) { | ||
this.myNode = myNode; | ||
this.id = id; | ||
} | ||
|
||
@OnTrigger(parallelExecution = true) | ||
public boolean triggered() { | ||
int millisSleep = new Random(id).nextInt(25, 200); | ||
String threadName = Thread.currentThread().getName(); | ||
System.out.printf("%s ForkedChild[%d]::triggered - sleep:%d %n", threadName, id, millisSleep); | ||
try { | ||
Thread.sleep(millisSleep); | ||
} catch (InterruptedException e) { | ||
throw new RuntimeException(e); | ||
} | ||
System.out.printf("%s ForkedChild[%d]::complete %n", threadName, id); | ||
return true; | ||
} | ||
} | ||
|
||
public static class ResultJoiner { | ||
private final ForkedChild[] forkedTasks; | ||
|
||
public ResultJoiner(ForkedChild[] forkedTasks) { | ||
this.forkedTasks = forkedTasks; | ||
} | ||
|
||
public ResultJoiner(int forkTaskNumber){ | ||
MyNode myNode = new MyNode(); | ||
forkedTasks = new ForkedChild[forkTaskNumber]; | ||
for (int i = 0; i < forkTaskNumber; i++) { | ||
forkedTasks[i] = new ForkedChild(myNode, i); | ||
} | ||
} | ||
|
||
@OnTrigger | ||
public boolean complete(){ | ||
System.out.printf("%s ResultJoiner:complete %n%n", Thread.currentThread().getName()); | ||
return true; | ||
} | ||
} | ||
|
||
public static void main(String[] args) { | ||
var processor = Fluxtion.interpret(new ResultJoiner(5)); | ||
processor.init(); | ||
|
||
Instant start = Instant.now(); | ||
processor.onEvent("test"); | ||
|
||
System.out.printf("duration: %d milliseconds%n", Duration.between(start, Instant.now()).toMillis()); | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
...ion/src/main/java/com/fluxtion/example/reference/execution/NopPropagateServiceMethod.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,65 @@ | ||
package com.fluxtion.example.reference.execution; | ||
|
||
import com.fluxtion.compiler.Fluxtion; | ||
import com.fluxtion.runtime.annotations.ExportService; | ||
import com.fluxtion.runtime.annotations.NoPropagateFunction; | ||
import com.fluxtion.runtime.annotations.OnTrigger; | ||
|
||
import java.util.function.IntSupplier; | ||
|
||
public class NopPropagateServiceMethod { | ||
public interface MyService { | ||
void cumulativeSum(int a); | ||
void reset(); | ||
} | ||
|
||
public static class MyServiceImpl implements @ExportService MyService, IntSupplier { | ||
|
||
private int sum; | ||
|
||
@Override | ||
public void cumulativeSum(int a) { | ||
sum += a; | ||
System.out.printf("MyServiceImpl::adding %d cumSum: %d %n", a, sum); | ||
} | ||
|
||
@Override | ||
@NoPropagateFunction | ||
public void reset() { | ||
sum = 0; | ||
System.out.printf("MyServiceImpl::reset cumSum: %d %n", sum); | ||
} | ||
|
||
@Override | ||
public int getAsInt() { | ||
return sum; | ||
} | ||
} | ||
|
||
public static class ResultPublisher { | ||
private final IntSupplier intSupplier; | ||
|
||
public ResultPublisher(IntSupplier intSupplier) { | ||
this.intSupplier = intSupplier; | ||
} | ||
|
||
@OnTrigger | ||
public boolean printResult() { | ||
System.out.println("ResultPublisher::result - " + intSupplier.getAsInt()); | ||
return true; | ||
} | ||
} | ||
|
||
public static void main(String[] args) { | ||
var processor = Fluxtion.interpret(new ResultPublisher(new MyServiceImpl())); | ||
processor.init(); | ||
|
||
//get the exported service | ||
MyService myService = processor.getExportedService(); | ||
myService.cumulativeSum(11); | ||
myService.cumulativeSum(31); | ||
System.out.println(); | ||
|
||
myService.reset(); | ||
} | ||
} |
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