Uploaded image for project: 'Byteman'
  1. Byteman
  2. BYTEMAN-313

Extend Helper with a LinkMap API to allow better sharing of state between rules

XMLWordPrintable

    • Icon: Feature Request Feature Request
    • Resolution: Done
    • Icon: Major Major
    • 3.0.5
    • 3.0.3
    • Rule Helpers
    • None

      Sometimes it is helpful if a value identified by one rule can be made accessible to other rules. This issue proposes to extend the standard Helper with a small builtin API to support this capability. The proposed API employs the concept of a LinkMap. That notion and the API is presented in more details in the linked forum thread. Essentially a LinkMap is a HashMap<Object, Object> i..e it provides a way of first establishing and subsequently identifying a link from one object (a HashMap key) to some related object (the linked HashMap value).

      For simple cases, the API supports inserting removing and looking up values by key in a special, global, default LinkMap. This is fine if you want to record some value using a key which is, say, a global name like "source", "tid" or "bad value" or even using an index like 0, 1, 2, etc and then have other threads look it up by supplying the same key.

      Unfiortunately, that's inadequate if you might need to link multiple values under the same key. Fir example, you might need to associate both a good and bad value with each thread. In that case linking a good value using the thread as key will throw away any previously linked bad value and vice versa.

      So, the API also allows you to create other LinkMaps and label them using some identifying Object. In the example cited above two LinkMaps could be created, labelled with the keys "good value" and "bad value". Rules can insert, remove and lookup links in the appropriate LinkMap by supplying both the label and the current thread as the LinkMap name and link key. Of course, it is also possible achieve the same thing using these values the other way round, labelling LinkMaps with the current thread and using the relevant String as the link key.

      Link maps can be explicitly created before being used to insert, remove or lookup linked objects. However, they will also be created on demand if needed.

      Also, the default LinkMap is actually just a pre-defined LinkMap whose label is the String "default". So, each of the LinkMap API builtins which omits the LinkMap label argument is implemented by delegating to the corresponding LinkMap API builtin which takes the LinkMap label argument, with that argument supplied as the String "default".

              rhn-engineering-adinn Andrew Dinn
              rhn-engineering-adinn Andrew Dinn
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Created:
                Updated:
                Resolved: