diff options
Diffstat (limited to 'java')
-rw-r--r-- | java/src/Glacier2/SessionFactoryHelper.java | 32 | ||||
-rw-r--r-- | java/src/Glacier2/SessionHelper.java | 60 | ||||
-rw-r--r-- | java/test/Glacier2/sessionHelper/Client.java | 7 |
3 files changed, 85 insertions, 14 deletions
diff --git a/java/src/Glacier2/SessionFactoryHelper.java b/java/src/Glacier2/SessionFactoryHelper.java index 120b55a59bf..474acf3dca7 100644 --- a/java/src/Glacier2/SessionFactoryHelper.java +++ b/java/src/Glacier2/SessionFactoryHelper.java @@ -11,7 +11,7 @@ package Glacier2; /** * A helper class for using Glacier2 with GUI applications. - * + * * Applications should create a session factory for each Glacier2 router to which the application will * connect. To connect with the Glacier2 router, call {@link SessionFactory#connect}. The callback object is * notified of the various life cycle events. Once the session is torn down for whatever reason, the application @@ -21,7 +21,7 @@ public class SessionFactoryHelper { /** * Creates a SessionFactory object. - * + * * @param callback The callback object for notifications. * @throws {@link Ice.InitializationException} */ @@ -34,7 +34,7 @@ public class SessionFactoryHelper /** * Creates a SessionFactory object. - * + * * @param initData The initialization data to use when creating the communicator. * @param callback The callback object for notifications. * @throws {@link Ice.InitializationException} @@ -246,8 +246,8 @@ public class SessionFactoryHelper * Connect the Glacier2 session using user name and password credentials. * * Once the connection is established, {@link SessionCallback#connected} is called on the callback object; - * upon failure, {@link SessionCallback#connectFailed) is called with the exception. - * + * upon failure, {@link SessionCallback#connectFailed) is called with the exception. + * * @param username The user name. * @param password The password. * @return The connected session. @@ -271,9 +271,18 @@ public class SessionFactoryHelper if(initData.properties.getProperty("Ice.Default.Router").length() == 0) { + boolean useFinder = _identity == null; + StringBuffer sb = new StringBuffer(); sb.append("\""); - sb.append(Ice.Util.identityToString(_identity)); + if(useFinder) + { + sb.append("Ice/RouterFinder"); + } + else + { + sb.append(Ice.Util.identityToString(_identity)); + } sb.append("\""); sb.append(":"); @@ -310,7 +319,14 @@ public class SessionFactoryHelper sb.append(_timeout); } - initData.properties.setProperty("Ice.Default.Router", sb.toString()); + 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 @@ -327,7 +343,7 @@ public class SessionFactoryHelper private SessionCallback _callback; private String _routerHost = "localhost"; private Ice.InitializationData _initData; - private Ice.Identity _identity = new Ice.Identity("router", "Glacier2"); + private Ice.Identity _identity = null; private boolean _secure = true; private int _port = 0; private int _timeout = 10000; diff --git a/java/src/Glacier2/SessionHelper.java b/java/src/Glacier2/SessionHelper.java index 2ea89487044..49709b47a8d 100644 --- a/java/src/Glacier2/SessionHelper.java +++ b/java/src/Glacier2/SessionHelper.java @@ -501,6 +501,66 @@ 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) + { new Thread(new Runnable() { @Override diff --git a/java/test/Glacier2/sessionHelper/Client.java b/java/test/Glacier2/sessionHelper/Client.java index faaf05536a3..f61f84d0051 100644 --- a/java/test/Glacier2/sessionHelper/Client.java +++ b/java/test/Glacier2/sessionHelper/Client.java @@ -108,10 +108,6 @@ public class Client extends test.Util.Application out.print("testing SessionHelper connect with wrong userid/password... "); out.flush(); - _factory.setRouterHost("127.0.0.1"); - _factory.setPort(12347); - _factory.setRouterIdentity(Ice.Util.stringToIdentity("Glacier2/router")); - _factory.setSecure(false); _session = _factory.connect("userid", "xxx"); while(true) { @@ -126,6 +122,7 @@ public class Client extends test.Util.Application } } + _initData.properties.setProperty("Ice.Default.Router", ""); _factory = new Glacier2.SessionFactoryHelper(_initData, new Glacier2.SessionCallback() { @Override @@ -172,7 +169,6 @@ public class Client extends test.Util.Application out.flush(); _factory.setRouterHost("127.0.0.1"); _factory.setPort(12347); - _factory.setRouterIdentity(Ice.Util.stringToIdentity("Glacier2/router")); _factory.setSecure(false); _session = _factory.connect("userid", "abc123"); while(true) @@ -387,7 +383,6 @@ public class Client extends test.Util.Application _factory.setRouterHost("127.0.0.1"); _factory.setPort(12347); - _factory.setRouterIdentity(Ice.Util.stringToIdentity("Glacier2/router")); _factory.setSecure(false); _session = _factory.connect("userid", "abc123"); while(true) |