Home Help Center

Custom "event loops"?

stephanstephan Member Stephan StapelOrganization: Stephan StapelProject: BristolNG
Dear list members,

Is it possible (or does it make sense) to use custom 'event loops' within Ice servers? What I basically would like to achieve is to avoid the blocking waitForShutdown() call but instead still have control over my program, e.g. to emit intervalled signals to my server to make it perform certain tasks after those intervals.
Or would it make more sense to run two threads within a program, one for Ice and the other one for the timer?

Comments appreciated.

Kind regards,

Kind regards,

Stephan

Comments

  • marcmarc FloridaAdministrators, ZeroC Staff Marc LaukienOrganization: ZeroC, Inc.Project: The Internet Communications Engine ZeroC Staff
    You don't need to call waitForShutdown(). This method is only provided for pure servers, to be able to suspend the main thread until the server is shut down.

    There is no Ice event loop, because Ice is inherently multithreaded. So events are handled internally, by a leader/follower thread pool. This means that you can use the main thread in any way you wish.
  • stephanstephan Member Stephan StapelOrganization: Stephan StapelProject: BristolNG
    Hi Mark!
    Originally posted by marc
    There is no Ice event loop, because Ice is inherently multithreaded. So events are handled internally, by a leader/follower thread pool. This means that you can use the main thread in any way you wish.

    sorry for another disbelief in the simplicity of the ICE framework. It's really amazing. My code now looks like (meta):
    int main()
    {
      // ...
      unsigned int nSleepMsecs = 2000;
    
      adapter->activate();
    
      while (true)
      {
    #ifdef WIN32
        Sleep(nSleepMsecs);
    #else
       msleep(nSleepMsecs);
    #endif
      
        if (areWeDone())
        {
          break;
        }
      }
    
      comm->shutdown();
      return status;
    }
    

    Does this make sense to you?
    Also, two new questions arise:
    1) What is the proposed way of calling function within the remote object? Shall I call the functions directly on the MyServerClassI instance or shall I better call the function through the MyServerClassPrx, i.e. through Ice?
    2) How should the server object and the "main" thread exchange data? I.e. I would like to have things executed at certain times, e.g. sunday, midnight. Imho it would make sense to hand this time to the main thread and make the main thread call the server object function at the specified time. The other method would be to invoke a schedule() function on the server object every second/ minute/ whatever and make this schedule() functions check what to perform now (basically this is another pushing vs. polling situation).

    regs,

    Stephan

    P.S.: I hope that I'm using the forum in the correct way, i.e. in order to discuss things and not simply use it in a question-answer fashion :)
  • marcmarc FloridaAdministrators, ZeroC Staff Marc LaukienOrganization: ZeroC, Inc.Project: The Internet Communications Engine ZeroC Staff
    Originally posted by stephan

    Does this make sense to you?

    Sure, this looks fine.
    Originally posted by stephan

    Also, two new questions arise:
    1) What is the proposed way of calling function within the remote object? Shall I call the functions directly on the MyServerClassI instance or shall I better call the function through the MyServerClassPrx, i.e. through Ice?

    If you use the ASM only (Active Servant Map), and you know exactly the life cycle of your servants and Ice objects, then you can use servant calls directly.

    However, for the more general case, you should use proxies. For example, if you use servant locators or Freeze. With Freeze, a call to an Ice object might first load the servant on demand, and release it later automatically. Therefore you cannot use the servant directly in this case.

    So the general recommendation is to use proxies. This will give you less worries if you change the implementation of an Ice object.
    Originally posted by stephan

    2) How should the server object and the "main" thread exchange data? I.e. I would like to have things executed at certain times, e.g. sunday, midnight. Imho it would make sense to hand this time to the main thread and make the main thread call the server object function at the specified time. The other method would be to invoke a schedule() function on the server object every second/ minute/ whatever and make this schedule() functions check what to perform now (basically this is another pushing vs. polling situation).

    The usual way to exchange data is by calling operations with the data as parameters.

    The other method would be more complicated. You would have to start a new thread for a servant implementing an Ice object, make sure that the thread is terminated properly when the servant is not used anymore, etc. And this gets even more complicated if you use Freeze, because then you don't control the instantiations and destructions of servants as direct anymore as when you use the ASM.
    Originally posted by stephan

    regs,

    Stephan

    P.S.: I hope that I'm using the forum in the correct way, i.e. in order to discuss things and not simply use it in a question-answer fashion :)

    This is just the right forum for such questions.
Sign In or Register to comment.