Exo Cosnaming
Exo Cosnaming
/bin/sh
# Try to find top−level directory
if test −f naming/src/com/ooc/CosNaming/Server.java
then top_srcdir=naming
elif test −f src/com/ooc/CosNaming/Server.java
then top_srcdir=.
elif test −f ../src/com/ooc/CosNaming/Server.java
then top_srcdir=..
elif test −f ../../src/com/ooc/CosNaming/Server.java
then top_srcdir=../..
elif test −f ../../../src/com/ooc/CosNaming/Server.java
then top_srcdir=../../..
elif test −f ../../../../src/com/ooc/CosNaming/Server.java
then top_srcdir=../../../..
else
$echo "$0: can’t find top−level directory"
exit
fi
# Run standard init script
. $top_srcdir/../config/sh.init
# Check for the C++ distribution
have_cpp=if test −n "$OB_CPP_DIST" −a −x "$OB_CPP_DIST/naming/bin/nameserv"
then have_cpp="yes"
fi
# JDK 1.2 users may encounter an IncompatibleClassChangeError exception due to an incompatibility
# with the JDK’s builtin stubs for the Naming Service. We’ll use the −Xbootclasspath option to
# avoid this problem.
java_version=‘$JAVA −version 2>&1‘
if ‘$echo $java_version | grep −q ’1\.2’‘
then
# For JDK 1.2, we can use the −Xbootclasspath/p option to prepend classes to the bootclasspath.
if test "$windows" = "yes"
then BOOTCLASSPATH="−Xbootclasspath/p:$top_srcdir/lib;$OB_LIB"
else BOOTCLASSPATH="−Xbootclasspath/p:$top_srcdir/lib:$OB_LIB"
fi
fi
# Set Java CLASSPATH
if test "$windows" = "yes"
then
CLASSPATH="$top_srcdir/demo/classes;$CLASSPATH"
CLASSPATH="$top_srcdir/lib;$CLASSPATH"
CLASSPATH="$OB_LIB;$CLASSPATH"
else
CLASSPATH="$top_srcdir/demo/classes:$CLASSPATH"
CLASSPATH="$top_srcdir/lib:$CLASSPATH"
CLASSPATH="$OB_LIB:$CLASSPATH"
fi
export CLASSPATH
# Print welcome message
$echo "* ORBacus NamingService Demo *"
# Ask for server
server=while test −z "$server"
do
$echo
$echo "Select NamingService to use:"
$echo
if test −n "$have_cpp"
then $echo "1: C++ NamingService"
else $echo "1: C++ NamingService (not available)"
fi
$echo "2: Java NamingService"
$echo
$echo "−−−> \c"
read num
if test "$num" = "1" −a −n "$have_cpp"
then server="$OB_CPP_DIST/naming/bin/nameserv${exe}"
fi
if test "$num" = "2"
then server="$JAVA $BOOTCLASSPATH com.ooc.CosNaming.Server"
fi
done
# Set name of reference file
ref=Naming.ref
# Function to deactivate the server
nsid=0
srvid=0
deactivate()
{
if test $nsid −ne 0
then kill $nsid
fi
if test $srvid −ne 0
then kill $srvid
fi
exit lance le serveur de nommage en arrière−
} plan avec récupération de la référence dans
# Start NamingService
$echo le fichier "Naming.ref"
$echo "Waiting for NamingService to start up... \c"
rm −f $ref
$server −−ior > $ref &
nsid=$!
trap deactivate 1 2 3 4 5 6 7 8 10 12 13 14 15
count=0
while test ! −s $ref −a $count −lt 6
do
sleep 1
count=‘expr $count + 1‘
done
if test ! −s $ref nom du service lancé avec
then les applications
$echo "Failed!" client/serveur, accompagné
$echo "(NamingService was not started)" de l’IOR associée.
exit
else $echo "OK!"
fi
# Start server
$JAVA $BOOTCLASSPATH naming.Server −ORBservice NameService ‘cat $ref‘ &
srvid=$!
sleep 3
# Start client
$JAVA $BOOTCLASSPATH naming.Client −ORBservice NameService ‘cat $ref‘
# Deactivate naming service and server
deactivate
// **********************************************************************
//
// .../JOB−4.0.4/naming/src/com/ooc/CosNaming/Server.java
//
// Ce fichier est appelé par le shell ’run" dans la démo du service de nommage ci−avant.
// **********************************************************************
package com.ooc.CosNaming;
import org.omg.CORBA.*;
import org.omg.PortableServer.*;
import java.io.*;
static int
run(org.omg.CORBA.ORB orb, String progName, String[] args,
java.util.Properties props)
{
//
// Get options
//
boolean ior = false;
NamingServiceOptions options = new NamingServiceOptions();
//
// Check properties first
//
String propRoot = "ooc.naming.";
java.util.Enumeration keys = props.propertyNames();
while(keys.hasMoreElements())
{
String key = (String)keys.nextElement();
if(!key.startsWith(propRoot))
continue;
if(key.equals("ooc.naming.database"))
{
options.databaseName = value;
}
else if(key.equals("ooc.naming.timeout"))
{
try
{
options.databaseTimeout = Integer.parseInt(value);
}
catch(NumberFormatException ex)
{
System.err.println("Invalid value for ooc.naming.timeout");
return 1;
}
}
else if(key.equals("ooc.naming.callback_timeout"))
{
try
{
options.callbackTimeout = Integer.parseInt(value);
}
catch(NumberFormatException ex)
{
System.err.println(
"Invalid value for ooc.naming.callback_timeout");
return 1;
}
}
else if(key.equals("ooc.naming.no_updates"))
{
options.noUpdates = value.equals("true") ||
value.equals("TRUE") || value.equals("1");
}
else if(key.equals("ooc.naming.trace_level"))
{
options.traceLevel = Integer.parseInt(value);
}
else if(key.equals("ooc.naming.port"))
{
//
// Set the ooc.orb.oa.port property from this value
//
String oaPort = props.getProperty("ooc.orb.oa.port");
if (oaPort == null)
props.put("ooc.orb.oa.port", value);
}
else
{
System.err.println(progName + ": ‘" + key + "’: " +
"unknown property");
}
}
//
// Resolve Root POA
//
org.omg.CORBA.Object poaObj = null;
try
{
poaObj = orb.resolve_initial_references("RootPOA");
}
catch(org.omg.CORBA.ORBPackage.InvalidName ex)
{
throw new RuntimeException();
}
POA rootPOA = POAHelper.narrow(poaObj);
//
// Get a reference to the POA manager
//
POAManager manager = rootPOA.the_POAManager();
//
// The persistent poa
//
POA rootContextPOA = null;
POA contextPOA = null;
try
{
Policy[] policies = new org.omg.CORBA.Policy[2];
policies[0] =
rootPOA.create_lifespan_policy(
org.omg.PortableServer.LifespanPolicyValue.PERSISTENT);
policies[1] =
rootPOA.create_id_assignment_policy(
org.omg.PortableServer.IdAssignmentPolicyValue.USER_ID);
rootContextPOA =
rootPOA.create_POA("RootContextPOA", manager, policies);
policies[1] =
rootPOA.create_id_assignment_policy(
org.omg.PortableServer.IdAssignmentPolicyValue.SYSTEM_ID);
contextPOA = rootPOA.create_POA("ContextPOA", manager, policies);
}
catch(org.omg.PortableServer.POAPackage.AdapterAlreadyExists ex)
{
}
catch(org.omg.PortableServer.POAPackage.InvalidPolicy ex)
{
}
com.ooc.OB.Assert.assert(rootContextPOA != null);
com.ooc.OB.Assert.assert(contextPOA != null);
for(int i = 0 ; i < args.length && args[i].startsWith("−") ; i++)
{
if(args[i].equals("−−help") || args[i].equals("−h"))
{
usage(progName);
return 0;
}
else if(args[i].equals("−−version") || args[i].equals("−v"))
{
System.err.println("ORBacus Names" +
com.ooc.OB.Version.version);
return 0;
}
else if(args[i].equals("−−ior") || args[i].equals("−i"))
{
ior = true;
}
else if(args[i].equals("−−no−updates") || args[i].equals("−n"))
{
options.noUpdates = true;
}
else if(args[i].equals("−−timeout") || args[i].equals("−t"))
{
++i;
if(i >= args.length)
{
System.err.println(progName + ": " + args[i − 1] +
"expects argument");
usage(progName);
return 1;
}
options.databaseTimeout = Integer.parseInt(args[i]);
}
else if(args[i].equals("−−callback−timeout") ||
args[i].equals("−c"))
{
++i;
if(i >= args.length)
{
System.err.println(progName + ": " + args[i − 1] +
"expects argument");
usage(progName);
return 1;
}
options.callbackTimeout = Integer.parseInt(args[i]);
}
else if(args[i].equals("−−database") ||
args[i].equals("−d"))
{
++i;
if(i >= args.length)
{
System.err.println(progName + ": " + args[i − 1] +
"expects argument");
usage(progName);
return 1;
}
options.databaseName = args[i];
}
else if(args[i].equals("−−start") || args[i].equals("−s"))
{
options.databaseExists = false;
}
else
{
System.err.println(progName + ": unknown option ‘"
+ args[i] + "’\n");
usage(progName);
return 1;
}
}
if(options.databaseTimeout <= 0)
{
System.err.println(progName + ": timeout value must be > 0");
return 1;
}
//
// Initialize the naming service.
//
NamingService namingService = new NamingService(orb, rootContextPOA,
contextPOA, options);
namingService.initialize();
c’est la racine
// du contexte de
// Get the root naming context. nommage
//
org.omg.CosNaming.NamingContext root =
namingService.rootNamingContext();
//
// Add reference to boot manager permet de mettre des associations dans les
// tables internes, accessibles ensuite par
try "orb.resolve_initial_reference".
{
byte[] oid = ("NameService").getBytes();
com.ooc.OB.BootManager bootManager =
com.ooc.OB.BootManagerHelper.narrow(
orb.resolve_initial_references("BootManager"));
bootManager.add_binding(oid, root);
}
catch(org.omg.CORBA.ORBPackage.InvalidName ex)
{
throw new RuntimeException();
}
catch(com.ooc.OB.BootManagerPackage.AlreadyExists ex)
{
throw new RuntimeException();
}
//
// Print IOR on standard output
//
if(ior)
{
System.out.println(orb.object_to_string(root));
}
//
// Run implementation
//
try
{
manager.activate();
}
catch(org.omg.PortableServer.POAManagerPackage.AdapterInactive ex)
{
throw new RuntimeException();
}
orb.run();
return 0;
}
int status = 0;
org.omg.CORBA.ORB orb = null;
//
// Set the program name
//
String progName = "com.ooc.CosNaming.Server";
try
{
args = com.ooc.OBCORBA.ORB_impl.ParseArgs(args, props, null);
//
// Check to see if the concurrency model is usable for nested
// method invocations. Threaded/thread_per_request/thread_pool
// is needed.
//
String oaModel = props.getProperty("ooc.orb.oa.conc_model");
String orbModel = props.getProperty("ooc.orb.conc_model");
boolean valid;
if (oaModel != null && orbModel != null)
{
valid = (orbModel.equals("threaded") &&
(oaModel.equals("thread_per_request") ||
oaModel.equals("thread_pool")));
}
else
valid = false;
//
// Set the concurrency model to threaded/threaded if a valid
// concurrency model wasn’t selected
//
if(!valid)
{
props.put("ooc.orb.conc_model", "threaded");
props.put("ooc.orb.oa.conc_model", "thread_per_request");
}
//
// Create ORB
//
orb = ORB.init(args, props);
status = run(orb, progName, args, props);
}
catch(Exception ex)
{
ex.printStackTrace();
status = 1;
}
if(orb != null)
{
try
{
((com.ooc.CORBA.ORB)orb).destroy();
}
catch(Exception ex)
{
ex.printStackTrace();
status = 1;
}
}
System.exit(status);
}
}
//////////////////////////////// Client.java ////////////////////////////////////////////////////////////////////////////////////////////////
package naming;
import org.omg.CORBA.*;
import org.omg.CosNaming.*;
import org.omg.CosNaming.NamingContextPackage.*;
// Run implementation
try { manager.activate(); }
catch(org.omg.PortableServer.POAManagerPackage.AdapterInactive ex) {
throw new RuntimeException();
}
orb.run();