Use multiple ORBs through different threads (multithreaded multi-orb client application) - how?

后端 未结 2 1101
Happy的楠姐
Happy的楠姐 2021-01-29 01:43

This question is related to: Is it possible to have several ORB objects in the same process?

So, thanks to @BrianKelly I found information about the OR

相关标签:
2条回答
  • 2021-01-29 02:18

    The ORB will use different connections (and threads) to different servers every time - always. Receiving answers and incomming calls are also handled in different threads (if useful and/or needed).

    I think you try try to solve things, that the ORB already has solved for you. It's a middleware, don't scare about threading and stuff. It's already done by CORBA experts.

    0 讨论(0)
  • 2021-01-29 02:26

    I found something like a workaround. Makes my code really ugly and not easy for support, but it's still something.

    Here's what I did:

    • add a mechanism (in my application), that will count the necessary threads, before starting them
    • read, in advance, the configurations - I need to know the necessary parameters for the naming services (used in ORB_init)
    • before starting any threads, a "manager" will execute just once ORB_init, but it will pass several times the -ORBInitRef parameter, with different values - one for each thread/connection
    • after this is done, the threads are started, but instead of executing ORB_init, they directly execute resolve_initial_references and continue with the server specific things

    Note: My example does not containt resolve_initial_references, because the crash is in ORB_init.


    So, applying this "algorithm" for this "workaround" would look like:

    #include <OB/CORBA.h>
    
    void* run( void * );
    CORBA::ORB_var varORB;
    
    int main()
    {
        /** The necessary configurations */
        //-------------------------------------v
        const char* nameservice1 = "NameService1=corbaloc::10.102.8.15:13069/NameService";
        const char* nameservice2 = "NameService2=corbaloc::192.168.1.99:13069/NameService";
        //-------------------------------------^
    
        /** INIT the ORB **/
        int argc = 5; char* argv[ 6 ];
        const char* initref = "-ORBInitRef";
        const char* exe = "test";
    
        argv[0] = (char*)exe;
        argv[1] = (char*)initref; argv[2] = (char*)nameservice1;
        argv[3] = (char*)initref; argv[4] = (char*)nameservice2;
        argv[5] = NULL;
    
        varORB = CORBA::ORB_init( argc, argv );
    
        pthread_t t1, t2; 
    
        char ns_id1 = '1', ns_id2 = '2';
        pthread_create( &t1, NULL, run, (void*)&ns_id1 );  
        pthread_create( &t2, NULL, run, (void*)&ns_id2 );  
    
        pthread_join( t1, NULL ); pthread_join( t2, NULL );
    
        varORB->destroy();
    
        return 0;
    }
    void* run( void* arg )
    {
        char nameservice[] = "NameServiceN";
    
        // set the right number of the nameservice
        nameservice[ 11 ] = *((char*)arg);  
    
        varORB->resolve_initial_references( nameservice );
    
        // do some CORBA-specific stuff
    
        printf( "SUCCESS %c\n", *(char*)arg );
        return NULL;
    }
    

    NOTE

    I still can't believe this is the only option. If you look at my code (in the question) carefully, you'll see, that:

    • it IS possible to have multiple ORBs (see the case with mt == false)
    • the call to ORB_init IS synchronized
    • the ORB identifier IS implemented and it works fine (again with mt == false)

    So, this is not actual answer to my question, it's kind of a workaround.

    It doesn't make sense (at least to me) to be possible to create several ORBs in a single thread, but not in multiple threads.

    0 讨论(0)
提交回复
热议问题