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(); }
connected(RouterPrx router, SessionPrx session) { string category = router.getCategoryForClient(); long timeout = router.getSessionTimeout(); Ice.Connection conn = router.ice_getCachedConnection(); lock (this) { _router = router; if (_destroy) { // // Run the destroyInternal in a thread. This is because it // destroyInternal makes remote invocations. // Thread t = new Thread(new ThreadStart(destroyInternal)); t.Start(); return; } // // Cache the category. // _category = category; // // Assign the session after _destroy is checked. // _session = session; _connected = true; Debug.Assert(_sessionRefresh == null); if (timeout > 0) { _sessionRefresh = new SessionRefreshThread(this, _router, (int)(timeout * 1000) / 2); _refreshThread = new Thread(new ThreadStart(_sessionRefresh.run)); _refreshThread.Start(); } } dispatchCallback(delegate() { try { _callback.connected(this); } catch (Glacier2.SessionNotExistException) { destroy(); } }, conn); }
public ObjectAdapter createObjectAdapterWithRouter(string name, RouterPrx router) { if(name.Length == 0) { name = System.Guid.NewGuid().ToString(); } // // We set the proxy properties here, although we still use the proxy supplied. // Dictionary<string, string> properties = proxyToProperty(router, name + ".Router"); foreach(KeyValuePair<string, string> entry in properties) { getProperties().setProperty(entry.Key, entry.Value); } return instance_.objectAdapterFactory().createObjectAdapter(name, router); }
// // Returns router info for a given router. Automatically creates // the router info if it doesn't exist yet. // public RouterInfo get(RouterPrx rtr) { // // The router cannot be routed. // RouterPrx router = rtr.Clone(clearRouter: true); lock (this) { RouterInfo info; if (!_table.TryGetValue(router, out info)) { info = new RouterInfo(router); _table.Add(router, info); } return(info); } }
public ObjectAdapter createObjectAdapterWithRouter(string name, RouterPrx router) { if (name.Length == 0) { name = System.Guid.NewGuid().ToString(); } // // We set the proxy properties here, although we still use the proxy supplied. // Dictionary <string, string> properties = proxyToProperty(router, name + ".Router"); foreach (KeyValuePair <string, string> entry in properties) { getProperties().setProperty(entry.Key, entry.Value); } return(instance_.objectAdapterFactory().createObjectAdapter(name, router)); }
// // Returns router info for a given router. Automatically creates // the router info if it doesn't exist yet. // public RouterInfo erase(RouterPrx rtr) { RouterInfo info = null; if (rtr != null) { // // The router cannot be routed. // RouterPrx router = rtr.Clone(clearRouter: true); lock (this) { if (_table.TryGetValue(router, out info)) { _table.Remove(router); } } } return(info); }
// // 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 static void allTests(global::Test.TestHelper helper) { Communicator communicator = helper.communicator(); var manager = ServerManagerPrx.Parse($"ServerManager :{helper.getTestEndpoint(0)}", communicator); var locator = TestLocatorPrx.UncheckedCast(communicator.getDefaultLocator()); Console.WriteLine("registry checkedcast"); var registry = TestLocatorRegistryPrx.CheckedCast(locator.getRegistry()); test(registry != null); var output = helper.getWriter(); output.Write("testing stringToProxy... "); output.Flush(); var @base = IObjectPrx.Parse("test @ TestAdapter", communicator); var base2 = IObjectPrx.Parse("test @ TestAdapter", communicator); var base3 = IObjectPrx.Parse("test", communicator); var base4 = IObjectPrx.Parse("ServerManager", communicator); var base5 = IObjectPrx.Parse("test2", communicator); var base6 = IObjectPrx.Parse("test @ ReplicatedAdapter", communicator); output.WriteLine("ok"); output.Write("testing ice_locator and ice_getLocator... "); test(default(ProxyIdentityComparer).Compare(@base.Locator, communicator.getDefaultLocator()) == 0); var anotherLocator = LocatorPrx.Parse("anotherLocator", communicator); @base = @base.Clone(locator: anotherLocator); test(default(ProxyIdentityComparer).Compare(@base.Locator, anotherLocator) == 0); communicator.setDefaultLocator(null); @base = IObjectPrx.Parse("test @ TestAdapter", communicator); test(@base.Locator == null); @base = @base.Clone(locator: anotherLocator); test(default(ProxyIdentityComparer).Compare(@base.Locator, anotherLocator) == 0); communicator.setDefaultLocator(locator); @base = IObjectPrx.Parse("test @ TestAdapter", communicator); test(default(ProxyIdentityComparer).Compare(@base.Locator, communicator.getDefaultLocator()) == 0); // // We also test ice_router/ice_getRouter(perhaps we should add a // test/Ice/router test?) // test(@base.Router == null); var anotherRouter = RouterPrx.Parse("anotherRouter", communicator); @base = @base.Clone(router: anotherRouter); test(default(ProxyIdentityComparer).Compare(@base.Router, anotherRouter) == 0); var router = RouterPrx.Parse("dummyrouter", communicator); communicator.setDefaultRouter(router); @base = IObjectPrx.Parse("test @ TestAdapter", communicator); test(default(ProxyIdentityComparer).Compare(@base.Router, communicator.getDefaultRouter()) == 0); communicator.setDefaultRouter(null); @base = IObjectPrx.Parse("test @ TestAdapter", communicator); test(@base.Router == 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.TestIntfPrx.CheckedCast(@base); test(obj != null); var obj2 = Test.TestIntfPrx.CheckedCast(base2); test(obj2 != null); var obj3 = Test.TestIntfPrx.CheckedCast(base3); test(obj3 != null); var obj4 = Test.ServerManagerPrx.CheckedCast(base4); test(obj4 != null); var obj5 = Test.TestIntfPrx.CheckedCast(base5); test(obj5 != null); var obj6 = Test.TestIntfPrx.CheckedCast(base6); test(obj6 != null); output.WriteLine("ok"); output.Write("testing id@AdapterId indirect proxy... "); output.Flush(); obj.shutdown(); manager.startServer(); try { obj2.IcePing(); } catch (LocalException) { test(false); } output.WriteLine("ok"); output.Write("testing id@ReplicaGroupId indirect proxy... "); output.Flush(); obj.shutdown(); manager.startServer(); try { obj6.IcePing(); } catch (LocalException) { test(false); } output.WriteLine("ok"); output.Write("testing identity indirect proxy... "); output.Flush(); obj.shutdown(); manager.startServer(); try { obj3.IcePing(); } catch (LocalException) { test(false); } try { obj2.IcePing(); } catch (LocalException) { test(false); } obj.shutdown(); manager.startServer(); try { obj2.IcePing(); } catch (LocalException) { test(false); } try { obj3.IcePing(); } catch (LocalException) { test(false); } obj.shutdown(); manager.startServer(); try { obj2.IcePing(); } catch (LocalException) { test(false); } obj.shutdown(); manager.startServer(); try { obj3.IcePing(); } catch (LocalException) { test(false); } obj.shutdown(); manager.startServer(); try { obj5 = Test.TestIntfPrx.CheckedCast(base5); obj5.IcePing(); } catch (LocalException) { test(false); } output.WriteLine("ok"); output.Write("testing proxy with unknown identity... "); output.Flush(); try { @base = IObjectPrx.Parse("unknown/unknown", communicator); @base.IcePing(); 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 = IObjectPrx.Parse("test @ TestAdapterUnknown", communicator); @base.IcePing(); 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(); var basencc = IObjectPrx.Parse("test@TestAdapter", communicator).Clone(connectionCached: false); int count = locator.getRequestCount(); basencc.Clone(locatorCacheTimeout: 0).IcePing(); // No locator cache. test(++count == locator.getRequestCount()); basencc.Clone(locatorCacheTimeout: 0).IcePing(); // No locator cache. test(++count == locator.getRequestCount()); basencc.Clone(locatorCacheTimeout: 2).IcePing(); // 2s timeout. test(count == locator.getRequestCount()); System.Threading.Thread.Sleep(1300); // 1300ms basencc.Clone(locatorCacheTimeout: 1).IcePing(); // 1s timeout. test(++count == locator.getRequestCount()); IObjectPrx.Parse("test", communicator).Clone(locatorCacheTimeout: 0).IcePing(); // No locator cache. count += 2; test(count == locator.getRequestCount()); IObjectPrx.Parse("test", communicator).Clone(locatorCacheTimeout: 2).IcePing(); // 2s timeout test(count == locator.getRequestCount()); System.Threading.Thread.Sleep(1300); // 1300ms IObjectPrx.Parse("test", communicator).Clone(locatorCacheTimeout: 1).IcePing(); // 1s timeout count += 2; test(count == locator.getRequestCount()); IObjectPrx.Parse("test@TestAdapter", communicator).Clone(locatorCacheTimeout: -1).IcePing(); test(count == locator.getRequestCount()); IObjectPrx.Parse("test", communicator).Clone(locatorCacheTimeout: -1).IcePing(); test(count == locator.getRequestCount()); IObjectPrx.Parse("test@TestAdapter", communicator).IcePing(); test(count == locator.getRequestCount()); IObjectPrx.Parse("test", communicator).IcePing(); test(count == locator.getRequestCount()); test(IObjectPrx.Parse("test", communicator).Clone(locatorCacheTimeout: 99).LocatorCacheTimeout == 99); output.WriteLine("ok"); output.Write("testing proxy from server... "); output.Flush(); obj = TestIntfPrx.Parse("test@TestAdapter", communicator); var hello = obj.getHello(); test(hello.AdapterId.Equals("TestAdapter")); hello.sayHello(); hello = obj.getReplicatedHello(); test(hello.AdapterId.Equals("ReplicatedAdapter")); hello.sayHello(); output.WriteLine("ok"); output.Write("testing locator request queuing... "); output.Flush(); hello = obj.getReplicatedHello().Clone(locatorCacheTimeout: 0, connectionCached: false); count = locator.getRequestCount(); hello.IcePing(); 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 = hello.Clone(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 { IObjectPrx.Parse("test@TestAdapter3", communicator).IcePing(); test(false); } catch (NotRegisteredException ex) { test(ex.kindOfObject == "object adapter"); test(ex.id.Equals("TestAdapter3")); } registry.setAdapterDirectProxy("TestAdapter3", locator.findAdapterById("TestAdapter")); try { IObjectPrx.Parse("test@TestAdapter3", communicator).IcePing(); registry.setAdapterDirectProxy("TestAdapter3", IObjectPrx.Parse($"dummy:{helper.getTestEndpoint(99)}", communicator)); IObjectPrx.Parse("test@TestAdapter3", communicator).IcePing(); } catch (LocalException) { test(false); } try { IObjectPrx.Parse("test@TestAdapter3", communicator).Clone(locatorCacheTimeout: 0).IcePing(); test(false); } catch (LocalException) { } try { IObjectPrx.Parse("test@TestAdapter3", communicator).IcePing(); test(false); } catch (LocalException) { } registry.setAdapterDirectProxy("TestAdapter3", locator.findAdapterById("TestAdapter")); try { IObjectPrx.Parse("test@TestAdapter3", communicator).IcePing(); } catch (LocalException) { test(false); } output.WriteLine("ok"); output.Write("testing well-known object locator cache... "); output.Flush(); registry.addObject(IObjectPrx.Parse("test3@TestUnknown", communicator)); try { IObjectPrx.Parse("test3", communicator).IcePing(); test(false); } catch (NotRegisteredException ex) { test(ex.kindOfObject == "object adapter"); test(ex.id.Equals("TestUnknown")); } registry.addObject(IObjectPrx.Parse("test3@TestAdapter4", communicator)); // Update registry.setAdapterDirectProxy("TestAdapter4", IObjectPrx.Parse($"dummy:{helper.getTestEndpoint(99)}", communicator)); try { IObjectPrx.Parse("test3", communicator).IcePing(); test(false); } catch (LocalException) { } registry.setAdapterDirectProxy("TestAdapter4", locator.findAdapterById("TestAdapter")); try { IObjectPrx.Parse("test3", communicator).IcePing(); } catch (LocalException) { test(false); } registry.setAdapterDirectProxy("TestAdapter4", IObjectPrx.Parse($"dummy:{helper.getTestEndpoint(99)}", communicator)); try { IObjectPrx.Parse("test3", communicator).IcePing(); } catch (LocalException) { test(false); } try { IObjectPrx.Parse("test@TestAdapter4", communicator).Clone(locatorCacheTimeout: 0).IcePing(); test(false); } catch (LocalException) { } try { IObjectPrx.Parse("test@TestAdapter4", communicator).IcePing(); test(false); } catch (LocalException) { } try { IObjectPrx.Parse("test3", communicator).IcePing(); test(false); } catch (LocalException) { } registry.addObject(IObjectPrx.Parse("test3@TestAdapter", communicator)); try { IObjectPrx.Parse("test3", communicator).IcePing(); } catch (LocalException) { test(false); } registry.addObject(IObjectPrx.Parse("test4", communicator)); try { IObjectPrx.Parse("test4", communicator).IcePing(); test(false); } catch (NoEndpointException) { } output.WriteLine("ok"); output.Write("testing locator cache background updates... "); output.Flush(); { Dictionary <string, string> properties = communicator.GetProperties(); properties["Ice.BackgroundLocatorCacheUpdates"] = "1"; Communicator ic = helper.initialize(properties); registry.setAdapterDirectProxy("TestAdapter5", locator.findAdapterById("TestAdapter")); registry.addObject(IObjectPrx.Parse("test3@TestAdapter", communicator)); count = locator.getRequestCount(); IObjectPrx.Parse("test@TestAdapter5", ic).Clone(locatorCacheTimeout: 0).IcePing(); // No locator cache. IObjectPrx.Parse("test3", ic).Clone(locatorCacheTimeout: 0).IcePing(); // No locator cache. count += 3; test(count == locator.getRequestCount()); registry.setAdapterDirectProxy("TestAdapter5", null); registry.addObject(IObjectPrx.Parse($"test3:{helper.getTestEndpoint(99)}", communicator)); IObjectPrx.Parse("test@TestAdapter5", ic).Clone(locatorCacheTimeout: 10).IcePing(); // 10s timeout. IObjectPrx.Parse("test3", ic).Clone(locatorCacheTimeout: 10).IcePing(); // 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. IObjectPrx.Parse("test@TestAdapter5", ic).Clone(locatorCacheTimeout: 1).IcePing(); // 1s timeout. IObjectPrx.Parse("test3", ic).Clone(locatorCacheTimeout: 1).IcePing(); // 1s timeout. try { while (true) { IObjectPrx.Parse("test@TestAdapter5", ic).Clone(locatorCacheTimeout: 1).IcePing(); // 1s timeout. System.Threading.Thread.Sleep(10); } } catch (LocalException) { // Expected to fail once they endpoints have been updated in the background. } try { while (true) { IObjectPrx.Parse("test3", ic).Clone(locatorCacheTimeout: 1).IcePing(); // 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 = HelloPrx.Parse("hello", communicator); obj.migrateHello(); hello.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 = HelloPrx.Parse("hello", communicator); count = locator.getRequestCount(); IObjectPrx.Parse("test@TestAdapter", communicator).Clone(encodingVersion: Util.Encoding_1_1).IcePing(); test(count == locator.getRequestCount()); IObjectPrx.Parse("test@TestAdapter10", communicator).Clone(encodingVersion: Util.Encoding_1_0).IcePing(); test(++count == locator.getRequestCount()); IObjectPrx.Parse("test -e 1.0@TestAdapter10-2", communicator).IcePing(); 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.IcePing(); test(false); } catch (LocalException) { } try { obj3.IcePing(); test(false); } catch (LocalException) { } try { obj5.IcePing(); test(false); } catch (LocalException) { } output.WriteLine("ok"); output.Write("testing indirect proxies to collocated objects... "); output.Flush(); communicator.SetProperty("Hello.AdapterId", Guid.NewGuid().ToString()); ObjectAdapter adapter = communicator.createObjectAdapterWithEndpoints("Hello", "default"); var id = new Identity(Guid.NewGuid().ToString(), ""); adapter.Add(new HelloI(), id); adapter.Activate(); // Ensure that calls on the well-known proxy is collocated. HelloPrx?helloPrx = HelloPrx.Parse("\"" + id.ToString(communicator.ToStringMode) + "\"", communicator); test(helloPrx.GetConnection() == null); // Ensure that calls on the indirect proxy (with adapter ID) is collocated helloPrx = HelloPrx.CheckedCast(adapter.CreateIndirectProxy(id)); test(helloPrx != null && helloPrx.GetConnection() == null); // Ensure that calls on the direct proxy is collocated helloPrx = HelloPrx.CheckedCast(adapter.CreateDirectProxy(id)); test(helloPrx != null && helloPrx.GetConnection() == null); output.WriteLine("ok"); output.Write("shutdown server manager... "); output.Flush(); manager.shutdown(); output.WriteLine("ok"); }
public void setDefaultRouter(RouterPrx router) { instance_.setDefaultRouter(router); }
// // 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 = instance_.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; } }
connected(RouterPrx router, SessionPrx session) { // // Remote invocation should be done without acquiring a mutex lock. // Debug.Assert(router != null); Ice.Connection conn = router.ice_getCachedConnection(); string category = router.getCategoryForClient(); int acmTimeout = 0; try { acmTimeout = router.getACMTimeout(); } catch(Ice.OperationNotExistException) { } if(acmTimeout <= 0) { acmTimeout = (int)router.getSessionTimeout(); } // // We create the callback object adapter here because createObjectAdapter internally // makes synchronous RPCs to the router. We can't create the OA on-demand when the // client calls objectAdapter() or addWithUUID() because they can be called from the // GUI thread. // if(_useCallbacks) { Debug.Assert(_adapter == null); _adapter = _communicator.createObjectAdapterWithRouter("", router); _adapter.activate(); } lock(this) { _router = router; if(_destroy) { // // Run destroyInternal in a thread because it makes remote invocations. // Thread t = new Thread(new ThreadStart(destroyInternal)); t.Start(); return; } // // Cache the category. // _category = category; // // Assign the session after _destroy is checked. // _session = session; _connected = true; if(acmTimeout > 0) { Ice.Connection connection = _router.ice_getCachedConnection(); Debug.Assert(connection != null); connection.setACM(acmTimeout, Ice.Util.None, Ice.ACMHeartbeat.HeartbeatAlways); connection.setCloseCallback(_ => destroy()); } } dispatchCallback(() => { try { _callback.connected(this); } catch(Glacier2.SessionNotExistException) { destroy(); } }, conn); }
connected(RouterPrx router, SessionPrx session) { // // Remote invocation should be done without acquiring a mutex lock. // Debug.Assert(router != null); Ice.Connection conn = router.ice_getCachedConnection(); string category = router.getCategoryForClient(); int acmTimeout = 0; try { acmTimeout = router.getACMTimeout(); } catch (Ice.OperationNotExistException) { } if (acmTimeout <= 0) { acmTimeout = (int)router.getSessionTimeout(); } // // We create the callback object adapter here because createObjectAdapter internally // makes synchronous RPCs to the router. We can't create the OA on-demand when the // client calls objectAdapter() or addWithUUID() because they can be called from the // GUI thread. // if (_useCallbacks) { Debug.Assert(_adapter == null); _adapter = _communicator.createObjectAdapterWithRouter("", router); _adapter.activate(); } lock (_mutex) { _router = router; if (_destroy) { // // Run destroyInternal in a thread because it makes remote invocations. // Thread t = new Thread(new ThreadStart(destroyInternal)); t.Start(); return; } // // Cache the category. // _category = category; // // Assign the session after _destroy is checked. // _session = session; _connected = true; if (acmTimeout > 0) { Ice.Connection connection = _router.ice_getCachedConnection(); Debug.Assert(connection != null); connection.setACM(acmTimeout, Ice.Util.None, Ice.ACMHeartbeat.HeartbeatAlways); connection.setCloseCallback(_ => destroy()); } } dispatchCallback(() => { try { _callback.connected(this); } catch (SessionNotExistException) { destroy(); } }, conn); }
public static Test.BackgroundPrx allTests(Test.TestHelper helper) { Communicator communicator = helper.communicator(); var background = BackgroundPrx.Parse($"background:{helper.getTestEndpoint(0)}", communicator); var backgroundController = BackgroundControllerPrx.Parse("backgroundController:" + helper.getTestEndpoint(1, "tcp"), communicator); Configuration configuration = Configuration.getInstance(); Console.Write("testing connect... "); Console.Out.Flush(); { connectTests(configuration, background); } Console.Out.WriteLine("ok"); Console.Write("testing initialization... "); Console.Out.Flush(); { initializeTests(configuration, background, backgroundController); } Console.Out.WriteLine("ok"); Console.Write("testing connection validation... "); Console.Out.Flush(); { validationTests(configuration, background, backgroundController); } Console.Out.WriteLine("ok"); Console.Write("testing read/write... "); Console.Out.Flush(); { readWriteTests(configuration, background, backgroundController); } Console.Out.WriteLine("ok"); Console.Write("testing locator... "); Console.Out.Flush(); { var locator = LocatorPrx.Parse($"locator:{helper.getTestEndpoint(0)}", communicator).Clone( invocationTimeout: 250); var obj = IObjectPrx.Parse("background@Test", communicator).Clone(locator: locator, oneway: true); backgroundController.pauseCall("findAdapterById"); try { obj.IcePing(); test(false); } catch (Ice.TimeoutException) { } backgroundController.resumeCall("findAdapterById"); locator = LocatorPrx.Parse($"locator:{helper.getTestEndpoint(0)}", communicator).Clone(locator: locator); locator.IcePing(); var bg = BackgroundPrx.Parse("background@Test", communicator).Clone(locator: locator); backgroundController.pauseCall("findAdapterById"); var t1 = bg.opAsync(); var t2 = bg.opAsync(); test(!t1.IsCompleted); test(!t2.IsCompleted); backgroundController.resumeCall("findAdapterById"); t1.Wait(); t2.Wait(); test(t1.IsCompleted); test(t2.IsCompleted); } Console.Out.WriteLine("ok"); Console.Write("testing router... "); Console.Out.Flush(); { var router = RouterPrx.Parse($"router:{helper.getTestEndpoint(0)}", communicator).Clone( invocationTimeout: 250); var obj = IObjectPrx.Parse("background@Test", communicator).Clone(router: router, oneway: true); backgroundController.pauseCall("getClientProxy"); try { obj.IcePing(); test(false); } catch (Ice.TimeoutException) { } backgroundController.resumeCall("getClientProxy"); router = RouterPrx.Parse($"router:{helper.getTestEndpoint(0)}", communicator); var bg = BackgroundPrx.Parse("background@Test", communicator).Clone(router: router); test(bg.Router != null); backgroundController.pauseCall("getClientProxy"); var t1 = bg.opAsync(); var t2 = bg.opAsync(); test(!t1.IsCompleted); test(!t2.IsCompleted); backgroundController.resumeCall("getClientProxy"); t1.Wait(); t2.Wait(); test(t1.IsCompleted); test(t2.IsCompleted); } Console.Out.WriteLine("ok"); bool ws = communicator.GetProperty("Ice.Default.Protocol") == "test-ws"; bool wss = communicator.GetProperty("Ice.Default.Protocol") == "test-wss"; if (!ws && !wss) { Console.Write("testing buffered transport... "); Console.Out.Flush(); configuration.buffered(true); backgroundController.buffered(true); background.opAsync(); background.GetCachedConnection() !.close(ConnectionClose.Forcefully); background.opAsync(); OpAMICallback cb = new OpAMICallback(); var results = new List <Task>(); for (int i = 0; i < 10000; ++i) { var t = background.opAsync().ContinueWith((Task p) => { try { p.Wait(); cb.responseNoOp(); } catch (Ice.Exception ex) { cb.noException(ex); } }); results.Add(t); if (i % 50 == 0) { backgroundController.holdAdapter(); backgroundController.resumeAdapter(); } if (i % 100 == 0) { t.Wait(); } } Task.WaitAll(results.ToArray()); Console.Out.WriteLine("ok"); } return(background); }
/// <summary> /// Creates a new proxy that is identical to this proxy, except for the router. /// </summary> /// <param name="router">The router for the new proxy.</param> /// <returns>The new proxy with the specified router.</returns> public ObjectPrx ice_router(RouterPrx router) { IceInternal.Reference @ref = _reference.changeRouter(router); if(@ref.Equals(_reference)) { return this; } else { return newInstance(@ref); } }
connected(RouterPrx router, SessionPrx session) { string category = router.getCategoryForClient(); long sessionTimeout = router.getSessionTimeout(); int acmTimeout = 0; try { acmTimeout = router.getACMTimeout(); } catch(Ice.OperationNotExistException) { } Ice.Connection conn = router.ice_getCachedConnection(); lock(this) { _router = router; if(_destroy) { // // Run the destroyInternal in a thread. This is because it // destroyInternal makes remote invocations. // Thread t = new Thread(new ThreadStart(destroyInternal)); t.Start(); return; } // // Cache the category. // _category = category; // // Assign the session after _destroy is checked. // _session = session; _connected = true; if(acmTimeout > 0) { Ice.Connection connection = _router.ice_getCachedConnection(); Debug.Assert(connection != null); connection.setACM(acmTimeout, Ice.Util.None, Ice.ACMHeartbeat.HeartbeatAlways); connection.setCallback(new ConnectionCallbackI(this)); } else if(sessionTimeout > 0) { IceInternal.Timer timer = IceInternal.Util.getInstance(communicator()).timer(); timer.scheduleRepeated(new SessionRefreshTask(this, _router), (sessionTimeout * 1000)/2); } } dispatchCallback(() => { try { _callback.connected(this); } catch(Glacier2.SessionNotExistException) { destroy(); } }, conn); }
connected(RouterPrx router, SessionPrx session) { string category = router.getCategoryForClient(); long timeout = router.getSessionTimeout(); Ice.Connection conn = router.ice_getCachedConnection(); lock(this) { _router = router; if(_destroy) { // // Run the destroyInternal in a thread. This is because it // destroyInternal makes remote invocations. // Thread t = new Thread(new ThreadStart(destroyInternal)); t.Start(); return; } // // Cache the category. // _category = category; // // Assign the session after _destroy is checked. // _session = session; _connected = true; Debug.Assert(_sessionRefresh == null); if(timeout > 0) { _sessionRefresh = new SessionRefreshThread(this, _router, (int)(timeout * 1000)/2); _refreshThread = new Thread(new ThreadStart(_sessionRefresh.run)); _refreshThread.Start(); } } dispatchCallback(delegate() { try { _callback.connected(this); } catch(Glacier2.SessionNotExistException) { destroy(); } }, conn); }
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.IObjectPrx @base = IObjectPrx.Parse(@ref, communicator); test(@base != null); output.WriteLine("ok"); output.Write("testing checked cast... "); output.Flush(); var obj = Test.TestIntfPrx.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 (ArgumentException) { } 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 comm = new Communicator(communicator.GetProperties()); IObjectPrx.Parse($"test:{helper.getTestEndpoint(0)}", communicator).IcePingAsync(); comm.destroy(); } output.WriteLine("ok"); } output.Write("testing object adapter published endpoints... "); output.Flush(); { communicator.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")); var prx = IObjectPrx.Parse("dummy:tcp -h localhost -p 12346 -t 20000:tcp -h localhost -p 12347 -t 10000", communicator); adapter.SetPublishedEndpoints(prx.Endpoints); test(adapter.GetPublishedEndpoints().Length == 2); test(Collections.Equals(adapter.CreateProxy(new Identity("dummy", "")).Endpoints, prx.Endpoints)); test(Collections.Equals(adapter.GetPublishedEndpoints(), prx.Endpoints)); adapter.RefreshPublishedEndpoints(); test(adapter.GetPublishedEndpoints().Length == 1); test(adapter.GetPublishedEndpoints()[0].Equals(endpt)); communicator.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.GetConnection() != null) { output.Write("testing object adapter with bi-dir connection... "); output.Flush(); var adapter = communicator.createObjectAdapter(""); obj.GetConnection().setAdapter(adapter); obj.GetConnection().setAdapter(null); adapter.Deactivate(); try { obj.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 = RouterPrx.UncheckedCast(@base.Clone(routerId, 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.Endpoints); test(false); } catch (ArgumentException) { // Expected. } adapter.Destroy(); try { routerId.name = "test"; router = RouterPrx.UncheckedCast(@base.Clone(routerId)); communicator.createObjectAdapterWithRouter("", router); test(false); } catch (OperationNotExistException) { // Expected: the "test" object doesn't implement Ice::Router! } try { router = RouterPrx.Parse($"test:{helper.getTestEndpoint(1)}", communicator); 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.Clone(connectionTimeout: 100).IcePing(); // Use timeout to speed up testing on Windows test(false); } catch (LocalException) { output.WriteLine("ok"); } return(obj); }
connectImpl(ConnectStrategy factory) { Debug.Assert(!_destroy); new Thread(new ThreadStart(() => { try { lock (_mutex) { _communicator = new Communicator( properties: _properties, compactIdResolver: _compactIdResolver, dispatcher: _dispatcher, logger: _logger, observer: _observer, threadStart: _threadStart, threadStop: _threadStop, typeIdNamespaces: _typeIdNamespaces); } } catch (LocalException ex) { lock (_mutex) { _destroy = true; } dispatchCallback(() => _callback.connectFailed(this, ex), null); return; } if (_communicator.getDefaultRouter() == null) { var finder = RouterFinderPrx.Parse(_finderStr, _communicator); try { _communicator.setDefaultRouter(finder.getRouter()); } catch (CommunicatorDestroyedException ex) { dispatchCallback(() => _callback.connectFailed(this, ex), null); return; } catch (System.Exception) { // // In case of error getting router identity from RouterFinder use default identity. // _communicator.setDefaultRouter( Ice.RouterPrx.UncheckedCast(finder.Clone(new Identity("router", "Glacier2")))); } } try { dispatchCallbackAndWait(() => _callback.createdCommunicator(this)); Ice.RouterPrx?defaultRouter = _communicator.getDefaultRouter(); Debug.Assert(defaultRouter != null); RouterPrx routerPrx = RouterPrx.UncheckedCast(defaultRouter); SessionPrx session = factory(routerPrx); connected(routerPrx, session); } catch (System.Exception ex) { _communicator.destroy(); dispatchCallback(() => _callback.connectFailed(this, ex), null); } })).Start(); }