0

我正在使用 spring 应用程序,我的 gigaspace 在启动时正在连接。如果 gigaspace 关闭,我没有任何例外。

@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");

     }
4

1 回答 1

1

使用 getGigaSpace() 方法引用 Gigaspace,该方法以 spacekey 作为参数。如果在运行时抛出异常,则表示应用程序无法连接到指定的 Gigaspace url。

或者更优雅的方式,在您的 Gigaspace 代理类(实际上实现 IGigaspace)中覆盖 getGigaSpace() 方法,以便在无法连接时返回 null。

/** 空格。*/ 私有瞬态映射空间 = new HashMap<>();

@Override public GigaSpace getGigaSpace(String spaceKey) {

    if(spaces.get(spaceKey) != null){
        return spaces.get(spaceKey).getGigaSpace();
    }
  return null;
}

空格是在 Gigapsace 注册的所有 url 的 Map。如果没有人注册,我们在上面的方法中返回 null。

于 2017-01-13T08:56:22.687 回答