Open Source on IBM i

Sharing Configuration in ILEastic

I stumbled upon a little problem I first had some trouble to wrap my head around. My situation was the following:

  • I had an ILEastic web service with multiple modules
  • I wanted to share the configuration data with all modules

So for this kind of internal sharing of data I had decided to use a global variable I exported in one module and imported in the other module.

So for my first module the code looked something like this:


ctl-opt thread(*concurrent);

/include 'ileastic/ileastic.rpgle'
/include 'noxdb/jsonparser.rpgle'

dcl-s userConfig pointer export;

*inlr = *on;

dcl-proc main;
  dcl-ds config likeds(il_config);

  userConfig = loadConfig();


And the second module with the code for the web service endpoints looked something like this:


ctl-opt nomain thread(*CONCURRENT);

/include 'ileastic/ileastic.rpgle'

dcl-s userConfig pointer import;


Everything looked nice. The procedure loadConfig did load the configuration and the configuration was assigned to the variable userConfig. All seemed well but when the procedure in the second module accessed the imported variable the variable hold no value.

Hmmm ...

After much reading in the IBM Knowledge Center I haven't found anything which made it work.

And I noticed that I find most of my solutions on my way home from work or before going to bed. And that was also the case here.

I hadn't taken into account that this was a multi-threaded application and with thread(*CONCURRENT) I have a new userConfig variable for every thread I started. So the value I previously set is not available in the thread I started. But I wanted the configuration to be available in all threads so a little change to the code made it happen.

dcl-s userConfig pointer export static(*allthread);


dcl-s userConfig pointer import static(*allthread);

Now with the keywords static(*ALLTHREAD) there is only one instance of this variable for all threads.

Next post will be about provisioning the web service with a dynamic configuration.

Happy configuring!


Tags : RPG