Java Reference
In-Depth Information
(ix)
Wait for client calls .
Unlike our previous server programs, this is not achieved via an explicitly
'infi nite' loop. A call is made to method wait of (Java class) Object . This call
is isolated within a code block that is declared synchronized , as shown
below.
java.lang.Object syncObj = new java.lang.Object();
synchronized(syncObj)
{
syncObj.wait();
}
All of the above code will be contained in the server's main method. Since vari-
ous CORBA system exceptions may be generated, all the executable code will be
held within a try block.
Now for the full program…
import SimpleCORBAExample.*;
import org.omg.CosNaming.*;
import org.omg.CosNaming.NamingContextPackage.*;
import org.omg.CORBA.*;
public class HelloServer
{
public static void main(String[] args)
{
try
{
ORB orb = ORB.init(args,null);
HelloServant servant = new HelloServant();
orb.connect(servant);
org.omg.CORBA.Object objectRef =
orb.resolve_initial_references("NameService");
NamingContext namingContext =
NamingContextHelper.narrow(objectRef);
NameComponent nameComp =
new NameComponent("Hello", "");
NameComponent[] path = {nameComp};
namingContext.rebind(path,servant);
java.lang.Object syncObj =
new java.lang.Object();
synchronized(syncObj)
Search WWH ::




Custom Search