RTC Forums
April 29, 2024, 05:06:27 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
 
   Home   Help Login Register  
Pages: [1]
  Print  
Author Topic: Session / Thread isolated environment variable  (Read 3473 times)
zsleo
RTC Expired
*
Posts: 80


« on: May 18, 2017, 07:57:43 AM »

RTC 7.71

I have an issue with the use of environment variables in RTC session.

Here is the issue. I must integrate with a government provided JAVA based API to communicate with a government portal. One of the setting is a "user based" environment variable used by the JAVA API to create per user (read RTC session) to call the government server and it creates report files in a folder specified by that "user based" environment variable.

I pass a parameter from a RTC client to a RTC server. Everything works perfectly if only one RTC client connects and completes its processing before another RTC client connects. Each process can take from a few second to a few minutes.

I am successfully creating and setting the environment variable but when multiple users call the same TRTCFunction at the same time one of the user's uses the wrong environment variable.  I set the environment variable by calling "SetEnvironmentVariable('EASY_API_LOG', PWideChar(sResult));" and I DO NOT call "PostMessage(HWND_BROADCAST, WM_SETTINGCHANGE, 0, integer(PAnsiChar('Environment')));" - this theoretically should restrict this environment variable's value to the session / thread.

Any suggestions as to how I can set an environment variable to be session / thread specific will be GREATLY welcomed.

In anticipation, thanks in advance.
Logged
D.Tkalcec (RTC)
Administrator
*****
Posts: 1881


« Reply #1 on: May 18, 2017, 08:12:46 AM »

According to this MSDN article, the SetEnvironmentVariable API is per-process and not per-thread:
https://msdn.microsoft.com/en-us/library/windows/desktop/ms686206(v=vs.85).aspx

You shoud also check this MSDN article, in case you are changing environment variables of another process:
https://msdn.microsoft.com/en-us/library/windows/desktop/ms682009(v=vs.85).aspx

Anyway ... RTC SDK does NOT use Environment variables and does NOT affect the way Environment Variables work. In other words, if there is a way to set an Environment Variable for a specific thread rather than a process, it would work with the RTC SDK the same way it works with any other Application. But ... since the RTC SDK uses a thread pool which is shared by all Clients, there is no guarantee that anything you set for a specific thread inside one event will be available to the same Client from any other event triggered by that Client.

PS. Anything that uses Environment Variables to pass parameters between processes has either NOT been designed for access from multiple users at the same time, or ... was developed by someone who doesn't know anything about multi-threading, so you will either need to create a separate child process of that JAVA-thingy you are calling for every one of your Clients connecting to the Server, or make sure that only one of your Clients can access that API at any time - for example, by using critical sections to secure access to that remote function on your Server. You might also want to use a global variable to keep track of the number of Clients waiting in the queue, so you don't exhaust all the threads in your Servers thread pool should there be a lot of Clients waiting.

Best Regards,
Danijel Tkalcec
Logged
zsleo
RTC Expired
*
Posts: 80


« Reply #2 on: May 19, 2017, 12:39:29 AM »

Danijel,

Thanks for your reply.

WRT " there is no guarantee that anything you set for a specific thread inside one event will be available to the same Client from any other event triggered by that Client.": This I understand and the call from the client passes the value for the variable with each call.

WRT "Anything that uses Environment Variables to pass parameters between processes has either NOT been designed for access from multiple users at the same time, or ... was developed by someone who doesn't know anything about multi-threading": What can I say? Sad. We (the industry I work in) have been trying then to change this for years - like a web service, but what do I know.

My last resort is to create an EXE that is started & called by the RTC Server for each client request and kill the EXE when the calling RTC Client terminates.  A LOT of work for a small outcome!

Best regards
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!
Page created in 0.024 seconds with 17 queries.