bug 10449: handle the case when cluster servlet may be called during management server initialization phase

This commit is contained in:
Kelven Yang 2011-06-24 18:12:01 -07:00
parent 217ab1a851
commit f3d7d075ee

View File

@ -51,7 +51,14 @@ public class ClusterServiceServletAdapter implements ClusterServiceAdapter {
private int _clusterServicePort = DEFAULT_SERVICE_PORT;
@Override
public ClusterService getPeerService(String strPeer) throws RemoteException {
public ClusterService getPeerService(String strPeer) throws RemoteException {
try {
init();
} catch (ConfigurationException e) {
s_logger.error("Unable to init ClusterServiceServletAdapter");
throw new RemoteException("Unable to init ClusterServiceServletAdapter");
}
String serviceUrl = getServiceEndpointName(strPeer);
if(serviceUrl == null)
return null;
@ -61,6 +68,12 @@ public class ClusterServiceServletAdapter implements ClusterServiceAdapter {
@Override
public String getServiceEndpointName(String strPeer) {
try {
init();
} catch (ConfigurationException e) {
s_logger.error("Unable to init ClusterServiceServletAdapter");
return null;
}
long msid = Long.parseLong(strPeer);
@ -86,33 +99,10 @@ public class ClusterServiceServletAdapter implements ClusterServiceAdapter {
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
_name = name;
ComponentLocator locator = ComponentLocator.getCurrentLocator();
manager = locator.getManager(ClusterManager.class);
if(manager == null)
throw new ConfigurationException("Unable to get " + ClusterManager.class.getName());
_mshostDao = locator.getDao(ManagementServerHostDao.class);
if(_mshostDao == null)
throw new ConfigurationException("Unable to get " + ManagementServerHostDao.class.getName());
File dbPropsFile = PropertiesUtil.findConfigFile("db.properties");
Properties dbProps = new Properties();
try {
dbProps.load(new FileInputStream(dbPropsFile));
} catch (FileNotFoundException e) {
throw new ConfigurationException("Unable to find db.properties");
} catch (IOException e) {
throw new ConfigurationException("Unable to load db.properties content");
}
_clusterServicePort = NumbersUtil.parseInt(dbProps.getProperty("cluster.servlet.port"), DEFAULT_SERVICE_PORT);
if(s_logger.isInfoEnabled())
s_logger.info("Cluster servlet port : " + _clusterServicePort);
init();
return true;
}
}
@Override
public String getName() {
return _name;
@ -130,5 +120,34 @@ public class ClusterServiceServletAdapter implements ClusterServiceAdapter {
if(_servletContainer != null)
_servletContainer.stop();
return true;
}
}
private void init() throws ConfigurationException {
if(_mshostDao != null)
return;
ComponentLocator locator = ComponentLocator.getCurrentLocator();
manager = locator.getManager(ClusterManager.class);
if(manager == null)
throw new ConfigurationException("Unable to get " + ClusterManager.class.getName());
_mshostDao = locator.getDao(ManagementServerHostDao.class);
if(_mshostDao == null)
throw new ConfigurationException("Unable to get " + ManagementServerHostDao.class.getName());
File dbPropsFile = PropertiesUtil.findConfigFile("db.properties");
Properties dbProps = new Properties();
try {
dbProps.load(new FileInputStream(dbPropsFile));
} catch (FileNotFoundException e) {
throw new ConfigurationException("Unable to find db.properties");
} catch (IOException e) {
throw new ConfigurationException("Unable to load db.properties content");
}
_clusterServicePort = NumbersUtil.parseInt(dbProps.getProperty("cluster.servlet.port"), DEFAULT_SERVICE_PORT);
if(s_logger.isInfoEnabled())
s_logger.info("Cluster servlet port : " + _clusterServicePort);
}
}