如何在Java应用程序启动时知道Gigaspace已连接
我正在使用spring应用程序,我的gigaspace正在启动时连接。如果gigaspace宕机,我不会有任何例外如何在Java应用程序启动时知道Gigaspace已连接,java,gigaspaces,Java,Gigaspaces,我正在使用spring应用程序,我的gigaspace正在启动时连接。如果gigaspace宕机,我不会有任何例外 @Override public void onContextRefreshed(ContextRefreshedEvent event) { String gigaSpaceURL = null; LOGGER.info("({}) initializing gigaspaces client", getName());
@Override
public void onContextRefreshed(ContextRefreshedEvent event) {
String gigaSpaceURL = null;
LOGGER.info("({}) initializing gigaspaces client", getName());
try {
initGSProxy();
Iterator<Map.Entry<ConfiguredSpace, Space>> entries = spaces.entrySet().iterator();
while (entries.hasNext()) {
Map.Entry<ConfiguredSpace, Space> entry = entries.next();
LOGGER.info("({}) initialing space- key=" +
entry.getKey() + ", value = " + entry.getValue(),
getName());
// TODO : Need to verify Boolean Value Input
gigaspace.createSpace(entry.getKey().name(),
entry.getValue().getURL(), false);
gigaSpaceURL = entry.getValue().getURL();
}
} catch (Exception e) {
return;
}
GenericUtil.updateLogLevel("INFO",
"com.renovite.ripps.ap.gs.Spaces");
LOGGER.info("\n************************************\nConnected with Gigaspace successfully:URL:" + gigaSpaceURL
+ "\n************************************\n");
GenericUtil.updateLogLevel("ERROR",
"com.renovite.ripps.ap.gs.Spaces");
}
使用getGigaSpace方法引用Gigaspace,该方法将spacekey作为参数。如果在运行时引发异常,则表示应用程序无法连接到指定的Gigaspace url 或者更优雅的方式,在实际实现IGigaspace的Gigaspace代理类中,重写getGigaSpace方法,以便在无法连接时返回null /**空间*/ 私有瞬态映射空间=新HashMap @凌驾 公共GigaSpace getGigaSpaceString空格键{
if(spaces.get(spaceKey) != null){
return spaces.get(spaceKey).getGigaSpace();
}
return null;
}
spaces是向Gigapsace注册的所有URL的映射。如果没有注册任何URL,则在上述方法中返回null