swimos / cookbook

Cookbook code snippets, gathered into runnable Gradle projects.
Apache License 2.0
16 stars 8 forks source link

Cookbook to illustrate server.recon for Web Agents. #21

Closed AdityaRandive closed 2 years ago

AdityaRandive commented 2 years ago

This commit includes code to illustrate the utilization of server.recon configuration file for defining web agents. Also, illustrates the use of declaring and reading properties with different data-types.

Author: Aditya R Reviewers: Ajay G, Rohit B Test: Manual Issue: https://github.com/swimos/cookbook/issues/20

ajay-gov commented 2 years ago

@AdityaRandive looks good. Couple of suggestions

  1. Let's keep the web_agents cookbook as is for now. You can move your code under a new top-leve folder under cookbook and call it web_agents_server_recon

  2. The validation of whether the property passed in matches the type is useful but not relevant for this cookbook. It will be simpler if all the agents have one string prpoerty, one boolean property, one integer and one floatr property with different values. That should suffice. Also it will be good to fallback to defaults in the code if the prop is not defined. Eg , you can do something like this:

    final float propFloatValue = getProp("propFloat").floatValue(0.0f);
    final boolean propBooleanValue =  getProp("propBool").booleanValue(false);
    final String propStringValue =  getProp("propString").stringValue("");
  3. You have node definitions with uris, it will be good to show agent definitions with uri patterns as well. So the server .recon will look something like this:

    @node {
        uri: "/unit/1"
        @agent(class: "swim.basic.UnitAgent") {
            propString: "p1"
            propInt: 1
           propFloat: 1.1
            propBool: true
        }
    }
    @node {
        uri: "/unit/2"
        @agent(class: "swim.basic.UnitAgent") {
            propString: "pfoo"
            propInt: 2
           propFloat: 2.2
            propBool: true
    
        }
    }
    @node {
        uri: "/unit/:id"
        @agent(class: "swim.basic.UnitAgent") {
            propString: "defaultProp"
            propInt: 9
           propFloat: 9.9
            propBool: false
        }
    }

    This is useful to show since the agents with the uris i.e (/unit/1 and unit/2) will get instantiated by the swim runtime automatically when the server starts up. The agents that are started from the BasicPlane using space.command("/unit/foo", "unusedForNow", Value.absent()); will get initialized using the properties in the properties defined under the /unit/:id section in the server.recon file

ajay-gov commented 2 years ago

Looks good!

Super minor changes

Once you make these changes, please merge them to master and remove this branch