【Java开源代码栏目提醒】:网学会员,鉴于大家对Java开源代码十分关注,论文会员在此为大家搜集整理了“WatchValue.java”一文,供大家参考学习!
import Registry.*;
import org.omg.CosNaming.*;
import org.omg.CORBA.*;
public class WatchValue
{
public static void main(String args[])
{
try
{
// create and initialize the ORB
ORB orb = ORB.init(args, null);
// get the root naming context
org.omg.CORBA.Object objRef =
orb.resolve_initial_references("NameService");
NamingContext ncRef = NamingContextHelper.narrow(objRef);
// resolve the Object Reference in Naming
NameComponent nc = new NameComponent("StringRegistry", "");
NameComponent path[] = {nc};
StringRegistry registryRef = StringRegistryHelper.narrow(ncRef.resolve(path));
//Create a watcher and register them
MyWatcher watcher = new MyWatcher();
orb.connect(watcher);//Optional for some ORBs, as it will happen implicitly
registryRef.registerWatcher(watcher);
// wait for invocations from clients
java.lang.Object sync = new java.lang.Object();
synchronized (sync)
{
sync.wait();
}
}
catch (Exception e)
{
e.printStackTrace(System.out);
}
}
}