 |
CS 696 Emerging Technologies: Distributed Objects |
|
|---|
Spring Semester, 1998
Naming Service Example
To Lecture Notes Index
© 1998, All Rights Reserved, SDSU & Roger Whitney
San Diego State University -- This page last updated 21-Apr-98
Contents of Doc 27, Naming Service Example
- References
- Using OrbixWeb Naming Service
- Example - Server & NS Separate
CORBAservices, chapter 3, Naming Service Specification, March 1995
OrbixWeb Programmer's Guide, IONA Technologies PLC, November 1997,
chapter 8 Making Objects Available in OrbixWeb pp. 180-202
Method 1. Use the OrbixWeb Names Browser
- Add objects to the name space structure via a GUI
Method 2. Write a program to add/remove objects
- The following example uses a separate program to add objects from a server
to the naming service
-
- It is possible to have the server add object to the naming service
-
- See /opt/OrbixWeb3.0/demos/namesStaff on rohan for an example
Finding the Default Naming Context
Method 1 CORBA Compliant and OrbixWeb Recommended
Use resolve_initial_references
protected static NamingContext getRootContext() throws
org.omg.CORBA.ORBPackage.InvalidName
{
org.omg.CORBA.Object initNCRef =
ORB.init().resolve_initial_references("NameService");
return NamingContextHelper.narrow(initNCRef);
}
Method 2 Use Orbix bind()
NamingContext rootContext =
NamingContextHelper.bind( "root:NS", hostName );
Method 3 Use the root naming context's IOR
Server
import IE.Iona.OrbixWeb._CORBA;
import IE.Iona.OrbixWeb.CORBA.ORB;
public class GreeterServer
{
public static void main (String args[])
{
org.omg.CORBA.ORB orb =
org.omg.CORBA.ORB.init();
try
{
Greeter upTown =
new _tie_Greeter( new TieGreeter( "Upton"), "up");
Greeter beach =
new _tie_Greeter( new TieGreeter( "Bob"), "low");
Greeter mountain = new InheritedGreeter( "Mike", "high");
Greeter general = new InheritedGreeter( "Gloria");
_CORBA.Orbix.impl_is_ready( "Visitor",
_CORBA.IT_INFINITE_TIMEOUT);
System.out.println("Server going Down");
}
catch ( org.omg.CORBA.SystemException corbaError)
{
System.out.println("Exception " + corbaError);
}
}
}
Registering Program
import IE.Iona.OrbixWeb._OrbixWeb;
import IE.Iona.OrbixWeb._CORBA ;
import org.omg.CORBA.ORB;
import org.omg.CORBA.SystemException ;
import org.omg.CORBA.CosNaming.* ;
import org.omg.CORBA.CosNaming.NamingContextPackage.*;
public class RegisterInNS
{
public static void main(String args[]) throws Exception
{
org.omg.CORBA.ORB orb =
org.omg.CORBA.ORB.init();
NamingContext rootContext = getRootContext( orb );
NameComponent[] ca = new NameComponent[1];
ca[0] = new NameComponent("Califorina", "");
NamingContext stateContext =
rootContext.bind_new_context( ca );
NameComponent[] city = new NameComponent[1];
city[0] = new NameComponent("Del Mar", "");
stateContext.bind( city, getGreeter( "low") );
city[0] = new NameComponent("Julian", "");
stateContext.bind( city, getGreeter( "high") );
city[0] = new NameComponent("San Diego", "");
stateContext.bind( city, getGreeter( "up") );
}
// Registering Program Continued
protected static Greeter getGreeter( String marker )
{
String hostname = "eli.sdsu.edu";
String serverLabel = ":Visitor";
return GreeterHelper.bind(marker + serverLabel,
hostname);
}
protected static NamingContext getRootContext(
ORB myOrb) throws
org.omg.CORBA.ORBPackage.InvalidName
{
org.omg.CORBA.Object initNCRef =
myOrb.resolve_initial_references("NameService");
return NamingContextHelper.narrow(initNCRef);
}
}
Client Code
import IE.Iona.OrbixWeb._OrbixWeb;
import IE.Iona.OrbixWeb._CORBA ;
import org.omg.CORBA.ORB;
import org.omg.CORBA.SystemException ;
import org.omg.CORBA.CosNaming.* ;
import org.omg.CORBA.CosNaming.NamingContextPackage.*;
public class SimpleNSClient {
public static void main (String args[]) {
org.omg.CORBA.ORB orb = org.omg.CORBA.ORB.init();
Greeter californiaGreeter;
NamingContext rootContext;
try {
rootContext = getRootContext();
NameComponent[] ca = new NameComponent[2];
ca[0] = new NameComponent("Califorina", "");
ca[1] = new NameComponent("Julian", "");
org.omg.CORBA.Object greeterRef =
rootContext.resolve( ca );
californiaGreeter = GreeterHelper.narrow( greeterRef);
System.out.println( californiaGreeter.name());
}
catch ( Exception corbaError) {
System.out.println("Exception " + corbaError);
}
}
protected static NamingContext getRootContext() throws
org.omg.CORBA.ORBPackage.InvalidName
{
org.omg.CORBA.Object initNCRef =
ORB.init().resolve_initial_references("NameService");
return NamingContextHelper.narrow(initNCRef);
}
}
visitors since 02-Apr-98