-
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
8480b6e
commit 7439209
Showing
6 changed files
with
164 additions
and
8 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
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
42 changes: 42 additions & 0 deletions
42
...es/integration/src/main/java/com/fluxtion/example/reference/integration/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,42 @@ | ||
package com.fluxtion.example.reference.integration; | ||
|
||
import com.fluxtion.compiler.Fluxtion; | ||
import com.fluxtion.runtime.annotations.OnEventHandler; | ||
import com.fluxtion.runtime.time.Clock; | ||
|
||
import java.text.DateFormat; | ||
import java.util.Date; | ||
import java.util.concurrent.atomic.LongAdder; | ||
|
||
public class ClockExample { | ||
|
||
public static void main(String[] args) { | ||
var processor = Fluxtion.interpret(new TimeLogger()); | ||
processor.init(); | ||
//PRINT CURRENT TIME | ||
processor.onEvent(DateFormat.getDateTimeInstance()); | ||
|
||
//USE A SYNTHETIC STRATEGY TO SET TIME FOR THE PROCESSOR CLOCK | ||
LongAdder syntheticTime = new LongAdder(); | ||
processor.setClockStrategy(syntheticTime::longValue); | ||
|
||
//SET A NEW TIME - GOING BACK IN TIME!! | ||
syntheticTime.add(1_000_000_000); | ||
processor.onEvent(DateFormat.getDateTimeInstance()); | ||
|
||
//SET A NEW TIME - BACK TO THE FUTURE | ||
syntheticTime.add(1_800_000_000_000L); | ||
processor.onEvent(DateFormat.getDateTimeInstance()); | ||
} | ||
|
||
|
||
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; | ||
} | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
...tegration/src/main/java/com/fluxtion/example/reference/integration/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 |
---|---|---|
@@ -1,4 +1,32 @@ | ||
package com.fluxtion.example.reference.integration; | ||
|
||
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 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(); | ||
} | ||
|
||
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(); | ||
} | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
...tion/src/main/java/com/fluxtion/example/reference/integration/GetFlowNodeByIdExample.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.integration; | ||
|
||
import com.fluxtion.compiler.Fluxtion; | ||
import com.fluxtion.compiler.builder.dataflow.DataFlow; | ||
import com.fluxtion.runtime.annotations.OnEventHandler; | ||
import com.fluxtion.runtime.dataflow.helpers.Mappers; | ||
import com.fluxtion.runtime.node.NamedNode; | ||
import lombok.Data; | ||
|
||
public class GetFlowNodeByIdExample { | ||
public static void main(String[] args) throws NoSuchFieldException { | ||
var processor = Fluxtion.interpret(c ->{ | ||
DataFlow.subscribe(String.class) | ||
.filter(s -> s.equalsIgnoreCase("monday")) | ||
.mapToInt(Mappers.count()) | ||
.id("MondayChecker")//this makes the wrapped value accessible via the id | ||
.console("Monday is triggered"); | ||
}); | ||
processor.init(); | ||
|
||
processor.onEvent("Monday"); | ||
processor.onEvent("Tuesday"); | ||
processor.onEvent("Wednesday"); | ||
|
||
//ACCESS THE WRAPPED VALUE BY ITS ID | ||
Integer mondayCheckerCount = processor.getStreamed("MondayChecker"); | ||
System.out.println("Monday count:" + mondayCheckerCount + "\n"); | ||
|
||
//ACCESS THE WRAPPED VALUE BY ITS ID | ||
processor.onEvent("Monday"); | ||
mondayCheckerCount = processor.getStreamed("MondayChecker"); | ||
System.out.println("Monday count:" + mondayCheckerCount); | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
...egration/src/main/java/com/fluxtion/example/reference/integration/GetNodeByIdExample.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,48 @@ | ||
package com.fluxtion.example.reference.integration; | ||
|
||
import com.fluxtion.compiler.Fluxtion; | ||
import com.fluxtion.compiler.builder.dataflow.DataFlow; | ||
import com.fluxtion.runtime.annotations.OnEventHandler; | ||
import com.fluxtion.runtime.node.NamedNode; | ||
|
||
public class GetNodeByIdExample { | ||
public static void main(String[] args) throws NoSuchFieldException { | ||
var processor = Fluxtion.interpret(c ->{ | ||
DataFlow.subscribeToNode(new DirtyStateNode()) | ||
.console("Monday is triggered"); | ||
}); | ||
processor.init(); | ||
|
||
processor.onEvent("Monday"); | ||
processor.onEvent("Tuesday"); | ||
processor.onEvent("Wednesday"); | ||
|
||
DirtyStateNode dirtyStateNode = processor.getNodeById("MondayChecker"); | ||
System.out.println("Monday count:" + dirtyStateNode.getMondayCount() + "\n"); | ||
|
||
|
||
processor.onEvent("Monday"); | ||
System.out.println("Monday count:" + dirtyStateNode.getMondayCount()); | ||
} | ||
|
||
public static class DirtyStateNode implements NamedNode { | ||
|
||
private int mondayCounter = 0; | ||
|
||
@OnEventHandler | ||
public boolean checkIsMonday(String day){ | ||
boolean isMonday = day.equalsIgnoreCase("monday"); | ||
mondayCounter += isMonday ? 1 : 0; | ||
return isMonday; | ||
} | ||
|
||
public int getMondayCount() { | ||
return mondayCounter; | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return "MondayChecker"; | ||
} | ||
} | ||
} |