Hello,
In my program, I create one NamingContextExt obj (one connection to
orbix naming server), and from that point, every object I need to
resolve - I use the same NamingContextExt.
My question: how can I know if the naming context reference is up and
valid, or if there is a communication problem and it is down?
Can I perforn a test to check the validity of the NamingContextExt
before I return the ncRef object? Are there a built in functions?
Is there some kind of special exception?
Thanks,
Asaf
P.S
My singleton which hold the NamingContextExt is:
package com.comverse.tcm.SCEConnector;
import com.comverse.tcm.vfit.ConfLoader;
import org.omg.CORBA.ORB;
import org.omg.CORBA.ShortHolder;
import org.omg.CORBA.StringHolder;
import org.omg.CORBA.UserException;
import org.omg.CosNaming.NameComponent;
import org.omg.CosNaming.NamingContextExt;
import org.omg.CosNaming.NamingContextExtHelper;
import org.omg.CosNaming.NamingContextPackage.*;
import SCE.VsCollector;
import SCE.VsCollectorHelper;
import com.comverse.model.Event;
import com.comverse.model.KeyModel;
import com.comverse.model.KeyModelInterface;
import com.comverse.model.Listener;
import com.comverse.cap.cifs.log.LogWriterIfc;
import com.comverse.cap.cifs.log.LogWriter;
public class NamingServiceHolder {
private LogWriterIfc log =
LogWriter.getInstance(NamingServiceHolder.class);/* logger */
private ConfLoader conf = null;
private boolean isConnected;
private static NamingServiceHolder instance = null;
private static NamingContextExt ncRef = null;
private NamingServiceHolder() {
isConnected = false;
conf = ConfLoader.getInstance();
log.debug("Got new NamingServiceHolder");
}
public static NamingServiceHolder getInstance() {
if (instance == null) {
instance = new NamingServiceHolder();
}
return instance;
}
public boolean connect() {
log.debug("Connecting to ORBIX server");
String version = conf.getNamingServiceVersion();
String ip = conf.getNamingServiceIP();
int port = conf.getNamingServicePort();
String namingServiceName = conf.getNamingServiceName();
// create and initialize the ORB
String[] array = null;
ORB orb = ORB.init(array, null);
// get the root naming context
StringBuffer sb = new StringBuffer();
sb.append("corbaloc:iiop:").append(version).append('@[EMAIL PROTECTED]
').append(ip).append(':').append(port).append('/').append(namingServiceName);
String corbalocStr = sb.toString();
log.debug("corbaloc String: " + corbalocStr);
try {
org.omg.CORBA.Object objRef = orb.string_to_object(corbalocStr);
if(objRef == null) {
log.error("Could not get object of the NamingService");
isConnected = false;
return false;
}
ncRef = NamingContextExtHelper.narrow(objRef);
log.debug("Got handle to the naming service, found ORBD");
isConnected = true;
return true;
}
catch (org.omg.CORBA.COMM_FAILURE cf) {
log.error("Communication failure (probably problem with the
naming service): " + cf.toString());
isConnected = false;
return false;
}
}
public NamingContextExt getNcRef() {
return ncRef;
}
public boolean getIsConnected() {
return isConnected;
}
}


|