[omniORB] Interoperability between JAVA and omniORB

Jochen Fischer Jochen.Fischer@dlr.de
Mon, 30 Jul 2001 18:25:26 +0200


This is a multi-part message in MIME format.
--------------C26206359889EA88E2E38F3D
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Hello!

I have a question concerning the interoperability between 
JAVA and omniORB. We are using omniORB for the development 
of an integrated simulation environment which will be used 
in an heterogeneous computing environment. The software is 
developed using several programming languages like C++, JAVA 
and Python. Currently we are migrating our Software from
MICO (another freeware ORB) to omniORB3 (Version 3.0.4).

Since our software is heavily multithreaded there may be many 
concurrent invocations between two processes. When the involved 
client and server objects are implemented in C++ or Python 
anything is fine. But when the client is written in JAVA, 
multiple invocations on an arbitrary server object which are 
initiated in different JAVA threads will be serialized.
That means, the calls are executed one by one.

The attached sourcecode demonstrates this behaviour. When the 
echoWait call is in progress, it is not possible to invoke 
echoString concurrently from the JAVA client. The python 
client in contrast behaves like intended.
This can be reproduced on any platform with any JVM.

Is there anyone who can explain this strange behaviour?
Thanks a lot.

Jochen

-- 
Jochen Fischer
German Aerospace Center
Simulation and Software Technology 
51147 Koeln
Germany

Tel: +49 (0)2203/601-2059  mailto:Jochen.Fischer@dlr.de
FAX: +49 (0)2203/601-3070
--------------C26206359889EA88E2E38F3D
Content-Type: text/plain; charset=us-ascii;
 name="echo.idl"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="echo.idl"

// example_echo.idl
module Example {
  interface Echo {
    string echoString(in string mesg);
    void echoWait(in long timeout);
  };
};

--------------C26206359889EA88E2E38F3D
Content-Type: text/plain; charset=us-ascii;
 name="EchoServer.py"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="EchoServer.py"

#!/usr/local/bin/python

import sys
import time
from omniORB import CORBA, PortableServer

# Import the stubs for the Naming service
import CosNaming

# Import the stubs and skeletons for the Example module
import Example, Example__POA

# Define an implementation of the Echo interface
class Echo_i (Example__POA.Echo):
  def echoString(self, mesg):
    print "echoString() called with message:", mesg
    return mesg

  def echoWait(self, timeout):
    print "echoWait: waiting for %d seconds" % (timeout)
    while (timeout > 0):
      print timeout; 
      time.sleep (1)
      timeout = timeout - 1

# Initialise the ORB
orb = CORBA.ORB_init(sys.argv, CORBA.ORB_ID)

# Find the root POA
poa = orb.resolve_initial_references("RootPOA")

# Create an instance of Echo_i
ei = Echo_i()

# Create an object reference, and implicitly activate the object
eo = ei._this()

# Print out the IOR
print orb.object_to_string(eo)

# Activate the POA
poaManager = poa._get_the_POAManager()
poaManager.activate()

# Everything is running now, but if this thread drops out of the end
# of the file, the process will exit. orb.run() just blocks until the
# ORB is shut down
orb.run()

--------------C26206359889EA88E2E38F3D
Content-Type: text/plain; charset=us-ascii;
 name="EchoClient.py"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="EchoClient.py"

#!/usr/local/bin/python

import sys
import thread
import time

# Import the CORBA module
from omniORB import CORBA

# Import the stubs for the CosNaming and Example modules
import CosNaming, Example

def callEchoString(obj, msg):
  result = obj.echoString(msg)
  print "I said: '%s'. The object said: '%s'." % (msg,result)

def callEchoWait(obj, time):
  obj.echoWait(time)

# Initialise the ORB
orb = CORBA.ORB_init(sys.argv, CORBA.ORB_ID)

# Get the IOR of an Echo object from the command line
ior = sys.argv[1]
print ior;

# Convert the IOR to an object reference
obj = orb.string_to_object(ior)

# Narrow the object to an Example::Echo
eo = obj._narrow(Example.Echo)

if (eo is None):
  print "Object reference is not an Example::Echo"
  sys.exit(1)

# Invoke the echoWait operation in a thread
print "Starting thread"
thread.start_new_thread(callEchoWait,(eo,10));
print "Thread running"

# Invoke the echoString operation
for i in range(10):
  time.sleep(1)
  callEchoString(eo,"Hello from Python!")

--------------C26206359889EA88E2E38F3D
Content-Type: text/plain; charset=us-ascii;
 name="EchoClient.java"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="EchoClient.java"

import Example.*;           // The package containing our stubs.
import org.omg.CORBA.*;      // All CORBA applications need these classes.
import java.lang.*;

class EchoThread extends Thread {
    Example.Echo echoObj;
	
    public void setEchoObj(Example.Echo eo){
        echoObj = eo;
    }

    public void run() {
        System.out.println("Thread running");
        echoObj.echoWait(10);
        System.out.println("Thread terminated");
    }
}

public class EchoClient
{
  public static void main(String args[])
  {
    try{
      String ior, text, echoResult;
      
      // Create and initialize the ORB
      ORB orb = ORB.init(args, null);

      if (args.length == 0) {
        System.out.println("No IOR specified");
        System.exit(-1);
      }
      ior = args[0];
      
      org.omg.CORBA.Object echoObj = orb.string_to_object(ior);
      Example.Echo echoRef = Example.EchoHelper.narrow(echoObj);

      System.out.println("Starting Thread");
      EchoThread myEchothread = new EchoThread();
      myEchothread.setEchoObj(echoRef);
      myEchothread.start();

      text = "Hello from JAVA!";
      // Call the Echo server object and print results
      for (int i = 0; i < 10; i++) {
        Thread.sleep(1000);
        echoResult = echoRef.echoString(text);
        System.out.println("I said: " + text + ". The object said: " + echoResult + ".");
      }

    } catch(Exception e) {
        System.out.println("ERROR : " + e);
        e.printStackTrace(System.out);
      }  
  }
}



--------------C26206359889EA88E2E38F3D--