Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

To Calahan: this is an example of what doesn't work with my ORB

Status
Not open for further replies.

marcob

Programmer
Aug 1, 2000
8
0
0
IT
Hi,
In one of my previous posts I told I have a problem using my Java ORB. The code looks as:

import org.omg.CosNaming.*;
import org.omg.CORBA.*;

public class __main__ {
public static String __argomenti__ [] = new String[2];

public static void main(String args[]){
try{
int __count__;
char[] __buffer__ = new char[1024];
String __temp__ = "";
String __temp1__ = "";
java.io.FileReader rd = new java.io.FileReader("Config1.txt");
while ((__count__ = rd.read(__buffer__, 0, 1024)) != -1)
{
__temp__ = new String(__buffer__, 0, __count__);
__temp1__ = __temp1__ + __temp__;
}
rd.close();
__argomenti__[0] = "-ORBInitialHost";
__argomenti__[1] = __temp1__.trim();
ORB orb = ORB.init(__argomenti__,null);
org.omg.CORBA.Object objRef = orb.resolve_initial_references("NameService");
NamingContext ncRef = NamingContextHelper.narrow(objRef);
contatoreServant c;
NameComponent nc = new NameComponent("contatore", "ogg1");
NameComponent pathc[] = {nc};
contatoreServant d;
NameComponent nd = new NameComponent("contatore", "ogg2");
NameComponent pathd[] = {nd};
c = new contatoreServant ( new String2("User1") );
contatore contatoreServantRefogg1 = new _contatoreTie(c);
orb.connect(contatoreServantRefogg1);
ncRef.rebind(pathc, contatoreServantRefogg1);
d = new contatoreServant ( new String2("User2") );
contatore contatoreServantRefogg2 = new _contatoreTie(d);
orb.connect(contatoreServantRefogg2);
ncRef.rebind(pathd, contatoreServantRefogg2);
java.lang.Object sync = new java.lang.Object();
synchronized(sync){sync.wait();}
}
catch(Exception e)
{
System.out.println(e.toString());
}
}
} // end __main__ class

When a client uses an object of type contatore the ORB uses only the first one connected to reply (in this example the one identified by "c") to the request..
Is there a way to solve this problem without making many changes or I have to think of another solution?
Thanks,
Marco

PS To Calahan: Thanks for your reply, how would you adapt your bank example to this ? The interface of "contatore" doesn't matter at all..
 
OK - from looking at your code you are connecting to this contatore object, now even though you say the word new you are not getting a whole new object. What you are getting is a new local proxy object on the client siude which is connected to the remote contatore ORB. In effect you have to references to the same object.

To get two objects you would either need to register two contatore objects with the naming service (fine in a small system) or register a factory object in the naming service (good idea for a system with many objects). What you need to remember is that each contatore object ieUSER1 or USER2 , is a seperate object in your CORBA framework.

What you should do is have a contatoreFactory object which returns objects of type contatore this will give you a seperarte remote object for each instance.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top