Skip to content

Commit

Permalink
added some binding examples
Browse files Browse the repository at this point in the history
  • Loading branch information
greg-higgins committed Mar 16, 2024
1 parent 856fc87 commit 897f726
Show file tree
Hide file tree
Showing 3 changed files with 164 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.fluxtion.example.reference;

import com.fluxtion.compiler.Fluxtion;
import com.fluxtion.runtime.annotations.OnEventHandler;
import com.fluxtion.runtime.node.NamedNode;

public class AddByName {

public static class MyNode {

private final String name;

public MyNode(String name) {
this.name = name;
}


public String getName() {
return name;
}
}

public static class MyNamedNode implements NamedNode {

private final String name;

public MyNamedNode(String name) {
this.name = name;
}

@Override
public String getName() {
return name;
}
}

public static void main(String[] args) throws NoSuchFieldException {
var processor = Fluxtion.interpret(cfg -> {
cfg.addNode(new MyNode("customName"), "overrideName");
cfg.addNode(new MyNamedNode("name1"));
});
processor.init();

System.out.println(processor.<MyNode>getNodeById("overrideName").getName());
System.out.println(processor.<MyNamedNode>getNodeById("name1").getName());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.fluxtion.example.reference;

import com.fluxtion.compiler.Fluxtion;
import com.fluxtion.runtime.annotations.OnEventHandler;
import com.fluxtion.runtime.annotations.OnTrigger;
import com.fluxtion.runtime.annotations.builder.Inject;

public class InjectNoFactory {
public static class MyNode {
@OnEventHandler
public boolean handleStringEvent(String stringToProcess) {
System.out.println("MyNode::received:" + stringToProcess);
return true;
}
}

public static class Root1 {
@Inject
private final MyNode myNode;

public Root1() {
myNode = null;
}

public Root1(MyNode myNode) {
this.myNode = myNode;
}

@OnTrigger
public boolean trigger() {
System.out.println("Root1::triggered");
return true;
}
}

public static void main(String[] args) {
var processor = Fluxtion.interpret(cfg -> cfg.addNode(new Root1()));
processor.init();
processor.onEvent("TEST");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package com.fluxtion.example.reference;

import com.fluxtion.compiler.Fluxtion;
import com.fluxtion.runtime.annotations.OnEventHandler;
import com.fluxtion.runtime.annotations.OnTrigger;

import java.util.Objects;

public class SharedEqualityReference {

public static class MyNode {
private final String name;
int identifier;

public MyNode(String name, int identifier) {
this.name = name;
this.identifier = identifier;
}

@OnEventHandler
public boolean handleStringEvent(String stringToProcess) {
System.out.println(name + " identifier:" + identifier + " received:" + stringToProcess);
return true;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
MyNode myNode = (MyNode) o;
return name.equals(myNode.name);
}

@Override
public int hashCode() {
return name.hashCode();
}

@Override
public String toString() {
return "MyNode{" +
"name='" + name + '\'' +
", identifier=" + identifier +
'}';
}
}

public static class Root1 {
private final String name;
private final MyNode myNode;

public Root1(String name, MyNode myNode) {
this.name = name;
this.myNode = myNode;
System.out.println(name + "::new " + myNode);
}

@OnTrigger
public boolean trigger() {
System.out.println(name + "::triggered " + myNode);
return true;
}
}

public static void main(String[] args) {
var processor = Fluxtion.interpret(cfg -> {
MyNode myNode1 = new MyNode("myNode_1", 999);
MyNode myNode2 = new MyNode("myNode_1", 444);
cfg.addNode(new Root1("root_1", myNode1));
cfg.addNode(new Root1("root_2", myNode2));
});
processor.init();
System.out.println();
processor.onEvent("TEST");
}
}

0 comments on commit 897f726

Please sign in to comment.