문제

Is there any way to access the corba nameservice from a running Java (1.5) program. I would like to see which other processes are registered to a given one.

I do know, that there are three tools within the JRE. servertool, orbd and tnameserv but either I didn't use them properly or they are not the right tools.

Additional Information: The program is started with -ORBInitialPort 1234

Execute orbd -ORBInitialPort 1234 -> Returnes an error due to already in use ( yes fine, because the application is running ) same with tnameserv. But if I use servertool -ORBInitialPort 1234, no errors occur. But if I type "list" on the command prompt or another command, it will always return an empty list.

Sincerely Christian

도움이 되었습니까?

해결책

The existing, running CORBA naming service can be accessed through the classes in the org.omg.CosNaming package. You need to obtain the NamingContextExt. It has methods to iterate through all existing bindings as well as to resolve objects by name.

When you start a tnameserv tool, it prints for you IOR - this is CORBA URL. You can get the CORBA object (name service including) from any ORB in the world if it is accessible through network and you supply the IOR:

public static void main(String args[]) throws Exception {
   ORB orb = ORB.init(args, null);
   // pass the IOR as command line parameter for this program
   String ior = args[0];
   org.omg.CORBA.Object objRef = orb.string_to_object(ior);
   NamingContextExt nameService = NamingContextExtHelper.narrow(objRef);

   // Now you can work with your naming service. 
}

See here for tutorial on how to access CORBA objects and here on how to work with naming service.

The orb.resolve_initial_references("NameService") by default (if not configured) returns the local service on the running virtual machine and you need to query the external one. To use this, you need to pass the correct configuration properties (second parameter that is null in my example) with the ORBInitRef.NameService property set to the address of your name service, as described here. Many (or most of) production environments have this property set so that this method returns the correct remote name service.

servertool is a command line tool that allows to list the registered CORBA objects without writing Java code. You need to specify on which host the name service of interest is running. servertool will not complain if the service is running at the given host and port. It should complain if it does not find one!

Most important, your CORBA object must register with the obtained name service by calling

nameService.bind(yourName, yourCORBAObject);

In case the name service is remote, this will send the network message containing the URL of your orb and reference to your object. If your do not register your object, of course the reference will not be available there and the servertool will show you an empty list, just as you complain.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top