开发者

CORBA unclear stuff

I've recently began on working on my first CORBA project. I think I got the basic stuff , however there are some things that still elude me. One of these things is how CORBA handles several calls on the same object .

Suppose I have a client that registers itself with the server , and then can receive work. The server sends work at random times.

  • Are all these calls handled on the same thread ? This would mean that while the client is working , it cannot receive anything. In this case how could I give him a multithread behavior.

    • Or on the other hand is a thread spawned for every call received ?. In this case do I need to protect the common data that can be accessed on each call ? What would be a good practice to do so

Other thing I'd like to do is to create several workers and have them receive work ,but in my implementation only one worker is active .

Below :

public static void main(String[] args) 
{       
  try
  {
    connectWithServer(args);                
      createWorkers();              
      // wait for invocations from clients
      orb.run();
  }
  catch (Exception e) 
  {
       System.out.println("ERROR : " + e) ;
       e.printStackTrace(System.out);
   }
}

static public void connectWithServer(String[] args)throws Exception
{
        orb = ORB.init(args, null);

        // get reference to rootpoa & activate the POAManager
        rootpoa = POAHelper.narrow(orb.resolve_initial_references("RootPOA"));
        rootpoa.the_POAManager().activate();

        // get the root naming context
        org.omg.CORBA.Object objRef = orb.resolve_initial_references("NameService");

        // Use NamingContextExt instead of NamingContext. This is
        // part of the Interoperable naming Service.
        NamingContextExt ncRef = NamingContextExtHelper.narrow(objRef);

        // resolve the Object Reference in Naming
        taskBagImpl = TaskBagHelper.narrow(ncRef.resolve_str(SERVER_NAME));       

        System.out.println(TAG + " Obtained a handle on server object: " + taskBagImpl);        
    }



public static void createWorkers() throws Exception
    {
        for(int i = 0; i < nrOfWorkers; i++)
        {
             WorkerImpl w = new WorkerImpl();
             rootpoa.activate_object((S开发者_高级运维ervant) w);
             Worker ref = WorkerHelper.narrow(rootpoa.servant_to_reference(w));

             w.setRef(ref);

             taskBagImpl.registerWorker(w.getId(), ref);            
        }
    }


Threading options are not specified in the CORBA standard. The only configuration possible in respect to threading is the POA policy ThreadingPolicy. Possible values are either ORB_CTRL_MODEL or SINGLE_THREAD_MODEL. The former specifies nothing about threading, and the ORB implementation decides which threading model to use. The latter guarantees that every request that an object receives (within the same POA) is serialized, so no re-entrancy or multi-threading capabilities has to be implemented in the servant.

CORBA implementors, however, took notice of this limitation and implemented some standard default policies, that have to be configured by other means (maybe program options via ORB.init() or configuration files). Usually, you can find three different policies (once you select ORB_CTRL_MODEL):

  • Thread per request: Spawns a new thread each request.
  • Thread per client: Spawns a new thread for each different client.
  • Thread pool: The ORB pre-allocates some pool of threads and uses them to serve all requests.

Others are possible, but those tend to be the common ground. Of couse, either of them will force you to use any kind of locking strategy to support concurrent clients.


See this Java IDL FAQ :

What is the thread model supported by the CORBA implementation in this release?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜