Skip to main content

Problem:

  • Product Name: VisibBoker
  • Product Version: 5.2.
  • Product Component: Naming Service
  • Platform: Windows2000
  • JDK: JDK_1.3.1


I have two name service which have their object .For example:

name service - serviceA, serviceB
serviceA: Object_A, Object_B
serviceB: Object_C, Object_D

how the client can get the object for serviceA and serviceB? Assume they are of two different machines.

Resolution:

I have modified the Client.C file in the bank_naming example.

#include "CosNaming_c.hh"
#include "Bank_c.hh"
#if defined(_VIS_STD)
# include <fstream>
#else
# include <fstream.h>
#endif

const int MAXBUF = 1024;

// USE_STD_NS is a define setup by VisiBroker to use the std namespace
USE_STD_NS

int main(int argc, char* const* argv)
{
  try {
    // Initialize the ORB
    CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);

 // Read object reference from file ior1.dat
    ifstream in("ior1.dat");
    char ior[MAXBUF];
    in.getline(ior, MAXBUF);
    in.close();

    // convert the stringified IOR to an object reference
    CORBA::Object_var rootContextObj1 = orb->string_to_object(ior);

 // Read object reference from file ior2.dat
    in.open("ior2.dat", ios::in);
    in.getline(ior, MAXBUF);
    in.close();

    CORBA::Object_var rootContextObj2 = orb->string_to_object(ior);

    // Locate an account manager. Give the full POA name and the servant ID.
    CosNaming::NamingContext_var rootContext =
            CosNaming::NamingContext::_narrow(rootContextObj1);
    // Locate an account manager through the Naming Service
    CosNaming::Name name;
    name.length(1);
    name[0].id = (const char *) "BankManager";
    name[0].kind = (const char *) "";
    CORBA::Object_var managerObj = rootContext->resolve(name);
    Bank::AccountManager_var manager = Bank::AccountManager::_narrow(managerObj);

    // Use argv[1] as the account name, or a default
    const char* account_name = argc > 1 ? argv[1] : "Jack B. Quick";

    // Request the account manager to open a named account
    Bank::Account_var account = manager->open(account_name);

    // Get the balance of the account
    CORBA::Float balance = account->balance();

    // Print out the balance
    cout << "The balance in " << account_name << "'s account is $"
         << balance << endl;
//
    rootContext = CosNaming::NamingContext::_narrow(rootContextObj2);
    managerObj = rootContext->resolve(name);
    manager = Bank::AccountManager::_narrow(managerObj);
    account = manager->open(account_name);
    balance = account->balance();
    cout << "The balance in " << account_name << "'s account is $"
         << balance << endl;
  }
  catch(const CORBA::Exception& e) {
    cerr << e << endl;
    return 1;
  }
  return 0;
}

1)Start 2 naming Service in 2 different machines with different port no.
MachineA>nameserv -J-Dvbroker.se.iiop_tp.scm.iiop_tp.listener.port=14660
MachineB>nameserv -J-Dvbroker.se.iiop_tp.scm.iiop_tp.listener.port=146612

2)In the bank_naming directory, rename the "ns.ior" filename to "ior1.dat".
You can open up the Client.C file and see that we are now accessing the ior1.dat file and ior2.dat file.
Since we want to use two different namingService, you can use the ior file directly and can do string_to_object like in bank_naming example.

3) Start 2 Servers.
MachineA>start Server -ORBInitRef NameService=iioploc://143.186.138.24:14660/NameService
MachineB>start Server -ORBInitRef NameService=iioploc://143.186.138.24:14661/NameService

4) In the bank_naming directory, change the "ns.ior" filename to "ior2.dat".
Now also ftp/copy the ior1.dat file from Machine A to this bank_naming directory.
The reason is that when we start the Client in Machine B, we needto access both ior1.dat and ior2.dat file to locate the naming service.
So if you want to start the Client on Machine A, make sure you have these 2 files too in the bank_naming directory of Machine A.

5) Start Client:

>Client
The balance in Jack A. Quick"s account is $0.41
The balance in Jack A. Quick"s account is $184.67

As you can see from the Clients that it is actually returning 2 balances showing that it is using 2 naming services A & B to get these 2 objects.
Disadvantage of this way is that they should ftp (transfer) the ior file to Client directly. If customers do not like method, you can use master/slave configuration and refer to "Configuring VisiNaming Service Cluster" in vbdevelopers guide.

#VisiBroker
#Security