Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Join Value Lane creates duplicate didSet callbacks #68

Open
DobromirM opened this issue Oct 1, 2021 · 1 comment
Open

Join Value Lane creates duplicate didSet callbacks #68

DobromirM opened this issue Oct 1, 2021 · 1 comment
Labels
C-bug Category: bug

Comments

@DobromirM
Copy link
Member

Similar to #67 but with a slightly different output, potentially due to #65.

Example:

BasicPlane.java

public class BasicPlane extends AbstractPlane {


  @SwimRoute("/swim")
  AgentRoute<UnitAgent> unitAgentType;

  public static void main(String[] args) {
    final Kernel kernel = ServerLoader.loadServer();
    final ActorSpace space = (ActorSpace) kernel.getSpace("basic");

    kernel.start();
    System.out.println("Running Basic server...");
    kernel.run();

    space.command("/swim", "wakeup", Value.absent());
  }
}

UnitAgent.java

public class UnitAgent extends AbstractAgent {

  @SwimLane("people")
  ValueLane<Integer> people = this.valueLane();

  @SwimLane("addPeople")
  CommandLane<Integer> addPeople = this.<Integer>commandLane().onCommand(msg -> {
    this.people.set(this.people.get() + msg);
  });

  @SwimLane("join")
  JoinValueLane<Integer, Integer> join = this.<Integer, Integer>joinValueLane().didUpdate((Integer key, Integer newValue, Integer oldValue) -> {
    System.out.println("The people in room " + key + " are " + newValue + " from " + oldValue);
  });

  @Override
  public void didStart() {
    join.downlink(1).nodeUri("/swim").laneUri("people").open().didSet((newValue, oldValue) -> {
      System.out.println("people changed to " + newValue + " from " + oldValue);
    });
  }
}

Input

@command(node:"/swim", lane:"addPeople")5

Output

The people in room 1 are 0 from 0
people changed to 0 from 0
The people in room 1 are 0 from 0
The people in room 1 are 5 from 0
people changed to 5 from 5
The people in room 1 are 5 from 5

The first three messages are from the initial value and the next three are from the command.

@DobromirM DobromirM added the C-bug Category: bug label Oct 1, 2021
@DobromirM
Copy link
Member Author

Possible duplicate or related to #16

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: bug
Projects
None yet
Development

No branches or pull requests

1 participant