// // Implementation of Reference.GetConnectionCallback // public void setConnection(Ice.ConnectionI connection, bool compress) { lock (this) { Debug.Assert(_exception == null && _connection == null); _connection = connection; _compress = compress; } // // If this proxy is for a non-local object, and we are using a router, then // add this proxy to the router info object. // RouterInfo ri = _reference.getRouterInfo(); if (ri != null && !ri.addProxy(_proxy, this)) { return; // The request handler will be initialized once addProxy returns. } // // We can now send the queued requests. // flushRequests(); }
public void SetRouterInfo(RouterInfo routerInfo) { Debug.Assert(routerInfo != null); ObjectAdapter? adapter = routerInfo.Adapter; IReadOnlyList <Endpoint> endpoints = routerInfo.GetClientEndpoints(); // Must be called outside the synchronization lock (this) { if (_destroyed) { throw new CommunicatorDestroyedException(); } // // Search for connections to the router's client proxy // endpoints, and update the object adapter for such // connections, so that callbacks from the router can be // received over such connections. // for (int i = 0; i < endpoints.Count; ++i) { Endpoint endpoint = endpoints[i]; // // Modify endpoints with overrides. // if (_communicator.OverrideTimeout != null) { endpoint = endpoint.NewTimeout(_communicator.OverrideTimeout.Value); } // // The ConnectionI object does not take the compression flag of // endpoints into account, but instead gets the information // about whether messages should be compressed or not from // other sources. In order to allow connection sharing for // endpoints that differ in the value of the compression flag // only, we always set the compression flag to false here in // this connection factory. // endpoint = endpoint.NewCompressionFlag(false); foreach (ICollection <Connection> connections in _connections.Values) { foreach (Connection connection in connections) { if (connection.Endpoint == endpoint) { connection.Adapter = adapter; } } } } } }
public override bool Equals(object obj) { if (ReferenceEquals(this, obj)) { return(true); } RouterInfo rhs = obj as RouterInfo; return(rhs == null ? false : _router.Equals(rhs._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); } }
// // Returns router info for a given router. Automatically creates // the router info if it doesn't exist yet. // public RouterInfo erase(Ice.RouterPrx rtr) { RouterInfo info = null; if (rtr != null) { // // The router cannot be routed. // Ice.RouterPrx router = Ice.RouterPrxHelper.uncheckedCast(rtr.ice_router(null)); lock (this) { if (_table.TryGetValue(router, out info)) { _table.Remove(router); } } } return(info); }
// // 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); }
// // Returns router info for a given router. Automatically creates // the router info if it doesn't exist yet. // public RouterInfo get(Ice.RouterPrx rtr) { if (rtr == null) { return(null); } // // The router cannot be routed. // Ice.RouterPrx router = Ice.RouterPrxHelper.uncheckedCast(rtr.ice_router(null)); lock (this) { RouterInfo info = null; if (!_table.TryGetValue(router, out info)) { info = new RouterInfo(router); _table.Add(router, info); } return(info); } }
// // Returns router info for a given router. Automatically creates // the router info if it doesn't exist yet. // public RouterInfo get(Ice.RouterPrx rtr) { if(rtr == null) { return null; } // // The router cannot be routed. // Ice.RouterPrx router = Ice.RouterPrxHelper.uncheckedCast(rtr.ice_router(null)); lock(this) { RouterInfo info = null; if(!_table.TryGetValue(router, out info)) { info = new RouterInfo(router); _table.Add(router, info); } return info; } }
public void destroy() { // // Deactivate and wait for completion. // deactivate(); waitForDeactivate(); lock(this) { // // Only a single thread is allowed to destroy the object // adapter. Other threads wait for the destruction to be // completed. // while(state_ == StateDestroying) { System.Threading.Monitor.Wait(this); } if(state_ == StateDestroyed) { return; } state_ = StateDestroying; } // // Now it's also time to clean up our servants and servant // locators. // _servantManager.destroy(); // // Destroy the thread pool. // if(_threadPool != null) { _threadPool.destroy(); _threadPool.joinWithAllThreads(); } if(_objectAdapterFactory != null) { _objectAdapterFactory.removeObjectAdapter(this); } lock(this) { // // We're done, now we can throw away all incoming connection // factories. // _incomingConnectionFactories.Clear(); // // Remove object references (some of them cyclic). // instance_ = null; _threadPool = null; _routerEndpoints = null; _routerInfo = null; _publishedEndpoints = null; _locatorInfo = null; _reference = null; _objectAdapterFactory = null; state_ = StateDestroyed; System.Threading.Monitor.PulseAll(this); } }
// // 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; } }
private Reference create(Ice.Identity ident, string facet, Reference.Mode mode, bool secure, Ice.ProtocolVersion protocol, Ice.EncodingVersion encoding, EndpointI[] endpoints, string adapterId, string propertyPrefix) { DefaultsAndOverrides defaultsAndOverrides = instance_.defaultsAndOverrides(); // // Default local proxy options. // LocatorInfo locatorInfo = null; if (_defaultLocator != null) { if (!((Ice.ObjectPrxHelperBase)_defaultLocator).reference__().getEncoding().Equals(encoding)) { locatorInfo = instance_.locatorManager().get( (Ice.LocatorPrx)_defaultLocator.ice_encodingVersion(encoding)); } else { locatorInfo = instance_.locatorManager().get(_defaultLocator); } } RouterInfo routerInfo = instance_.routerManager().get(_defaultRouter); bool collocOptimized = defaultsAndOverrides.defaultCollocationOptimization; bool cacheConnection = true; bool preferSecure = defaultsAndOverrides.defaultPreferSecure; Ice.EndpointSelectionType endpointSelection = defaultsAndOverrides.defaultEndpointSelection; int locatorCacheTimeout = defaultsAndOverrides.defaultLocatorCacheTimeout; int invocationTimeout = defaultsAndOverrides.defaultInvocationTimeout; Dictionary <string, string> context = null; // // Override the defaults with the proxy properties if a property prefix is defined. // if (propertyPrefix != null && propertyPrefix.Length > 0) { Ice.Properties properties = instance_.initializationData().properties; // // Warn about unknown properties. // if (properties.getPropertyAsIntWithDefault("Ice.Warn.UnknownProperties", 1) > 0) { checkForUnknownProperties(propertyPrefix); } string property; property = propertyPrefix + ".Locator"; Ice.LocatorPrx locator = Ice.LocatorPrxHelper.uncheckedCast(_communicator.propertyToProxy(property)); if (locator != null) { if (!((Ice.ObjectPrxHelperBase)locator).reference__().getEncoding().Equals(encoding)) { locatorInfo = instance_.locatorManager().get( (Ice.LocatorPrx)locator.ice_encodingVersion(encoding)); } else { locatorInfo = instance_.locatorManager().get(locator); } } property = propertyPrefix + ".Router"; Ice.RouterPrx router = Ice.RouterPrxHelper.uncheckedCast(_communicator.propertyToProxy(property)); if (router != null) { if (propertyPrefix.EndsWith(".Router", StringComparison.Ordinal)) { string s = "`" + property + "=" + properties.getProperty(property) + "': cannot set a router on a router; setting ignored"; instance_.initializationData().logger.warning(s); } else { routerInfo = instance_.routerManager().get(router); } } property = propertyPrefix + ".CollocationOptimized"; collocOptimized = properties.getPropertyAsIntWithDefault(property, collocOptimized ? 1 : 0) > 0; property = propertyPrefix + ".ConnectionCached"; cacheConnection = properties.getPropertyAsIntWithDefault(property, cacheConnection ? 1 : 0) > 0; property = propertyPrefix + ".PreferSecure"; preferSecure = properties.getPropertyAsIntWithDefault(property, preferSecure ? 1 : 0) > 0; property = propertyPrefix + ".EndpointSelection"; if (properties.getProperty(property).Length > 0) { string type = properties.getProperty(property); if (type.Equals("Random")) { endpointSelection = Ice.EndpointSelectionType.Random; } else if (type.Equals("Ordered")) { endpointSelection = Ice.EndpointSelectionType.Ordered; } else { throw new Ice.EndpointSelectionTypeParseException("illegal value `" + type + "'; expected `Random' or `Ordered'"); } } property = propertyPrefix + ".LocatorCacheTimeout"; string val = properties.getProperty(property); if (val.Length > 0) { locatorCacheTimeout = properties.getPropertyAsIntWithDefault(property, locatorCacheTimeout); if (locatorCacheTimeout < -1) { locatorCacheTimeout = -1; StringBuilder msg = new StringBuilder("invalid value for "); msg.Append(property); msg.Append(" `"); msg.Append(properties.getProperty(property)); msg.Append("': defaulting to -1"); instance_.initializationData().logger.warning(msg.ToString()); } } property = propertyPrefix + ".InvocationTimeout"; val = properties.getProperty(property); if (val.Length > 0) { invocationTimeout = properties.getPropertyAsIntWithDefault(property, invocationTimeout); if (invocationTimeout < 1 && invocationTimeout != -1) { invocationTimeout = -1; StringBuilder msg = new StringBuilder("invalid value for "); msg.Append(property); msg.Append(" `"); msg.Append(properties.getProperty(property)); msg.Append("': defaulting to -1"); instance_.initializationData().logger.warning(msg.ToString()); } } property = propertyPrefix + ".Context."; Dictionary <string, string> contexts = properties.getPropertiesForPrefix(property); if (contexts.Count != 0) { context = new Dictionary <string, string>(); foreach (KeyValuePair <string, string> e in contexts) { context.Add(e.Key.Substring(property.Length), e.Value); } } } // // Create new reference // return(new RoutableReference(instance_, _communicator, ident, facet, mode, secure, protocol, encoding, endpoints, adapterId, locatorInfo, routerInfo, collocOptimized, cacheConnection, preferSecure, endpointSelection, locatorCacheTimeout, invocationTimeout, context)); }
private int _timeout; // Only used if _overrideTimeout == true #endregion Fields #region Constructors public RoutableReference(Instance instance, Ice.Communicator communicator, Ice.Identity identity, string facet, Reference.Mode mode, bool secure, EndpointI[] endpoints, string adapterId, LocatorInfo locatorInfo, RouterInfo routerInfo, bool collocationOptimized, bool cacheConnection, bool preferSecure, Ice.EndpointSelectionType endpointSelection, int locatorCacheTimeout) : base(instance, communicator, identity, facet, mode, secure) { _endpoints = endpoints; _adapterId = adapterId; _locatorInfo = locatorInfo; _routerInfo = routerInfo; _collocationOptimized = collocationOptimized; _cacheConnection = cacheConnection; _preferSecure = preferSecure; _endpointSelection = endpointSelection; _locatorCacheTimeout = locatorCacheTimeout; _overrideTimeout = false; _timeout = -1; if(_endpoints == null) { _endpoints = _emptyEndpoints; } if(_adapterId == null) { _adapterId = ""; } Debug.Assert(_adapterId.Length == 0 || _endpoints.Length == 0); }
internal GetClientProxyCallback(RouterInfo info, GetClientEndpointsCallback callback) { _info = info; _callback = callback; }
internal AddProxiesCallback(RouterInfo info, Ice.ObjectPrx prx, AddProxyCallback callback) { _info = info; _prx = prx; _callback = callback; }