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

Integer ValueLane can be set with Text. #40

Open
DobromirM opened this issue Dec 16, 2019 · 3 comments
Open

Integer ValueLane can be set with Text. #40

DobromirM opened this issue Dec 16, 2019 · 3 comments
Labels
C-bug Category: bug

Comments

@DobromirM
Copy link
Member

It is possible to set an Integer Value Lane ValueLane<Integer> with a Text object. The lane will work fine in terms of setting the value and sending it to all downlinks, however the new and old value for .didSet() method will always be zero (the default).

@DobromirM DobromirM added the C-bug Category: bug label Dec 16, 2019
@DobromirM
Copy link
Member Author

Example:

Plane.java

public class Plane extends AbstractPlane {

  @SwimRoute ("/agent/:id")
  AgentRoute<Agent> agent;

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

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

    fabric.command("/agent/1", "wakeup", Value.absent());
  }
}

Agent.java

public class Agent extends AbstractAgent {

  @SwimLane ("age")
  ValueLane<Integer> age = this.<Integer>valueLane().didSet((newValue, oldValue) -> {
    System.out.println("`age` set to {" + newValue + "} from {" + oldValue + "}");
  });
}

Client.java

class Client {

    public static void main(String[] args) throws InterruptedException {
        ClientRuntime swimClient = new ClientRuntime();
        swimClient.start();
        final String hostUri = "warp://localhost:9001";
        final String nodeUri = "/agent/1";
        final ValueDownlink<Value> link = swimClient.downlinkValue().hostUri(hostUri).nodeUri(nodeUri).laneUri("age").didSet((newValue, oldValue) -> {
            System.out.println("link watched info change TO " + newValue + " FROM " + oldValue);
        }).open();

        Thread.sleep(2000);
        link.set(Text.from("twenty"));
        Thread.sleep(2000);
        System.out.println(link.get());
        Thread.sleep(2000);
        System.out.println("Will shut down client in 2 seconds");
        swimClient.stop();
    }
}

Client Output

link watched info change TO Value.absent() FROM Value.absent()
link watched info change TO Text.from("twenty") FROM Value.absent()
link watched info change TO Text.from("twenty") FROM Text.from("twenty")
Text.from("twenty")

Server Output

'age' set to {0} from {0}

@brohitbrose
Copy link
Member

Good find. As I mentioned in Slack, the server output is especially disturbing.

Regarding client-side, see here for something similar. Lane versioning is something that has come up recently for different reasons, so this may be solved soon after all. Will update after further discussion.

@ajay-gov
Copy link
Member

ajay-gov commented Jan 7, 2020

This is the code block responsible for this behavior:

The valueForm.cast(this.newValue) will return null since the valueForm in this case is the IntegerForm and it tries to cast a Text value to an Integer. Since it returns a null it defaults to valueForm.unit() which is 0 for the IntegerForm.

In general in these kinds of scenarios the return value is the form's unit value.

In terms of fixing it, we can use the unit value of the form when the cast fails. However, should we ignore this error silently or should we send an error back to the client with a failure? The latter will involve adding another callback function to the downlink lifecycle.

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

3 participants