connectImpl(ConnectStrategy factory) { Debug.Assert(!_destroy); new Thread(new ThreadStart(() => { try { lock (_mutex) { _communicator = Ice.Util.initialize(_initData); } } catch (Ice.LocalException ex) { lock (_mutex) { _destroy = true; } dispatchCallback(() => _callback.connectFailed(this, ex), null); return; } if (_communicator.getDefaultRouter() == null) { Ice.RouterFinderPrx finder = Ice.RouterFinderPrxHelper.uncheckedCast(_communicator.stringToProxy(_finderStr)); try { _communicator.setDefaultRouter(finder.getRouter()); } catch (Ice.CommunicatorDestroyedException ex) { dispatchCallback(() => _callback.connectFailed(this, ex), null); return; } catch (Exception) { // // In case of error getting router identity from RouterFinder use default identity. // _communicator.setDefaultRouter( Ice.RouterPrxHelper.uncheckedCast(finder.ice_identity(new Ice.Identity("router", "Glacier2")))); } } try { dispatchCallbackAndWait(() => _callback.createdCommunicator(this)); RouterPrx routerPrx = RouterPrxHelper.uncheckedCast(_communicator.getDefaultRouter()); SessionPrx session = factory(routerPrx); connected(routerPrx, session); } catch (Exception ex) { _communicator.destroy(); dispatchCallback(() => _callback.connectFailed(this, ex), null); } })).Start(); }
// // Only for use by ObjectAdapterFactory // public ObjectAdapterI(Instance instance, Communicator communicator, ObjectAdapterFactory objectAdapterFactory, string name, RouterPrx router, bool noConfig) { instance_ = instance; _communicator = communicator; _objectAdapterFactory = objectAdapterFactory; _servantManager = new ServantManager(instance, name); _name = name; _incomingConnectionFactories = new List <IncomingConnectionFactory>(); _publishedEndpoints = new List <EndpointI>(); _routerEndpoints = new List <EndpointI>(); _routerInfo = null; _directCount = 0; _noConfig = noConfig; if (_noConfig) { _id = ""; _replicaGroupId = ""; _reference = instance_.referenceFactory().create("dummy -t", ""); _acm = instance_.serverACM(); return; } Properties properties = instance_.initializationData().properties; List <string> unknownProps = new List <string>(); bool noProps = filterProperties(unknownProps); // // Warn about unknown object adapter properties. // if (unknownProps.Count != 0 && properties.getPropertyAsIntWithDefault("Ice.Warn.UnknownProperties", 1) > 0) { StringBuilder message = new StringBuilder("found unknown properties for object adapter `"); message.Append(_name); message.Append("':"); foreach (string s in unknownProps) { message.Append("\n "); message.Append(s); } instance_.initializationData().logger.warning(message.ToString()); } // // Make sure named adapter has configuration. // if (router == null && noProps) { // // These need to be set to prevent warnings/asserts in the destructor. // state_ = StateDestroyed; instance_ = null; _incomingConnectionFactories = null; InitializationException ex = new InitializationException(); ex.reason = "object adapter `" + _name + "' requires configuration"; throw ex; } _id = properties.getProperty(_name + ".AdapterId"); _replicaGroupId = properties.getProperty(_name + ".ReplicaGroupId"); // // Setup a reference to be used to get the default proxy options // when creating new proxies. By default, create twoway proxies. // string proxyOptions = properties.getPropertyWithDefault(_name + ".ProxyOptions", "-t"); try { _reference = instance_.referenceFactory().create("dummy " + proxyOptions, ""); } catch (ProxyParseException) { InitializationException ex = new InitializationException(); ex.reason = "invalid proxy options `" + proxyOptions + "' for object adapter `" + _name + "'"; throw ex; } _acm = new ACMConfig(properties, communicator.getLogger(), _name + ".ACM", instance_.serverACM()); { int defaultMessageSizeMax = instance.messageSizeMax() / 1024; int num = properties.getPropertyAsIntWithDefault(_name + ".MessageSizeMax", defaultMessageSizeMax); if (num < 1 || num > 0x7fffffff / 1024) { _messageSizeMax = 0x7fffffff; } else { _messageSizeMax = num * 1024; // Property is in kilobytes, _messageSizeMax in bytes } } try { int threadPoolSize = properties.getPropertyAsInt(_name + ".ThreadPool.Size"); int threadPoolSizeMax = properties.getPropertyAsInt(_name + ".ThreadPool.SizeMax"); if (threadPoolSize > 0 || threadPoolSizeMax > 0) { _threadPool = new ThreadPool(instance_, _name + ".ThreadPool", 0); } if (router == null) { router = RouterPrxHelper.uncheckedCast( instance_.proxyFactory().propertyToProxy(_name + ".Router")); } if (router != null) { _routerInfo = instance_.routerManager().get(router); if (_routerInfo != null) { // // Make sure this router is not already registered with another adapter. // if (_routerInfo.getAdapter() != null) { Ice.AlreadyRegisteredException ex = new Ice.AlreadyRegisteredException(); ex.kindOfObject = "object adapter with router"; ex.id = Ice.Util.identityToString(router.ice_getIdentity()); throw ex; } // // Add the router's server proxy endpoints to this object // adapter. // EndpointI[] endpoints = _routerInfo.getServerEndpoints(); for (int i = 0; i < endpoints.Length; ++i) { _routerEndpoints.Add(endpoints[i]); } _routerEndpoints.Sort(); // Must be sorted. // // Remove duplicate endpoints, so we have a list of unique endpoints. // for (int i = 0; i < _routerEndpoints.Count - 1;) { EndpointI e1 = _routerEndpoints[i]; EndpointI e2 = _routerEndpoints[i + 1]; if (e1.Equals(e2)) { _routerEndpoints.RemoveAt(i); } else { ++i; } } // // Associate this object adapter with the router. This way, // new outgoing connections to the router's client proxy will // use this object adapter for callbacks. // _routerInfo.setAdapter(this); // // Also modify all existing outgoing connections to the // router's client proxy to use this object adapter for // callbacks. // instance_.outgoingConnectionFactory().setRouterInfo(_routerInfo); } } else { // // Parse the endpoints, but don't store them in the adapter. The connection // factory might change it, for example, to fill in the real port number. // List <EndpointI> endpoints = parseEndpoints(properties.getProperty(_name + ".Endpoints"), true); foreach (EndpointI endp in endpoints) { IncomingConnectionFactory factory = new IncomingConnectionFactory(instance, endp, this); _incomingConnectionFactories.Add(factory); } if (endpoints.Count == 0) { TraceLevels tl = instance_.traceLevels(); if (tl.network >= 2) { instance_.initializationData().logger.trace(tl.networkCat, "created adapter `" + _name + "' without endpoints"); } } // // Parse published endpoints. // _publishedEndpoints = parsePublishedEndpoints(); } if (properties.getProperty(_name + ".Locator").Length > 0) { setLocator(LocatorPrxHelper.uncheckedCast( instance_.proxyFactory().propertyToProxy(_name + ".Locator"))); } else { setLocator(instance_.referenceFactory().getDefaultLocator()); } } catch (LocalException) { destroy(); throw; } }
public void Initialize(IScene scene) { try { if (!m_enabled) { return; } IMurmurService service = scene.RequestModuleInterface <IMurmurService>(); if (service == null) { return; } MurmurConfig config = service.GetConfiguration(scene.RegionInfo.RegionName); if (config == null) { return; } bool justStarted = false; if (!m_started) { justStarted = true; m_started = true; // retrieve configuration variables m_murmurd_host = config.MurmurHost; m_server_version = config.ServerVersion; //Fix the callback URL, its our IP, so we deal with it IConfig m_config = m_source.Configs["MurmurService"]; if (m_config != null) { config.IceCB = m_config.GetString("murmur_ice_cb", "tcp -h 127.0.0.1"); } // Admin interface required values if (String.IsNullOrEmpty(m_murmurd_host)) { m_log.Error("[MurmurVoice] plugin disabled: incomplete configuration"); return; } Ice.Communicator comm = Ice.Util.initialize(); if (config.GlacierEnabled) { router = RouterPrxHelper.uncheckedCast(comm.stringToProxy(config.GlacierIce)); comm.setDefaultRouter(router); router.createSession(config.GlacierUser, config.GlacierPass); } MetaPrx meta = MetaPrxHelper.checkedCast(comm.stringToProxy(config.MetaIce)); // Create the adapter comm.getProperties().setProperty("Ice.PrintAdapterReady", "0"); if (config.GlacierEnabled) { adapter = comm.createObjectAdapterWithRouter("Callback.Client", comm.getDefaultRouter()); } else { adapter = comm.createObjectAdapterWithEndpoints("Callback.Client", config.IceCB); } adapter.activate(); // Create identity and callback for Metaserver Ice.Identity metaCallbackIdent = new Ice.Identity(); metaCallbackIdent.name = "metaCallback"; if (router != null) { metaCallbackIdent.category = router.getCategoryForClient(); } MetaCallbackPrx meta_callback = MetaCallbackPrxHelper.checkedCast(adapter.add(new MetaCallbackImpl(), metaCallbackIdent)); meta.addCallback(meta_callback); m_log.InfoFormat("[MurmurVoice] using murmur server ice '{0}'", config.MetaIce); // create a server and figure out the port name Dictionary <string, string> defaults = meta.getDefaultConf(); m_server = ServerPrxHelper.checkedCast(meta.getServer(config.ServerID)); // start thread to ping glacier2 router and/or determine if con$ m_keepalive = new KeepAlive(m_server); ThreadStart ka_d = new ThreadStart(m_keepalive.StartPinging); m_keepalive_t = new Thread(ka_d); m_keepalive_t.Start(); // first check the conf for a port, if not then use server id and default port to find the right one. string conf_port = m_server.getConf("port"); if (!String.IsNullOrEmpty(conf_port)) { m_murmurd_port = Convert.ToInt32(conf_port); } else { m_murmurd_port = Convert.ToInt32(defaults["port"]) + config.ServerID - 1; } try { m_server.start(); } catch { } } // starts the server and gets a callback ServerManager manager = new ServerManager(m_server, config.ChannelName); // Create identity and callback for this current server AddServerCallback(scene, new ServerCallbackImpl(manager)); AddServerManager(scene, manager); if (justStarted) { Ice.Identity serverCallbackIdent = new Ice.Identity(); serverCallbackIdent.name = "serverCallback"; if (router != null) { serverCallbackIdent.category = router.getCategoryForClient(); } m_server.addCallback(ServerCallbackPrxHelper.checkedCast(adapter.add(GetServerCallback(scene), serverCallbackIdent))); } // Show information on console for debugging purposes m_log.InfoFormat("[MurmurVoice] using murmur server '{0}:{1}', sid '{2}'", m_murmurd_host, m_murmurd_port, config.ServerID); m_log.Info("[MurmurVoice] plugin enabled"); m_enabled = true; } catch (Exception e) { m_log.ErrorFormat("[MurmurVoice] plugin initialization failed: {0}", e.ToString()); return; } }
public void Initialize(Scene scene) { try { if (!m_enabled) { return; } if (!m_started) { m_started = true; scene.AddCommand(this, "mumble report", "mumble report", "Returns mumble report", MumbleReport); scene.AddCommand(this, "mumble unregister", "mumble unregister <userid>", "Unregister User by userid", UnregisterUser); scene.AddCommand(this, "mumble remove", "mumble remove <UUID>", "Remove Agent by UUID", RemoveAgent); Ice.Communicator comm = Ice.Util.initialize(); if (m_glacier_enabled) { m_router = RouterPrxHelper.uncheckedCast(comm.stringToProxy(m_glacier_ice)); comm.setDefaultRouter(m_router); m_router.createSession(m_glacier_user, m_glacier_pass); } MetaPrx meta = MetaPrxHelper.checkedCast(comm.stringToProxy(m_murmurd_ice)); // Create the adapter comm.getProperties().setProperty("Ice.PrintAdapterReady", "0"); if (m_glacier_enabled) { m_adapter = comm.createObjectAdapterWithRouter("Callback.Client", comm.getDefaultRouter()); } else { m_adapter = comm.createObjectAdapterWithEndpoints("Callback.Client", m_murmur_ice_cb); } m_adapter.activate(); // Create identity and callback for Metaserver Ice.Identity metaCallbackIdent = new Ice.Identity(); metaCallbackIdent.name = "metaCallback"; if (m_router != null) { metaCallbackIdent.category = m_router.getCategoryForClient(); } MetaCallbackPrx meta_callback = MetaCallbackPrxHelper.checkedCast(m_adapter.add(new MetaCallbackImpl(), metaCallbackIdent)); meta.addCallback(meta_callback); m_log.InfoFormat("[MurmurVoice] using murmur server ice '{0}'", m_murmurd_ice); // create a server and figure out the port name Dictionary <string, string> defaults = meta.getDefaultConf(); m_server = ServerPrxHelper.checkedCast(meta.getServer(m_server_id)); // start thread to ping glacier2 router and/or determine if con$ m_keepalive = new KeepAlive(m_server); ThreadStart ka_d = new ThreadStart(m_keepalive.StartPinging); m_keepalive_t = new Thread(ka_d); m_keepalive_t.Start(); // first check the conf for a port, if not then use server id and default port to find the right one. string conf_port = m_server.getConf("port"); if (!String.IsNullOrEmpty(conf_port)) { m_murmurd_port = Convert.ToInt32(conf_port); } else { m_murmurd_port = Convert.ToInt32(defaults["port"]) + m_server_id - 1; } try { m_server.start(); } catch { } m_log.Info("[MurmurVoice] started"); } // starts the server and gets a callback ServerManager manager = new ServerManager(m_server, m_channel_name); // Create identity and callback for this current server AddServerCallback(scene, new ServerCallbackImpl(manager)); AddServerManager(scene, manager); Ice.Identity serverCallbackIdent = new Ice.Identity(); serverCallbackIdent.name = "serverCallback_" + scene.RegionInfo.RegionName.Replace(" ", "_"); if (m_router != null) { serverCallbackIdent.category = m_router.getCategoryForClient(); } m_server.addCallback(ServerCallbackPrxHelper.checkedCast(m_adapter.add(GetServerCallback(scene), serverCallbackIdent))); // Show information on console for debugging purposes m_log.InfoFormat("[MurmurVoice] using murmur server '{0}:{1}', sid '{2}'", m_murmurd_host, m_murmurd_port, m_server_id); m_log.Info("[MurmurVoice] plugin enabled"); m_enabled = true; } catch (Exception e) { m_log.ErrorFormat("[MurmurVoice] plugin initialization failed: {0}", e.ToString()); return; } }
doMain(string[] args, Ice.InitializationData initData, out int status) { // // Reset internal state variables from Ice.Application. The // remainder are reset at the end of this method. // iceCallbackInProgress = false; iceDestroyed = false; iceInterrupted = false; bool restart = false; bool sessionCreated = false; status = 0; try { iceCommunicator = Ice.Util.initialize(ref args, initData); _router = RouterPrxHelper.uncheckedCast(communicator().getDefaultRouter()); if (_router == null) { Ice.Util.getProcessLogger().error(iceAppName + ": no Glacier2 router configured"); status = 1; } else { // // The default is to destroy when a signal is received. // if (iceSignalPolicy == Ice.SignalPolicy.HandleSignals) { destroyOnInterrupt(); } // // If createSession throws, we're done. // try { _session = createSession(); sessionCreated = true; } catch (Ice.LocalException ex) { Ice.Util.getProcessLogger().error(ex.ToString()); status = 1; } if (sessionCreated) { int acmTimeout = 0; try { acmTimeout = _router.getACMTimeout(); } catch (Ice.OperationNotExistException) { } if (acmTimeout <= 0) { acmTimeout = (int)_router.getSessionTimeout(); } if (acmTimeout > 0) { Ice.Connection connection = _router.ice_getCachedConnection(); Debug.Assert(connection != null); connection.setACM(acmTimeout, Ice.Util.None, Ice.ACMHeartbeat.HeartbeatAlways); connection.setCloseCallback(_ => sessionDestroyed()); } _category = _router.getCategoryForClient(); status = runWithSession(args); } } } // // We want to restart on those exceptions that indicate a // break down in communications, but not those exceptions that // indicate a programming logic error (i.e., marshal, protocol // failure, etc). // catch (RestartSessionException) { restart = true; } catch (Ice.ConnectionRefusedException ex) { Ice.Util.getProcessLogger().error(ex.ToString()); restart = true; } catch (Ice.ConnectionLostException ex) { Ice.Util.getProcessLogger().error(ex.ToString()); restart = true; } catch (Ice.UnknownLocalException ex) { Ice.Util.getProcessLogger().error(ex.ToString()); restart = true; } catch (Ice.RequestFailedException ex) { Ice.Util.getProcessLogger().error(ex.ToString()); restart = true; } catch (Ice.TimeoutException ex) { Ice.Util.getProcessLogger().error(ex.ToString()); restart = true; } catch (Ice.LocalException ex) { Ice.Util.getProcessLogger().error(ex.ToString()); status = 1; } catch (Exception ex) { Ice.Util.getProcessLogger().error("unknown exception:\n" + ex.ToString()); status = 1; } // // Don't want any new interrupt. And at this point // (post-run), it would not make sense to release a held // signal to run shutdown or destroy. // if (iceSignalPolicy == Ice.SignalPolicy.HandleSignals) { ignoreInterrupt(); } lock (iceMutex) { while (iceCallbackInProgress) { System.Threading.Monitor.Wait(iceMutex); } if (iceDestroyed) { iceCommunicator = null; } else { iceDestroyed = true; // // And iceCommunicator != null, meaning will be // destroyed next, iceDestroyed = true also ensures that // any remaining callback won't do anything // } } if (sessionCreated && _router != null) { try { _router.destroySession(); } catch (Ice.ConnectionLostException) { // // Expected if another thread invoked on an object from the session concurrently. // } catch (SessionNotExistException) { // // This can also occur. // } catch (Exception ex) { // // Not expected. // Ice.Util.getProcessLogger().error("unexpected exception when destroying the session:\n" + ex.ToString()); } _router = null; } if (iceCommunicator != null) { try { iceCommunicator.destroy(); } catch (Ice.LocalException ex) { Ice.Util.getProcessLogger().error(ex.ToString()); status = 1; } catch (Exception ex) { Ice.Util.getProcessLogger().error("unknown exception:\n" + ex.ToString()); status = 1; } iceCommunicator = null; } // // Reset internal state. We cannot reset the Application state // here, since iceDestroyed must remain true until we re-run // this method. // _adapter = null; _router = null; _session = null; _category = null; return(restart); }
public static void allTests(global::Test.TestHelper helper) { Communicator communicator = helper.communicator(); var manager = Test.ServerManagerPrxHelper.checkedCast( communicator.stringToProxy("ServerManager :" + helper.getTestEndpoint(0))); test(manager != null); var locator = Test.TestLocatorPrxHelper.uncheckedCast(communicator.getDefaultLocator()); test(locator != null); var registry = Test.TestLocatorRegistryPrxHelper.checkedCast(locator.getRegistry()); test(registry != null); var output = helper.getWriter(); output.Write("testing stringToProxy... "); output.Flush(); ObjectPrx @base = communicator.stringToProxy("test @ TestAdapter"); ObjectPrx base2 = communicator.stringToProxy("test @ TestAdapter"); ObjectPrx base3 = communicator.stringToProxy("test"); ObjectPrx base4 = communicator.stringToProxy("ServerManager"); ObjectPrx base5 = communicator.stringToProxy("test2"); ObjectPrx base6 = communicator.stringToProxy("test @ ReplicatedAdapter"); output.WriteLine("ok"); output.Write("testing ice_locator and ice_getLocator... "); test(Util.proxyIdentityCompare(@base.ice_getLocator(), communicator.getDefaultLocator()) == 0); LocatorPrx anotherLocator = LocatorPrxHelper.uncheckedCast(communicator.stringToProxy("anotherLocator")); @base = @base.ice_locator(anotherLocator); test(Util.proxyIdentityCompare(@base.ice_getLocator(), anotherLocator) == 0); communicator.setDefaultLocator(null); @base = communicator.stringToProxy("test @ TestAdapter"); test(@base.ice_getLocator() == null); @base = @base.ice_locator(anotherLocator); test(Util.proxyIdentityCompare(@base.ice_getLocator(), anotherLocator) == 0); communicator.setDefaultLocator(locator); @base = communicator.stringToProxy("test @ TestAdapter"); test(Util.proxyIdentityCompare(@base.ice_getLocator(), communicator.getDefaultLocator()) == 0); // // We also test ice_router/ice_getRouter(perhaps we should add a // test/Ice/router test?) // test(@base.ice_getRouter() == null); RouterPrx anotherRouter = RouterPrxHelper.uncheckedCast(communicator.stringToProxy("anotherRouter")); @base = @base.ice_router(anotherRouter); test(Util.proxyIdentityCompare(@base.ice_getRouter(), anotherRouter) == 0); RouterPrx router = RouterPrxHelper.uncheckedCast(communicator.stringToProxy("dummyrouter")); communicator.setDefaultRouter(router); @base = communicator.stringToProxy("test @ TestAdapter"); test(Util.proxyIdentityCompare(@base.ice_getRouter(), communicator.getDefaultRouter()) == 0); communicator.setDefaultRouter(null); @base = communicator.stringToProxy("test @ TestAdapter"); test(@base.ice_getRouter() == null); output.WriteLine("ok"); output.Write("starting server... "); output.Flush(); manager.startServer(); output.WriteLine("ok"); output.Write("testing checked cast... "); output.Flush(); var obj = Test.TestIntfPrxHelper.checkedCast(@base); test(obj != null); var obj2 = Test.TestIntfPrxHelper.checkedCast(base2); test(obj2 != null); var obj3 = Test.TestIntfPrxHelper.checkedCast(base3); test(obj3 != null); var obj4 = Test.ServerManagerPrxHelper.checkedCast(base4); test(obj4 != null); var obj5 = Test.TestIntfPrxHelper.checkedCast(base5); test(obj5 != null); var obj6 = Test.TestIntfPrxHelper.checkedCast(base6); test(obj6 != null); output.WriteLine("ok"); output.Write("testing id@AdapterId indirect proxy... "); output.Flush(); obj.shutdown(); manager.startServer(); try { obj2.ice_ping(); } catch (LocalException) { test(false); } output.WriteLine("ok"); output.Write("testing id@ReplicaGroupId indirect proxy... "); output.Flush(); obj.shutdown(); manager.startServer(); try { obj6.ice_ping(); } catch (LocalException) { test(false); } output.WriteLine("ok"); output.Write("testing identity indirect proxy... "); output.Flush(); obj.shutdown(); manager.startServer(); try { obj3.ice_ping(); } catch (LocalException) { test(false); } try { obj2.ice_ping(); } catch (LocalException) { test(false); } obj.shutdown(); manager.startServer(); try { obj2.ice_ping(); } catch (LocalException) { test(false); } try { obj3.ice_ping(); } catch (LocalException) { test(false); } obj.shutdown(); manager.startServer(); try { obj2.ice_ping(); } catch (LocalException) { test(false); } obj.shutdown(); manager.startServer(); try { obj3.ice_ping(); } catch (LocalException) { test(false); } obj.shutdown(); manager.startServer(); try { obj5 = Test.TestIntfPrxHelper.checkedCast(base5); obj5.ice_ping(); } catch (LocalException) { test(false); } output.WriteLine("ok"); output.Write("testing proxy with unknown identity... "); output.Flush(); try { @base = communicator.stringToProxy("unknown/unknown"); @base.ice_ping(); test(false); } catch (NotRegisteredException ex) { test(ex.kindOfObject.Equals("object")); test(ex.id.Equals("unknown/unknown")); } output.WriteLine("ok"); output.Write("testing proxy with unknown adapter... "); output.Flush(); try { @base = communicator.stringToProxy("test @ TestAdapterUnknown"); @base.ice_ping(); test(false); } catch (NotRegisteredException ex) { test(ex.kindOfObject.Equals("object adapter")); test(ex.id.Equals("TestAdapterUnknown")); } output.WriteLine("ok"); output.Write("testing locator cache timeout... "); output.Flush(); ObjectPrx basencc = communicator.stringToProxy("test@TestAdapter").ice_connectionCached(false); int count = locator.getRequestCount(); basencc.ice_locatorCacheTimeout(0).ice_ping(); // No locator cache. test(++count == locator.getRequestCount()); basencc.ice_locatorCacheTimeout(0).ice_ping(); // No locator cache. test(++count == locator.getRequestCount()); basencc.ice_locatorCacheTimeout(2).ice_ping(); // 2s timeout. test(count == locator.getRequestCount()); System.Threading.Thread.Sleep(1300); // 1300ms basencc.ice_locatorCacheTimeout(1).ice_ping(); // 1s timeout. test(++count == locator.getRequestCount()); communicator.stringToProxy("test").ice_locatorCacheTimeout(0).ice_ping(); // No locator cache. count += 2; test(count == locator.getRequestCount()); communicator.stringToProxy("test").ice_locatorCacheTimeout(2).ice_ping(); // 2s timeout test(count == locator.getRequestCount()); System.Threading.Thread.Sleep(1300); // 1300ms communicator.stringToProxy("test").ice_locatorCacheTimeout(1).ice_ping(); // 1s timeout count += 2; test(count == locator.getRequestCount()); communicator.stringToProxy("test@TestAdapter").ice_locatorCacheTimeout(-1).ice_ping(); test(count == locator.getRequestCount()); communicator.stringToProxy("test").ice_locatorCacheTimeout(-1).ice_ping(); test(count == locator.getRequestCount()); communicator.stringToProxy("test@TestAdapter").ice_ping(); test(count == locator.getRequestCount()); communicator.stringToProxy("test").ice_ping(); test(count == locator.getRequestCount()); test(communicator.stringToProxy("test").ice_locatorCacheTimeout(99).ice_getLocatorCacheTimeout() == 99); output.WriteLine("ok"); output.Write("testing proxy from server... "); output.Flush(); obj = Test.TestIntfPrxHelper.checkedCast(communicator.stringToProxy("test@TestAdapter")); var hello = obj.getHello(); test(hello.ice_getAdapterId().Equals("TestAdapter")); hello.sayHello(); hello = obj.getReplicatedHello(); test(hello.ice_getAdapterId().Equals("ReplicatedAdapter")); hello.sayHello(); output.WriteLine("ok"); output.Write("testing locator request queuing... "); output.Flush(); hello = (Test.HelloPrx)obj.getReplicatedHello().ice_locatorCacheTimeout(0).ice_connectionCached(false); count = locator.getRequestCount(); hello.ice_ping(); test(++count == locator.getRequestCount()); List <Task> results = new List <Task>(); for (int i = 0; i < 1000; i++) { results.Add(hello.sayHelloAsync()); } Task.WaitAll(results.ToArray()); results.Clear(); test(locator.getRequestCount() > count && locator.getRequestCount() < count + 999); if (locator.getRequestCount() > count + 800) { output.Write("queuing = " + (locator.getRequestCount() - count)); } count = locator.getRequestCount(); hello = (Test.HelloPrx)hello.ice_adapterId("unknown"); for (int i = 0; i < 1000; i++) { results.Add(hello.sayHelloAsync().ContinueWith((Task t) => { try { t.Wait(); } catch (AggregateException ex) when(ex.InnerException is Ice.NotRegisteredException) { } })); } Task.WaitAll(results.ToArray()); results.Clear(); // XXX: // Take into account the retries. test(locator.getRequestCount() > count && locator.getRequestCount() < count + 1999); if (locator.getRequestCount() > count + 800) { output.Write("queuing = " + (locator.getRequestCount() - count)); } output.WriteLine("ok"); output.Write("testing adapter locator cache... "); output.Flush(); try { communicator.stringToProxy("test@TestAdapter3").ice_ping(); test(false); } catch (NotRegisteredException ex) { test(ex.kindOfObject == "object adapter"); test(ex.id.Equals("TestAdapter3")); } registry.setAdapterDirectProxy("TestAdapter3", locator.findAdapterById("TestAdapter")); try { communicator.stringToProxy("test@TestAdapter3").ice_ping(); registry.setAdapterDirectProxy("TestAdapter3", communicator.stringToProxy("dummy:" + helper.getTestEndpoint(99))); communicator.stringToProxy("test@TestAdapter3").ice_ping(); } catch (LocalException) { test(false); } try { communicator.stringToProxy("test@TestAdapter3").ice_locatorCacheTimeout(0).ice_ping(); test(false); } catch (LocalException) { } try { communicator.stringToProxy("test@TestAdapter3").ice_ping(); test(false); } catch (LocalException) { } registry.setAdapterDirectProxy("TestAdapter3", locator.findAdapterById("TestAdapter")); try { communicator.stringToProxy("test@TestAdapter3").ice_ping(); } catch (LocalException) { test(false); } output.WriteLine("ok"); output.Write("testing well-known object locator cache... "); output.Flush(); registry.addObject(communicator.stringToProxy("test3@TestUnknown")); try { communicator.stringToProxy("test3").ice_ping(); test(false); } catch (NotRegisteredException ex) { test(ex.kindOfObject == "object adapter"); test(ex.id.Equals("TestUnknown")); } registry.addObject(communicator.stringToProxy("test3@TestAdapter4")); // Update registry.setAdapterDirectProxy("TestAdapter4", communicator.stringToProxy("dummy:" + helper.getTestEndpoint(99))); try { communicator.stringToProxy("test3").ice_ping(); test(false); } catch (LocalException) { } registry.setAdapterDirectProxy("TestAdapter4", locator.findAdapterById("TestAdapter")); try { communicator.stringToProxy("test3").ice_ping(); } catch (LocalException) { test(false); } registry.setAdapterDirectProxy("TestAdapter4", communicator.stringToProxy("dummy:" + helper.getTestEndpoint(99))); try { communicator.stringToProxy("test3").ice_ping(); } catch (LocalException) { test(false); } try { communicator.stringToProxy("test@TestAdapter4").ice_locatorCacheTimeout(0).ice_ping(); test(false); } catch (LocalException) { } try { communicator.stringToProxy("test@TestAdapter4").ice_ping(); test(false); } catch (LocalException) { } try { communicator.stringToProxy("test3").ice_ping(); test(false); } catch (LocalException) { } registry.addObject(communicator.stringToProxy("test3@TestAdapter")); try { communicator.stringToProxy("test3").ice_ping(); } catch (LocalException) { test(false); } registry.addObject(communicator.stringToProxy("test4")); try { communicator.stringToProxy("test4").ice_ping(); test(false); } catch (NoEndpointException) { } output.WriteLine("ok"); output.Write("testing locator cache background updates... "); output.Flush(); { InitializationData initData = new InitializationData(); initData.properties = communicator.getProperties().ice_clone_(); initData.properties.setProperty("Ice.BackgroundLocatorCacheUpdates", "1"); Communicator ic = helper.initialize(initData); registry.setAdapterDirectProxy("TestAdapter5", locator.findAdapterById("TestAdapter")); registry.addObject(communicator.stringToProxy("test3@TestAdapter")); count = locator.getRequestCount(); ic.stringToProxy("test@TestAdapter5").ice_locatorCacheTimeout(0).ice_ping(); // No locator cache. ic.stringToProxy("test3").ice_locatorCacheTimeout(0).ice_ping(); // No locator cache. count += 3; test(count == locator.getRequestCount()); registry.setAdapterDirectProxy("TestAdapter5", null); registry.addObject(communicator.stringToProxy("test3:" + helper.getTestEndpoint(99))); ic.stringToProxy("test@TestAdapter5").ice_locatorCacheTimeout(10).ice_ping(); // 10s timeout. ic.stringToProxy("test3").ice_locatorCacheTimeout(10).ice_ping(); // 10s timeout. test(count == locator.getRequestCount()); System.Threading.Thread.Sleep(1200); // The following request should trigger the background // updates but still use the cached endpoints and // therefore succeed. ic.stringToProxy("test@TestAdapter5").ice_locatorCacheTimeout(1).ice_ping(); // 1s timeout. ic.stringToProxy("test3").ice_locatorCacheTimeout(1).ice_ping(); // 1s timeout. try { while (true) { ic.stringToProxy("test@TestAdapter5").ice_locatorCacheTimeout(1).ice_ping(); // 1s timeout. System.Threading.Thread.Sleep(10); } } catch (LocalException) { // Expected to fail once they endpoints have been updated in the background. } try { while (true) { ic.stringToProxy("test3").ice_locatorCacheTimeout(1).ice_ping(); // 1s timeout. System.Threading.Thread.Sleep(10); } } catch (LocalException) { // Expected to fail once they endpoints have been updated in the background. } ic.destroy(); } output.WriteLine("ok"); output.Write("testing proxy from server after shutdown... "); output.Flush(); hello = obj.getReplicatedHello(); obj.shutdown(); manager.startServer(); hello.sayHello(); output.WriteLine("ok"); output.Write("testing object migration... "); output.Flush(); hello = Test.HelloPrxHelper.checkedCast(communicator.stringToProxy("hello")); obj.migrateHello(); hello.ice_getConnection().close(ConnectionClose.GracefullyWithWait); hello.sayHello(); obj.migrateHello(); hello.sayHello(); obj.migrateHello(); hello.sayHello(); output.WriteLine("ok"); output.Write("testing locator encoding resolution... "); output.Flush(); hello = Test.HelloPrxHelper.checkedCast(communicator.stringToProxy("hello")); count = locator.getRequestCount(); communicator.stringToProxy("test@TestAdapter").ice_encodingVersion(Util.Encoding_1_1).ice_ping(); test(count == locator.getRequestCount()); communicator.stringToProxy("test@TestAdapter10").ice_encodingVersion(Util.Encoding_1_0).ice_ping(); test(++count == locator.getRequestCount()); communicator.stringToProxy("test -e 1.0@TestAdapter10-2").ice_ping(); test(++count == locator.getRequestCount()); output.WriteLine("ok"); output.Write("shutdown server... "); output.Flush(); obj.shutdown(); output.WriteLine("ok"); output.Write("testing whether server is gone... "); output.Flush(); try { obj2.ice_ping(); test(false); } catch (LocalException) { } try { obj3.ice_ping(); test(false); } catch (LocalException) { } try { obj5.ice_ping(); test(false); } catch (LocalException) { } output.WriteLine("ok"); output.Write("testing indirect proxies to collocated objects... "); output.Flush(); communicator.getProperties().setProperty("Hello.AdapterId", Guid.NewGuid().ToString()); ObjectAdapter adapter = communicator.createObjectAdapterWithEndpoints("Hello", "default"); Identity id = new Identity(); id.name = Guid.NewGuid().ToString(); adapter.add(new HelloI(), id); adapter.activate(); // Ensure that calls on the well-known proxy is collocated. var helloPrx = Test.HelloPrxHelper.checkedCast( communicator.stringToProxy("\"" + communicator.identityToString(id) + "\"")); test(helloPrx.ice_getConnection() == null); // Ensure that calls on the indirect proxy (with adapter ID) is collocated helloPrx = Test.HelloPrxHelper.checkedCast(adapter.createIndirectProxy(id)); test(helloPrx.ice_getConnection() == null); // Ensure that calls on the direct proxy is collocated helloPrx = Test.HelloPrxHelper.checkedCast(adapter.createDirectProxy(id)); test(helloPrx.ice_getConnection() == null); output.WriteLine("ok"); output.Write("shutdown server manager... "); output.Flush(); manager.shutdown(); output.WriteLine("ok"); }
public static Test.TestIntfPrx allTests(global::Test.TestHelper helper) { Ice.Communicator communicator = helper.communicator(); var output = helper.getWriter(); output.Write("testing stringToProxy... "); output.Flush(); string @ref = "test:" + helper.getTestEndpoint(0); Ice.ObjectPrx @base = communicator.stringToProxy(@ref); test(@base != null); output.WriteLine("ok"); output.Write("testing checked cast... "); output.Flush(); var obj = Test.TestIntfPrxHelper.checkedCast(@base); test(obj != null); test(obj.Equals(@base)); output.WriteLine("ok"); { output.Write("creating/destroying/recreating object adapter... "); output.Flush(); ObjectAdapter adapter = communicator.createObjectAdapterWithEndpoints("TransientTestAdapter", "default"); try { communicator.createObjectAdapterWithEndpoints("TransientTestAdapter", "default"); test(false); } catch (AlreadyRegisteredException) { } adapter.destroy(); // // Use a different port than the first adapter to avoid an "address already in use" error. // adapter = communicator.createObjectAdapterWithEndpoints("TransientTestAdapter", "default"); adapter.destroy(); output.WriteLine("ok"); } output.Write("creating/activating/deactivating object adapter in one operation... "); output.Flush(); obj.transient(); obj.transientAsync().Wait(); output.WriteLine("ok"); { output.Write("testing connection closure... "); output.Flush(); for (int i = 0; i < 10; ++i) { var initData = new InitializationData(); initData.properties = communicator.getProperties().ice_clone_(); var comm = Util.initialize(initData); comm.stringToProxy("test:" + helper.getTestEndpoint(0)).ice_pingAsync(); comm.destroy(); } output.WriteLine("ok"); } output.Write("testing object adapter published endpoints... "); output.Flush(); { communicator.getProperties().setProperty("PAdapter.PublishedEndpoints", "tcp -h localhost -p 12345 -t 30000"); var adapter = communicator.createObjectAdapter("PAdapter"); test(adapter.getPublishedEndpoints().Length == 1); var endpt = adapter.getPublishedEndpoints()[0]; test(endpt.ToString().Equals("tcp -h localhost -p 12345 -t 30000")); ObjectPrx prx = communicator.stringToProxy("dummy:tcp -h localhost -p 12346 -t 20000:tcp -h localhost -p 12347 -t 10000"); adapter.setPublishedEndpoints(prx.ice_getEndpoints()); test(adapter.getPublishedEndpoints().Length == 2); var id = new Identity(); id.name = "dummy"; test(IceUtilInternal.Arrays.Equals(adapter.createProxy(id).ice_getEndpoints(), prx.ice_getEndpoints())); test(IceUtilInternal.Arrays.Equals(adapter.getPublishedEndpoints(), prx.ice_getEndpoints())); adapter.refreshPublishedEndpoints(); test(adapter.getPublishedEndpoints().Length == 1); test(adapter.getPublishedEndpoints()[0].Equals(endpt)); communicator.getProperties().setProperty("PAdapter.PublishedEndpoints", "tcp -h localhost -p 12345 -t 20000"); adapter.refreshPublishedEndpoints(); test(adapter.getPublishedEndpoints().Length == 1); test(adapter.getPublishedEndpoints()[0].ToString().Equals("tcp -h localhost -p 12345 -t 20000")); adapter.destroy(); test(adapter.getPublishedEndpoints().Length == 0); } output.WriteLine("ok"); if (obj.ice_getConnection() != null) { output.Write("testing object adapter with bi-dir connection... "); output.Flush(); var adapter = communicator.createObjectAdapter(""); obj.ice_getConnection().setAdapter(adapter); obj.ice_getConnection().setAdapter(null); adapter.deactivate(); try { obj.ice_getConnection().setAdapter(adapter); test(false); } catch (ObjectAdapterDeactivatedException) { } output.WriteLine("ok"); } output.Write("testing object adapter with router... "); output.Flush(); { var routerId = new Identity(); routerId.name = "router"; var router = RouterPrxHelper.uncheckedCast(@base.ice_identity(routerId).ice_connectionId("rc")); var adapter = communicator.createObjectAdapterWithRouter("", router); test(adapter.getPublishedEndpoints().Length == 1); test(adapter.getPublishedEndpoints()[0].ToString().Equals("tcp -h localhost -p 23456 -t 30000")); adapter.refreshPublishedEndpoints(); test(adapter.getPublishedEndpoints().Length == 1); test(adapter.getPublishedEndpoints()[0].ToString().Equals("tcp -h localhost -p 23457 -t 30000")); try { adapter.setPublishedEndpoints(router.ice_getEndpoints()); test(false); } catch (ArgumentException) { // Expected. } adapter.destroy(); try { routerId.name = "test"; router = RouterPrxHelper.uncheckedCast(@base.ice_identity(routerId)); communicator.createObjectAdapterWithRouter("", router); test(false); } catch (OperationNotExistException) { // Expected: the "test" object doesn't implement Ice::Router! } try { router = RouterPrxHelper.uncheckedCast(communicator.stringToProxy("test:" + helper.getTestEndpoint(1))); communicator.createObjectAdapterWithRouter("", router); test(false); } catch (ConnectFailedException) { } } output.WriteLine("ok"); output.Write("testing object adapter creation with port in use... "); output.Flush(); { var adapter1 = communicator.createObjectAdapterWithEndpoints("Adpt1", helper.getTestEndpoint(10)); try { communicator.createObjectAdapterWithEndpoints("Adpt2", helper.getTestEndpoint(10)); test(false); } catch (LocalException) { // Expected can't re-use the same endpoint. } adapter1.destroy(); } output.WriteLine("ok"); output.Write("deactivating object adapter in the server... "); output.Flush(); obj.deactivate(); output.WriteLine("ok"); output.Write("testing whether server is gone... "); output.Flush(); try { obj.ice_timeout(100).ice_ping(); // Use timeout to speed up testing on Windows test(false); } catch (LocalException) { output.WriteLine("ok"); } return(obj); }