diff options
author | Dwayne Boone <dwayne@zeroc.com> | 2014-09-25 13:18:48 -0230 |
---|---|---|
committer | Dwayne Boone <dwayne@zeroc.com> | 2014-09-25 13:18:48 -0230 |
commit | 9a5bfaa13d31b346f1fbbf6de1be2ef1e657e92e (patch) | |
tree | 5932a0fca63b0cad86c9adcb45f8a03c4ed14c1c /java | |
parent | Fixed again ICE-5687 - adapterDeactivation test warnings (diff) | |
download | ice-9a5bfaa13d31b346f1fbbf6de1be2ef1e657e92e.tar.bz2 ice-9a5bfaa13d31b346f1fbbf6de1be2ef1e657e92e.tar.xz ice-9a5bfaa13d31b346f1fbbf6de1be2ef1e657e92e.zip |
ICE-5611 on RouterFinder failure use default identity rather than failing
Diffstat (limited to 'java')
-rw-r--r-- | java/src/Glacier2/SessionFactoryHelper.java | 117 | ||||
-rw-r--r-- | java/src/Glacier2/SessionHelper.java | 83 |
2 files changed, 80 insertions, 120 deletions
diff --git a/java/src/Glacier2/SessionFactoryHelper.java b/java/src/Glacier2/SessionFactoryHelper.java index 474acf3dca7..dc7f7beec0e 100644 --- a/java/src/Glacier2/SessionFactoryHelper.java +++ b/java/src/Glacier2/SessionFactoryHelper.java @@ -237,7 +237,7 @@ public class SessionFactoryHelper synchronized public SessionHelper connect() { - SessionHelper session = new SessionHelper(_callback, createInitData()); + SessionHelper session = new SessionHelper(_callback, createInitData(), getRouterFinderStr()); session.connect(_context); return session; } @@ -255,7 +255,7 @@ public class SessionFactoryHelper synchronized public SessionHelper connect(final String username, final String password) { - SessionHelper session = new SessionHelper(_callback, createInitData()); + SessionHelper session = new SessionHelper(_callback, createInitData(), getRouterFinderStr()); session.connect(username, password, _context); return session; } @@ -269,75 +269,74 @@ public class SessionFactoryHelper Ice.InitializationData initData = (Ice.InitializationData)_initData.clone(); initData.properties = initData.properties._clone(); - if(initData.properties.getProperty("Ice.Default.Router").length() == 0) + if(initData.properties.getProperty("Ice.Default.Router").length() == 0 && _identity != null) { - boolean useFinder = _identity == null; + initData.properties.setProperty("Ice.Default.Router", getProxyStr(_identity)); + } - StringBuffer sb = new StringBuffer(); - sb.append("\""); - if(useFinder) - { - sb.append("Ice/RouterFinder"); - } - else - { - sb.append(Ice.Util.identityToString(_identity)); - } - sb.append("\""); - sb.append(":"); + // + // If using a secure connection setup the IceSSL plug-in, if IceSSL + // plug-in has already been setup we don't want to override the + // configuration so it can be loaded from a custom location. + // + if(_secure && initData.properties.getProperty("Ice.Plugin.IceSSL").length() == 0) + { + initData.properties.setProperty("Ice.Plugin.IceSSL", "IceSSL.PluginFactory"); + } - if(_secure) - { - sb.append("ssl -p "); - } - else - { - sb.append("tcp -p "); - } + return initData; + } - if(_port != 0) - { - sb.append(_port); - } - else - { - if(_secure) - { - sb.append(GLACIER2_SSL_PORT); - } - else - { - sb.append(GLACIER2_TCP_PORT); - } - } + private String + getRouterFinderStr() + { + Ice.Identity ident = new Ice.Identity("RouterFinder", "Ice"); + return getProxyStr(ident); + } - sb.append(" -h "); - sb.append(_routerHost); - if(_timeout > 0) - { - sb.append(" -t "); - sb.append(_timeout); - } + private String + getProxyStr(Ice.Identity ident) + { + StringBuffer sb = new StringBuffer(); + sb.append("\""); + sb.append(Ice.Util.identityToString(ident)); + sb.append("\""); + sb.append(":"); + + if(_secure) + { + sb.append("ssl -p "); + } + else + { + sb.append("tcp -p "); + } - if(useFinder) + if(_port != 0) + { + sb.append(_port); + } + else + { + if(_secure) { - initData.properties.setProperty("SessionHelper.RouterFinder", sb.toString()); + sb.append(GLACIER2_SSL_PORT); } else { - initData.properties.setProperty("Ice.Default.Router", sb.toString()); - } - // - // If using a secure connection setup the IceSSL plug-in, if IceSSL - // plug-in has already been setup we don't want to override the - // configuration so it can be loaded from a custom location. - // - if(_secure && initData.properties.getProperty("Ice.Plugin.IceSSL").length() == 0) - { - initData.properties.setProperty("Ice.Plugin.IceSSL", "IceSSL.PluginFactory"); + sb.append(GLACIER2_TCP_PORT); } } - return initData; + + sb.append(" -h "); + sb.append(_routerHost); + if(_timeout > 0) + { + sb.append(" -t "); + sb.append(_timeout); + } + + return sb.toString(); } private SessionCallback _callback; diff --git a/java/src/Glacier2/SessionHelper.java b/java/src/Glacier2/SessionHelper.java index 49709b47a8d..30b9f2aa616 100644 --- a/java/src/Glacier2/SessionHelper.java +++ b/java/src/Glacier2/SessionHelper.java @@ -42,10 +42,11 @@ public class SessionHelper * @param callback The callback for notifications about session establishment. * @param initData The {@link Ice.InitializationData} for initializing the communicator. */ - public SessionHelper(SessionCallback callback, Ice.InitializationData initData) + public SessionHelper(SessionCallback callback, Ice.InitializationData initData, String finderStr) { _callback = callback; _initData = initData; + _finderStr = finderStr; } /** @@ -501,71 +502,30 @@ public class SessionHelper return; } - if(_communicator.getDefaultRouter() != null) - { - completeConnect(factory); - } - else - { - Ice.RouterFinderPrx finder = Ice.RouterFinderPrxHelper.uncheckedCast( - _communicator.stringToProxy(_communicator.getProperties().getProperty("SessionHelper.RouterFinder"))); - finder.begin_getRouter(new Ice.Callback() - { - @Override - public void completed(Ice.AsyncResult result) - { - try - { - Ice.RouterPrx router = - Ice.RouterFinderPrxHelper.uncheckedCast( - result.getProxy()).end_getRouter(result); - _communicator.setDefaultRouter(router); - } - catch(final Ice.Exception ex) - { - Ice.Communicator communicator = null; - synchronized(SessionHelper.this) - { - communicator = _communicator; - _communicator = null; - } - - if(communicator != null) - { - try - { - communicator.destroy(); - } - catch(Throwable ex1) - { - } - } - - dispatchCallback(new Runnable() - { - @Override - public void run() - { - _callback.connectFailed(SessionHelper.this, ex); - } - }, null); - return; - } - - completeConnect(factory); - } - }); - } - } - - private void - completeConnect(final ConnectStrategy factory) - { + final Ice.RouterFinderPrx finder = + Ice.RouterFinderPrxHelper.uncheckedCast(_communicator.stringToProxy(_finderStr)); new Thread(new Runnable() { @Override public void run() { + if(_communicator.getDefaultRouter() == null) + { + try + { + _communicator.setDefaultRouter(finder.getRouter()); + } + catch(Exception ex) + { + // + // In case of error getting router identity from RouterFinder use + // default identity. + // + Ice.Identity ident = new Ice.Identity("router", "Glacier2"); + _communicator.setDefaultRouter(Ice.RouterPrxHelper.uncheckedCast(finder.ice_identity(ident))); + } + } + try { dispatchCallbackAndWait(new Runnable() @@ -650,6 +610,7 @@ public class SessionHelper private Glacier2.RouterPrx _router; private Glacier2.SessionPrx _session; private String _category; + private String _finderStr; private final SessionCallback _callback; private boolean _destroy = false; |