Archived

This forum has been archived. Please start a new discussion on GitHub.

strategies for sharing ice runtime in data layer under .net

I'm going to use ice proxies in the data layer for a variety of tiered systems. My question now is how best to share a single instance of the ice runtime amongst an indeterminate number of instances of data layer proxies which will be loaded into a single appdomain.

It's under .net 2.0. I know I need to find a way to 'register' and share the single instance of the runtime, and I can find a way to do that, but maybe someone else has already done the dirty work for this?

I'm asking, because I would prefer a method which does not require the business components (or the application in general) which will be using the DL components to have any knowledge of how the DL functions. I want the DL components to be the only ones who know about ice.

Comments

  • I don't quite understand your question. Can you explain a bit more about what you are trying to do? How many servers are involved in your application? What do you mean by "sharing a single instance of the runtime"?

    As far as .NET is concerned, Ice is just another DLL that process link against. It's simply a library. If multiple processes use Ice, the text and constant data of the Ice runtime are shared among all processes.

    Cheers,

    Michi.
  • Do you mean that multiple processes on a single client machine that call

    Ice.Communicator ic = Ice.Util.initialize();

    will actually be sharing a single underlying instance of the ice runtime?

    My fear was that calling this line from multiple data layer objects loaded into the same application would create multiple instances of the ice runtime.

    But if I understand you then even multiple processes doing so only create a single shared instance of the runtime on any one machine.

    Is this correct?
  • bernard
    bernard Jupiter, FL
    Each time you call:

    Ice.Communicator ic = Ice.Util.initialize();

    you create a brand new communicator object. It does not matter if your initialize() calls are in the same program, processes on the same machine or processes on different machines ... you always get a new Communicator object.

    What do you mean by "instance of the Ice runtime"? If it's just the Ice DLLs, then as Michi pointed out, several programs written against the same DLL versions will share them: a single copy of these DLLs will be loaded in memory and shared by your processes. Note that only the code is shared, not the data.

    Best regards,
    Bernard
  • Yes, this is what I originally thought, and my motivation for posting my question was to avoid creating several copies of the communicator *data* structures within a single process.

    What I mean by the 'ice runtime' is instances of the data structures created by the communicator object. I want to avoid duplicating these.

    What I want to do is, for example, have a process which will create a number of business entities, which will in turn create a number of data layer entities. The business entities, and the code which manages the business entities, have no idea how the data layer is implemented. So I do not want any ice management code in these. Each of the data layer entities (or some of them anyway) will want to obtain proxies for ice objects running in a remote process. So, each of these data layer (DL) entities will need to obtain a communicator.

    My concern is that, if the process ends up having 7 DL entities active at the same time, it will have 7 instances of Ice.Communicator running in the process. What I want is to share one instance of Communicator amongst all DL entities which *might* get loaded. They won't know who gets loaded until the upper-level code loads and creates them.

    So... I guess this is more of a .net question than ice question. I just thought that maybe someone in this forum has dealt with this issue already and might have a working solution, thereby saving me precious hours that I could spend on the beach with my daughter instead!!!

    Or maybe I am completely deluded. It's been said. Maybe the communicator data is lightweight enough that it does not matter.
  • bernard
    bernard Jupiter, FL
    If everything is within one process, then yes, you can share a single Communicator object.

    I'd suggest to use a singleton class to provide this communicator to the various components who need it, e.g.:
    public class SharedCommunicatorHolder
    {
          public static Communicator getInstance()
          {
               lock(_mutex)
               {
                    if(_instance == null)
                    {
                         initCommunicator();
                    }
               }
               return _instance;
          }
    
          private static void initCommunicator()
          {
              ...
          }
          private static Communicator _instance;
          private static Mutex _mutex = new Mutex();
    }
    

    Best regards,
    Bernard
  • Thank you! (simple for *you* I know...)