Record Generator

/site/assets/files/images/RecordGenerator.png

The RecordGenerator is a Swing tool, which generates JAVA auxiliary classes from message definitions (record.json and record.xml files). With these auxiliary classes it is easy to fill messages or read data from messages.

Message definitions can be defined in JSON and XML format. The record generator generates JAVA auxiliary classes from this, which allow messages to be read using getter methods and filled using setter methods.

Example of a record definition in JSON:

{
  "records": [
    {
      "id": "be125fa3-b4a7-493c-ad9a-5fa1a23be84d",
      "name": "NOTIFY_REMOTE_NODE_ADDED",
      "isService": "true",
      "namespaces": "SYSTEM",
      "description": "Notification that a remote node has been added.^It is now possible to send messages to the remote node.",
      "slots": [
        {
          "key": "1",
          "name": "REMOTE_NODE",
          "direction": "REQUEST",
          "mandatory": "true",
          "type": "NODE_ADDRESS",
          "description": "The remote node."
        },
        {
          "key": "2",
          "name": "TYPE",
          "direction": "REQUEST",
          "mandatory": "true",
          "type": "STRING",
          "description": "The type of the remote node, see ETypeOfNode."
        }
      ]
    }
  ]
}

Example of a record definition in XML:

<?xml version="1.0" encoding="ISO-8859-1"?>
    <records>
    <record id="92025e51-9a96-447b-bf06-29ba365b268b" name="ROUTE_MESSAGE" isService="true">

        <description>
            Send a Message via Router to the remote node.
        </description>

        <namespaces>SYSTEM</namespaces>

        <slot key="1" name="MESSAGE" answer="false" mandatory="true" type="MESSAGE">
            <description>The Message to send.</description>
        </slot>

    </record>

</records>

Usage

The tool needs two pieces of information for its work:

  • the prefix of the path where the sources are located (to determine the package), such as src or src/main/java.
  • the path to be searched along with subdirectories for files named record.json or record.xml.

Auxiliary classes are generated for all record definitions found. A single file can contain a large number of record definitions.

You can leave the tool open so that when you change a record definition, you can quickly generate new classes.

It is enough to specify a directory where all nyssr -based projects are located.

Why this cumbersome generator?

The nyssr.net messages consist of different slot types. The system can be expanded to include additional slot types. Therefore, a general class is not usable.

Slots (key-value pairs in a map in the record) come from slot factories. More slot factories can be installed.

Access to the slots always includes a JAVA type cast. Indeed, the correct access to slots is always checked. Thus, an attempt to read an integer from a slot containing a string is rewarded with an exception. However, it is simpler to access the data in a type-safe manner using a generated auxiliary class.

So we get a few conveniences in return:

  • Type-safe access to the data
  • A message API
  • A description of the message and the data
  • Reasonable getter and setter naming
  • Passing the API instead of interfaces and classes
  • Language independence

Command line tool

The generator is not yet available as a command line tool. Automatic use in build tools is therefore not possible. However, we will soon provide such a tool.

See also

How to build a message

nyssr.net - Innovative Distributed System