summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDwayne Boone <dwayne@zeroc.com>2014-09-25 13:18:48 -0230
committerDwayne Boone <dwayne@zeroc.com>2014-09-25 13:18:48 -0230
commit9a5bfaa13d31b346f1fbbf6de1be2ef1e657e92e (patch)
tree5932a0fca63b0cad86c9adcb45f8a03c4ed14c1c
parentFixed again ICE-5687 - adapterDeactivation test warnings (diff)
downloadice-9a5bfaa13d31b346f1fbbf6de1be2ef1e657e92e.tar.bz2
ice-9a5bfaa13d31b346f1fbbf6de1be2ef1e657e92e.tar.xz
ice-9a5bfaa13d31b346f1fbbf6de1be2ef1e657e92e.zip
ICE-5611 on RouterFinder failure use default identity rather than failing
-rw-r--r--cpp/include/Glacier2/SessionHelper.h2
-rw-r--r--cpp/src/Glacier2Lib/SessionHelper.cpp213
-rw-r--r--cs/src/Glacier2/SessionFactoryHelper.cs117
-rw-r--r--cs/src/Glacier2/SessionHelper.cs94
-rw-r--r--cs/test/Glacier2/sessionHelper/Client.cs1
-rw-r--r--java/src/Glacier2/SessionFactoryHelper.java117
-rw-r--r--java/src/Glacier2/SessionHelper.java83
7 files changed, 285 insertions, 342 deletions
diff --git a/cpp/include/Glacier2/SessionHelper.h b/cpp/include/Glacier2/SessionHelper.h
index 8ecbaffba10..199589bb3da 100644
--- a/cpp/include/Glacier2/SessionHelper.h
+++ b/cpp/include/Glacier2/SessionHelper.h
@@ -97,6 +97,8 @@ public:
private:
Ice::InitializationData createInitData();
+ std::string getRouterFinderStr();
+ std::string createProxyStr(const Ice::Identity& ident);
void setDefaultProperties();
IceUtil::Mutex _mutex;
diff --git a/cpp/src/Glacier2Lib/SessionHelper.cpp b/cpp/src/Glacier2Lib/SessionHelper.cpp
index e5ed66dc296..55bf73f1c21 100644
--- a/cpp/src/Glacier2Lib/SessionHelper.cpp
+++ b/cpp/src/Glacier2Lib/SessionHelper.cpp
@@ -59,7 +59,7 @@ class SessionHelperI : public Glacier2::SessionHelper
public:
- SessionHelperI(const Glacier2::SessionCallbackPtr&, const Ice::InitializationData&);
+ SessionHelperI(const Glacier2::SessionCallbackPtr&, const Ice::InitializationData&, const string&);
void destroy();
Ice::CommunicatorPtr communicator() const;
std::string categoryForClient() const;
@@ -89,8 +89,6 @@ private:
void dispatchCallback(const Ice::DispatcherCallPtr&, const Ice::ConnectionPtr&);
void dispatchCallbackAndWait(const Ice::DispatcherCallPtr&, const Ice::ConnectionPtr&);
- void finderCompleted(const Ice::AsyncResultPtr& result);
-
IceUtil::Mutex _mutex;
Ice::CommunicatorPtr _communicator;
Ice::ObjectAdapterPtr _adapter;
@@ -101,6 +99,7 @@ private:
bool _destroy;
const Ice::InitializationData _initData;
const Glacier2::SessionCallbackPtr _callback;
+ const string _finderStr;
};
typedef IceUtil::Handle<SessionHelperI> SessionHelperIPtr;
@@ -168,11 +167,13 @@ private:
}
SessionHelperI::SessionHelperI(const Glacier2::SessionCallbackPtr& callback,
- const Ice::InitializationData& initData) :
+ const Ice::InitializationData& initData,
+ const string& finderStr) :
_connected(false),
_destroy(false),
_initData(initData),
- _callback(callback)
+ _callback(callback),
+ _finderStr(finderStr)
{
}
@@ -501,17 +502,38 @@ class ConnectThread : public IceUtil::Thread
public:
ConnectThread(const Glacier2::SessionCallbackPtr& callback, const SessionHelperIPtr& session,
- const ConnectStrategyPtr& factory, const Ice::CommunicatorPtr& communicator) :
+ const ConnectStrategyPtr& factory, const Ice::CommunicatorPtr& communicator,
+ const Ice::RouterFinderPrx& finder) :
_callback(callback),
_session(session),
_factory(factory),
- _communicator(communicator)
+ _communicator(communicator),
+ _finder(finder)
{
}
virtual void
run()
{
+ if(!_communicator->getDefaultRouter())
+ {
+ try
+ {
+ _communicator->setDefaultRouter(_finder->getRouter());
+ }
+ catch(const Ice::Exception& ex)
+ {
+ //
+ // In case of error getting router identity from RouterFinder use
+ // default identity.
+ //
+ Ice::Identity ident;
+ ident.category = "Glacier2";
+ ident.name = "router";
+ _communicator->setDefaultRouter(Ice::RouterPrx::uncheckedCast(_finder->ice_identity(ident)));
+ }
+ }
+
try
{
_session->dispatchCallbackAndWait(new CreatedCommunicator(_callback, _session), 0);
@@ -539,6 +561,7 @@ private:
const SessionHelperIPtr _session;
const ConnectStrategyPtr _factory;
const Ice::CommunicatorPtr _communicator;
+ const Ice::RouterFinderPrx _finder;
};
@@ -586,36 +609,8 @@ SessionHelperI::connectImpl(const ConnectStrategyPtr& factory)
return;
}
- if(_communicator->getDefaultRouter())
- {
- IceUtil::ThreadPtr connectThread = new ConnectThread(_callback, this, factory, _communicator);
- connectThread->start().detach();
- }
- else
- {
- Ice::RouterFinderPrx finder = Ice::RouterFinderPrx::uncheckedCast(
- _communicator->stringToProxy(_communicator->getProperties()->getProperty("SessionHelper.RouterFinder")));
- finder->begin_getRouter(Ice::newCallback(this, &SessionHelperI::finderCompleted), factory);
- }
-}
-
-void
-SessionHelperI::finderCompleted(const Ice::AsyncResultPtr& result)
-{
- try
- {
- Ice::RouterPrx router = Ice::RouterFinderPrx::uncheckedCast(result->getProxy())->end_getRouter(result);
- _communicator->setDefaultRouter(router);
- }
- catch(const Ice::Exception& ex)
- {
- connectFailed();
- dispatchCallback(new ConnectFailed(_callback, this, ex), 0);
- return;
- }
-
- ConnectStrategyPtr factory = ConnectStrategyPtr::dynamicCast(result->getCookie());
- IceUtil::ThreadPtr connectThread = new ConnectThread(_callback, this, factory, _communicator);
+ Ice::RouterFinderPrx finder = Ice::RouterFinderPrx::uncheckedCast(_communicator->stringToProxy(_finderStr));
+ IceUtil::ThreadPtr connectThread = new ConnectThread(_callback, this, factory, _communicator, finder);
connectThread->start().detach();
}
@@ -755,7 +750,6 @@ SessionHelperI::dispatchCallback(const Ice::DispatcherCallPtr& call, const Ice::
{
call->run();
}
-
}
namespace
@@ -935,7 +929,7 @@ Glacier2::SessionHelperPtr
Glacier2::SessionFactoryHelper::connect()
{
IceUtil::Mutex::Lock sync(_mutex);
- SessionHelperIPtr session = new SessionHelperI(_callback, createInitData());
+ SessionHelperIPtr session = new SessionHelperI(_callback, createInitData(), getRouterFinderStr());
session->connect(_context);
return session;
}
@@ -944,7 +938,7 @@ Glacier2::SessionHelperPtr
Glacier2::SessionFactoryHelper::connect(const string& user, const string& password)
{
IceUtil::Mutex::Lock sync(_mutex);
- SessionHelperIPtr session = new SessionHelperI(_callback, createInitData());
+ SessionHelperIPtr session = new SessionHelperI(_callback, createInitData(), getRouterFinderStr());
session->connect(user, password, _context);
return session;
}
@@ -958,86 +952,89 @@ Glacier2::SessionFactoryHelper::createInitData()
Ice::InitializationData initData = _initData;
initData.properties = initData.properties->clone();
- if(initData.properties->getProperty("Ice.Default.Router").size() == 0)
+ if(initData.properties->getProperty("Ice.Default.Router").size() == 0 && !_identity.name.empty())
{
- ostringstream os;
- os << "\"";
+ initData.properties->setProperty("Ice.Default.Router", createProxyStr(_identity));
+ }
- //
- // TODO replace with identityToString, we cannot use the Communicator::identityToString
- // current implementation because we need to do that before the communicator has been
- // initialized.
- //
- bool useFinder = _identity.category.empty() && _identity.name.empty();
- if(useFinder)
- {
- os << "Ice/RouterFinder";
- }
- else
- {
- if(!_identity.category.empty())
- {
- os << _identity.category << "/";
- }
- os << _identity.name;
- }
+#ifndef ICE_OS_WINRT
+ //
+ // 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").empty())
+ {
+ initData.properties->setProperty("Ice.Plugin.IceSSL","IceSSL:createIceSSL");
+ }
+#endif
- os << "\"";
- os << ":";
- if(_secure)
- {
- os << "ssl -p ";
- }
- else
- {
- os << "tcp -p ";
- }
+ return initData;
+}
- if(_port != 0)
- {
- os << _port;
- }
- else
- {
- if(_secure)
- {
- os << GLACIER2_SSL_PORT;
- }
- else
- {
- os << GLACIER2_TCP_PORT;
- }
- }
+string
+Glacier2::SessionFactoryHelper::getRouterFinderStr()
+{
+ Ice::Identity ident;
+ ident.category = "Ice";
+ ident.name = "RouterFinder";
- os << " -h ";
- os << _routerHost;
- if(_timeout > 0)
- {
- os << " -t ";
- os << _timeout;
- }
+ return createProxyStr(ident);
+}
+
+string
+Glacier2::SessionFactoryHelper::createProxyStr(const Ice::Identity& ident)
+{
+ ostringstream os;
+ os << "\"";
- if(useFinder)
+ //
+ // TODO replace with identityToString, we cannot use the Communicator::identityToString
+ // current implementation because we need to do that before the communicator has been
+ // initialized.
+ //
+ if(!ident.category.empty())
+ {
+ os << ident.category << "/";
+ }
+ os << ident.name;
+
+ os << "\"";
+ os << ":";
+ if(_secure)
+ {
+ os << "ssl -p ";
+ }
+ else
+ {
+ os << "tcp -p ";
+ }
+
+ if(_port != 0)
+ {
+ os << _port;
+ }
+ else
+ {
+ if(_secure)
{
- initData.properties->setProperty("SessionHelper.RouterFinder", os.str());
+ os << GLACIER2_SSL_PORT;
}
else
{
- initData.properties->setProperty("Ice.Default.Router", os.str());
+ os << GLACIER2_TCP_PORT;
}
-#ifndef ICE_OS_WINRT
- //
- // 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").empty())
- {
- initData.properties->setProperty("Ice.Plugin.IceSSL","IceSSL:createIceSSL");
- }
-#endif
}
- return initData;
+
+ os << " -h ";
+ os << _routerHost;
+ if(_timeout > 0)
+ {
+ os << " -t ";
+ os << _timeout;
+ }
+
+ return os.str();
}
void
diff --git a/cs/src/Glacier2/SessionFactoryHelper.cs b/cs/src/Glacier2/SessionFactoryHelper.cs
index ff5afacfc44..5dcfd254420 100644
--- a/cs/src/Glacier2/SessionFactoryHelper.cs
+++ b/cs/src/Glacier2/SessionFactoryHelper.cs
@@ -247,7 +247,7 @@ public class SessionFactoryHelper
{
lock(this)
{
- SessionHelper session = new SessionHelper(_callback, createInitData());
+ SessionHelper session = new SessionHelper(_callback, createInitData(), getRouterFinderStr());
session.connect(_context);
return session;
}
@@ -268,7 +268,7 @@ public class SessionFactoryHelper
{
lock(this)
{
- SessionHelper session = new SessionHelper(_callback, createInitData());
+ SessionHelper session = new SessionHelper(_callback, createInitData(), getRouterFinderStr());
session.connect(username, password, _context);
return session;
}
@@ -283,71 +283,72 @@ public class SessionFactoryHelper
Ice.InitializationData initData = (Ice.InitializationData)_initData.Clone();
initData.properties = initData.properties.ice_clone_();
- if(initData.properties.getProperty("Ice.Default.Router").Length == 0)
+ if(initData.properties.getProperty("Ice.Default.Router").Length == 0 && _identity != null)
+ {
+ initData.properties.setProperty("Ice.Default.Router", createProxyStr(_identity));
+ }
+
+ //
+ // 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:IceSSL.PluginFactory");
+ }
+
+ return initData;
+ }
+
+ private string
+ getRouterFinderStr()
+ {
+ Ice.Identity ident = new Ice.Identity("RouterFinder", "Ice");
+ return createProxyStr(ident);
+ }
+
+ private string
+ createProxyStr(Ice.Identity ident)
+ {
+ StringBuilder sb = new StringBuilder();
+ sb.Append("\"");
+ sb.Append(Ice.Util.identityToString(ident));
+ sb.Append("\"");
+ sb.Append(":");
+ if(_secure)
+ {
+ sb.Append("ssl -p ");
+ }
+ else
+ {
+ sb.Append("tcp -p ");
+ }
+ if(_port != 0)
+ {
+ sb.Append(_port);
+ }
+ else
{
- bool useFinder = _identity == null;
- StringBuilder sb = new StringBuilder();
- sb.Append("\"");
- if(useFinder)
- {
- sb.Append("Ice/RouterFinder");
- }
- else
- {
- sb.Append(Ice.Util.identityToString(_identity));
- }
- sb.Append("\"");
- sb.Append(":");
if(_secure)
{
- sb.Append("ssl -p ");
+ sb.Append(GLACIER2_SSL_PORT);
}
else
{
- sb.Append("tcp -p ");
- }
- if(_port != 0)
- {
- sb.Append(_port);
- }
- else
- {
- if(_secure)
- {
- sb.Append(GLACIER2_SSL_PORT);
- }
- else
- {
- sb.Append(GLACIER2_TCP_PORT);
- }
+ sb.Append(GLACIER2_TCP_PORT);
}
+ }
- sb.Append(" -h ");
- sb.Append(_routerHost);
- if(_timeout > 0)
- {
- sb.Append(" -t ");
- sb.Append(_timeout);
- }
- if(useFinder)
- {
- initData.properties.setProperty("SessionHelper.RouterFinder", sb.ToString());
- }
- 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:IceSSL.PluginFactory");
- }
+ sb.Append(" -h ");
+ sb.Append(_routerHost);
+ if(_timeout > 0)
+ {
+ sb.Append(" -t ");
+ sb.Append(_timeout);
}
- return initData;
+
+ return sb.ToString();
}
private void
diff --git a/cs/src/Glacier2/SessionHelper.cs b/cs/src/Glacier2/SessionHelper.cs
index 226389f75d2..abd41c7fa14 100644
--- a/cs/src/Glacier2/SessionHelper.cs
+++ b/cs/src/Glacier2/SessionHelper.cs
@@ -78,10 +78,11 @@ public class SessionHelper
/// establishment.</param>
/// <param name="initData">The Ice.InitializationData for initializing
/// the communicator.</param>
- public SessionHelper(SessionCallback callback, Ice.InitializationData initData)
+ public SessionHelper(SessionCallback callback, Ice.InitializationData initData, string finderStr)
{
_callback = callback;
_initData = initData;
+ _finderStr = finderStr;
}
/// <summary>
@@ -437,71 +438,51 @@ public class SessionHelper
return;
}
- if(_communicator.getDefaultRouter() != null)
- {
- completeConnect(factory);
- }
- else
+ Ice.RouterFinderPrx finder = Ice.RouterFinderPrxHelper.uncheckedCast(_communicator.stringToProxy(_finderStr));
+ new Thread(new ThreadStart(() =>
{
- Ice.RouterFinderPrx finder = Ice.RouterFinderPrxHelper.uncheckedCast(
- _communicator.stringToProxy(_communicator.getProperties().getProperty("SessionHelper.RouterFinder")));
- finder.begin_getRouter().whenCompleted(
- (Ice.RouterPrx router) =>
+ if(_communicator.getDefaultRouter() == null)
+ {
+ try
{
- _communicator.setDefaultRouter(router);
- completeConnect(factory);
- },
- (Ice.Exception ex) =>
+ _communicator.setDefaultRouter(finder.getRouter());
+ }
+ catch(Exception)
{
- new Thread(new ThreadStart(() =>
+ // 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(() =>
{
- try
- {
- _communicator.destroy();
- }
- catch(Exception)
- {
- }
- dispatchCallback(() =>
- {
- _callback.connectFailed(this, ex);
- }, null);
- })).Start();
- });
- }
- }
+ _callback.createdCommunicator(this);
+ });
- private void
- completeConnect(ConnectStrategy factory)
- {
- new Thread(new ThreadStart(() =>
- {
+ Glacier2.RouterPrx routerPrx = Glacier2.RouterPrxHelper.uncheckedCast(
+ _communicator.getDefaultRouter());
+ Glacier2.SessionPrx session = factory(routerPrx);
+ connected(routerPrx, session);
+ }
+ catch(Exception ex)
+ {
try
{
- dispatchCallbackAndWait(() =>
- {
- _callback.createdCommunicator(this);
- });
-
- Glacier2.RouterPrx routerPrx = Glacier2.RouterPrxHelper.uncheckedCast(
- _communicator.getDefaultRouter());
- Glacier2.SessionPrx session = factory(routerPrx);
- connected(routerPrx, session);
+ _communicator.destroy();
}
- catch (Exception ex)
+ catch(Exception)
{
- try
- {
- _communicator.destroy();
- }
- catch(Exception)
- {
- }
- dispatchCallback(() =>
- {
- _callback.connectFailed(this, ex);
- }, null);
}
+ dispatchCallback(() =>
+ {
+ _callback.connectFailed(this, ex);
+ }, null);
+ }
})).Start();
}
@@ -554,6 +535,7 @@ public class SessionHelper
private Glacier2.SessionPrx _session;
private bool _connected = false;
private string _category;
+ private string _finderStr;
private readonly SessionCallback _callback;
private bool _destroy = false;
diff --git a/cs/test/Glacier2/sessionHelper/Client.cs b/cs/test/Glacier2/sessionHelper/Client.cs
index 867cc87151c..5652d8080d4 100644
--- a/cs/test/Glacier2/sessionHelper/Client.cs
+++ b/cs/test/Glacier2/sessionHelper/Client.cs
@@ -179,6 +179,7 @@ public class Client
Console.Out.Write("testing SessionHelper connect with wrong userid/password... ");
Console.Out.Flush();
+ _factory.setSecure(false);
_session = _factory.connect("userid", "xxx");
while(true)
{
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;