如何知道Gigaspace在启动时在Java应用程序中连接

时间:2017-01-12 10:09:19

标签: java gigaspaces

我正在使用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");

     }

1 个答案:

答案 0 :(得分:1)

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

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

/ **空格。 * /     private transient Map spaces = new HashMap&lt;&gt;();

@覆盖     public GigaSpace getGigaSpace(String spaceKey){

format_spec

spaces是在Gigapsace注册的所有网址的地图。如果没有人注册,我们在上述方法中返回null。