private ObjectAdapter AddObjectAdapter(
            string?name                 = null,
            bool serializeDispatch      = false,
            TaskScheduler?taskScheduler = null,
            IRouterPrx?router           = null)
        {
            if (name != null && name.Length == 0)
            {
                throw new ArgumentException("the empty string is not a valid object adapter name", nameof(name));
            }

            lock (_mutex)
            {
                if (IsDisposed)
                {
                    throw new CommunicatorDisposedException();
                }

                if (name != null)
                {
                    if (_adapterNamesInUse.Contains(name))
                    {
                        throw new ArgumentException($"an object adapter with name `{name}' is already registered",
                                                    nameof(name));
                    }
                    _adapterNamesInUse.Add(name);
                }
            }

            // Must be called outside the synchronization since the constructor can make client invocations
            // on the router if it's set.
            ObjectAdapter adapter;

            try
            {
                adapter = new ObjectAdapter(this, name ?? "", serializeDispatch, taskScheduler, router);
            }
            catch
            {
                if (name != null)
                {
                    lock (_mutex)
                    {
                        _adapterNamesInUse.Remove(name);
                    }
                }
                throw;
            }

            lock (_mutex)
            {
                if (IsDisposed)
                {
                    adapter.Dispose();
                    throw new CommunicatorDisposedException();
                }
                _adapters.Add(adapter);
                return(adapter);
            }
        }
예제 #2
0
        private ObjectAdapter AddObjectAdapter(string?name = null, IRouterPrx?router = null)
        {
            if (name != null && name.Length == 0)
            {
                throw new ArgumentException("the empty string is not a valid object adapter name", nameof(name));
            }

            lock (this)
            {
                if (_isShutdown)
                {
                    throw new CommunicatorDestroyedException();
                }

                if (name != null)
                {
                    if (_adapterNamesInUse.Contains(name))
                    {
                        throw new ArgumentException($"an object adapter with name `{name}' is already registered",
                                                    nameof(name));
                    }
                    _adapterNamesInUse.Add(name);
                }
            }

            // Must be called outside the synchronization since the constructor can make client invocations
            // on the router if it's set.
            ObjectAdapter?adapter = null;

            try
            {
                adapter = new ObjectAdapter(this, name ?? "", router);
                lock (this)
                {
                    if (_isShutdown)
                    {
                        throw new CommunicatorDestroyedException();
                    }
                    _adapters.Add(adapter);
                    return(adapter);
                }
            }
            catch (System.Exception)
            {
                if (adapter != null)
                {
                    adapter.Destroy();
                }

                if (name != null)
                {
                    lock (this)
                    {
                        _adapterNamesInUse.Remove(name);
                    }
                }
                throw;
            }
        }
예제 #3
0
파일: Proxy.cs 프로젝트: shawvi/ice
 /// <summary>Creates a clone of this proxy, with a new identity and optionally other options. The clone
 /// is identical to this proxy except for its identity and other options set through parameters.</summary>
 /// <param name="prx">The source proxy.</param>
 /// <param name="identity">The identity of the clone.</param>
 /// <param name="factory">The proxy factory used to manufacture the clone.</param>
 /// <param name="adapterId">The adapter ID of the clone (optional).</param>
 /// <param name="cacheConnection">Determines whether or not the clone caches its connection (optional).</param>
 /// <param name="clearLocator">When set to true, the clone does not have an associated locator proxy (optional).
 /// </param>
 /// <param name="clearRouter">When set to true, the clone does not have an associated router proxy (optional).
 /// </param>
 /// <param name="collocationOptimized">Determines whether or not the clone can use collocation optimization
 /// (optional).</param>
 /// <param name="compress">Determines whether or not the clone compresses requests (optional).</param>
 /// <param name="connectionId">The connection ID of the clone (optional).</param>
 /// <param name="connectionTimeout">The connection timeout of the clone (optional).</param>
 /// <param name="context">The context of the clone (optional).</param>
 /// <param name="encoding">The encoding of the clone (optional).</param>
 /// <param name="endpointSelection">The encoding selection policy of the clone (optional).</param>
 /// <param name="endpoints">The endpoints of the clone (optional).</param>
 /// <param name="facet">The facet of the clone (optional).</param>
 /// <param name="fixedConnection">The connection of the clone (optional). When specified, the clone is a fixed
 /// proxy. You can clone a non-fixed proxy into a fixed proxy but not vice-versa.</param>
 /// <param name="invocationMode">The invocation mode of the clone (optional).</param>
 /// <param name="invocationTimeout">The invocation timeout of the clone (optional).</param>
 /// <param name="locator">The locator proxy of the clone (optional).</param>
 /// <param name="locatorCacheTimeout">The locator cache timeout of the clone (optional).</param>
 /// <param name="oneway">Determines whether the clone is oneway or twoway (optional). This is a simplified
 /// version of the invocationMode parameter.</param>
 /// <param name="preferSecure">Determines whether the clone prefers secure connections over non-secure
 /// connections (optional).</param>
 /// <param name="protocol">The Ice protocol of the clone (optional).</param>
 /// <param name="router">The router proxy of the clone (optional).</param>
 /// <param name="secure">The secure option of the clone (optional).</param>
 /// <returns>A new proxy manufactured by the proxy factory (see factory parameter).</returns>
 public static T Clone <T>(this IObjectPrx prx,
                           Identity identity,
                           ProxyFactory <T> factory,
                           string?adapterId          = null,
                           bool?cacheConnection      = null,
                           bool clearLocator         = false,
                           bool clearRouter          = false,
                           bool?collocationOptimized = null,
                           bool?compress             = null,
                           string?connectionId       = null,
                           int?connectionTimeout     = null,
                           IReadOnlyDictionary <string, string>?context = null,
                           Encoding?encoding = null,
                           EndpointSelectionType?endpointSelection = null,
                           IEndpoint[]?endpoints         = null,
                           string?facet                  = null,
                           Connection?fixedConnection    = null,
                           InvocationMode?invocationMode = null,
                           int?invocationTimeout         = null,
                           ILocatorPrx?locator           = null,
                           int?locatorCacheTimeout       = null,
                           bool?oneway       = null,
                           bool?preferSecure = null,
                           Protocol?protocol = null,
                           IRouterPrx?router = null,
                           bool?secure       = null) where T : class, IObjectPrx
 {
     return(factory(prx.IceReference.Clone(adapterId,
                                           cacheConnection,
                                           clearLocator,
                                           clearRouter,
                                           collocationOptimized,
                                           compress,
                                           connectionId,
                                           connectionTimeout,
                                           context,
                                           encoding,
                                           endpointSelection,
                                           endpoints?.Select(e => (Endpoint)e).ToArray(),
                                           facet,
                                           fixedConnection,
                                           identity,
                                           invocationMode,
                                           invocationTimeout,
                                           locator,
                                           locatorCacheTimeout,
                                           oneway,
                                           preferSecure,
                                           protocol,
                                           router,
                                           secure)));
 }
예제 #4
0
파일: Proxy.cs 프로젝트: shawvi/ice
        /// <summary>Creates a clone of this proxy. The clone is identical to this proxy except for options set
        /// through parameters. This method returns this proxy instead of a new proxy in the event none of the options
        /// specified through the parameters change this proxy's options.</summary>
        /// <param name="prx">The source proxy.</param>
        /// <param name="adapterId">The adapter ID of the clone (optional).</param>
        /// <param name="cacheConnection">Determines whether or not the clone caches its connection (optional).</param>
        /// <param name="clearLocator">When set to true, the clone does not have an associated locator proxy (optional).
        /// </param>
        /// <param name="clearRouter">When set to true, the clone does not have an associated router proxy (optional).
        /// </param>
        /// <param name="collocationOptimized">Determines whether or not the clone can use collocation optimization
        /// (optional).</param>
        /// <param name="compress">Determines whether or not the clone compresses requests (optional).</param>
        /// <param name="connectionId">The connection ID of the clone (optional).</param>
        /// <param name="connectionTimeout">The connection timeout of the clone (optional).</param>
        /// <param name="context">The context of the clone (optional).</param>
        /// <param name="encoding">The encoding of the clone (optional).</param>
        /// <param name="endpointSelection">The encoding selection policy of the clone (optional).</param>
        /// <param name="endpoints">The endpoints of the clone (optional).</param>
        /// <param name="fixedConnection">The connection of the clone (optional). When specified, the clone is a fixed
        /// proxy. You can clone a non-fixed proxy into a fixed proxy but not vice-versa.</param>
        /// <param name="invocationMode">The invocation mode of the clone (optional).</param>
        /// <param name="invocationTimeout">The invocation timeout of the clone (optional).</param>
        /// <param name="locator">The locator proxy of the clone (optional).</param>
        /// <param name="locatorCacheTimeout">The locator cache timeout of the clone (optional).</param>
        /// <param name="oneway">Determines whether the clone is oneway or twoway (optional). This is a simplified
        /// version of the invocationMode parameter.</param>
        /// <param name="preferSecure">Determines whether the clone prefers secure connections over non-secure
        /// connections (optional).</param>
        /// <param name="protocol">The Ice protocol of the clone (optional).</param>
        /// <param name="router">The router proxy of the clone (optional).</param>
        /// <param name="secure">The secure option of the clone (optional).</param>
        /// <returns>A new proxy with the same type as this proxy.</returns>
        public static T Clone <T>(this T prx,
                                  string?adapterId          = null,
                                  bool?cacheConnection      = null,
                                  bool clearLocator         = false,
                                  bool clearRouter          = false,
                                  bool?collocationOptimized = null,
                                  bool?compress             = null,
                                  string?connectionId       = null,
                                  int?connectionTimeout     = null,
                                  IReadOnlyDictionary <string, string>?context = null,
                                  Encoding?encoding = null,
                                  EndpointSelectionType?endpointSelection = null,
                                  IEndpoint[]?endpoints         = null,
                                  Connection?fixedConnection    = null,
                                  InvocationMode?invocationMode = null,
                                  int?invocationTimeout         = null,
                                  ILocatorPrx?locator           = null,
                                  int?locatorCacheTimeout       = null,
                                  bool?oneway       = null,
                                  bool?preferSecure = null,
                                  Protocol?protocol = null,
                                  IRouterPrx?router = null,
                                  bool?secure       = null) where T : IObjectPrx
        {
            Reference clone = prx.IceReference.Clone(adapterId,
                                                     cacheConnection,
                                                     clearLocator,
                                                     clearRouter,
                                                     collocationOptimized,
                                                     compress,
                                                     connectionId,
                                                     connectionTimeout,
                                                     context,
                                                     encoding,
                                                     endpointSelection,
                                                     endpoints?.Select(e => (Endpoint)e).ToArray(),
                                                     facet: null,
                                                     fixedConnection,
                                                     identity: null,
                                                     invocationMode,
                                                     invocationTimeout,
                                                     locator,
                                                     locatorCacheTimeout,
                                                     oneway,
                                                     preferSecure,
                                                     protocol,
                                                     router,
                                                     secure);

            // Reference.Clone never returns a new reference == to itself.
            return(ReferenceEquals(clone, prx.IceReference) ? prx : (T)prx.Clone(clone));
        }
예제 #5
0
파일: Proxy.cs 프로젝트: yssource/ice
        public static IObjectPrx Clone(this IObjectPrx prx,
                                       string facet,
                                       string?adapterId          = null,
                                       bool clearLocator         = false,
                                       bool clearRouter          = false,
                                       bool?collocationOptimized = null,
                                       bool?compress             = null,
                                       bool?connectionCached     = null,
                                       string?connectionId       = null,
                                       int?connectionTimeout     = null,
                                       IReadOnlyDictionary <string, string>?context = null,
                                       Encoding?encoding = null,
                                       EndpointSelectionType?endpointSelectionType = null,
                                       IEndpoint[]?endpoints         = null,
                                       Connection?fixedConnection    = null,
                                       InvocationMode?invocationMode = null,
                                       int?invocationTimeout         = null,
                                       ILocatorPrx?locator           = null,
                                       int?locatorCacheTimeout       = null,
                                       bool?oneway       = null,
                                       bool?preferSecure = null,
                                       IRouterPrx?router = null,
                                       bool?secure       = null)
        {
            Reference reference = prx.IceReference.Clone(
                null,
                facet,
                adapterId,
                clearLocator,
                clearRouter,
                collocationOptimized,
                compress,
                connectionCached,
                connectionId,
                connectionTimeout,
                context,
                encoding,
                endpointSelectionType,
                endpoints,
                fixedConnection,
                invocationMode,
                invocationTimeout,
                locator,
                locatorCacheTimeout,
                oneway,
                preferSecure,
                router,
                secure);

            return(reference.Equals(prx.IceReference) ? prx : prx.Clone(reference));
        }
예제 #6
0
파일: Proxy.cs 프로젝트: mreinart/ice
        /// <summary>Creates a clone of this proxy. The clone is identical to this proxy except for options set
        /// through parameters. This method returns this proxy instead of a new proxy in the event none of the options
        /// specified through the parameters change this proxy's options.</summary>
        /// <param name="prx">The source proxy.</param>
        /// <param name="cacheConnection">Determines whether or not the clone caches its connection (optional).</param>
        /// <param name="clearLabel">When set to true, the clone does not have an associated label (optional).</param>
        /// <param name="clearLocator">When set to true, the clone does not have an associated locator proxy (optional).
        /// </param>
        /// <param name="clearRouter">When set to true, the clone does not have an associated router proxy (optional).
        /// </param>
        /// <param name="context">The context of the clone (optional).</param>
        /// <param name="encoding">The encoding of the clone (optional).</param>
        /// <param name="endpoints">The endpoints of the clone (optional).</param>
        /// <param name="fixedConnection">The connection of the clone (optional). When specified, the clone is a fixed
        /// proxy. You can clone a non-fixed proxy into a fixed proxy but not vice-versa.</param>
        /// <param name="invocationInterceptors">A collection of <see cref="InvocationInterceptor"/> that will be
        /// executed with each invocation</param>
        /// <param name="invocationMode">The invocation mode of the clone (optional). Applies only to ice1 proxies.
        /// </param>
        /// <param name="invocationTimeout">The invocation timeout of the clone (optional).</param>
        /// <param name="label">The label of the clone (optional).</param>
        /// <param name="location">The location of the clone (optional).</param>
        /// <param name="locator">The locator proxy of the clone (optional).</param>
        /// <param name="locatorCacheTimeout">The locator cache timeout of the clone (optional).</param>
        /// <param name="oneway">Determines whether the clone is oneway or twoway (optional).</param>
        /// <param name="preferExistingConnection">Determines whether or not the clone prefer using an existing
        /// connection.</param>
        /// <param name="preferNonSecure">Determines whether the clone prefers non-secure connections over secure
        /// connections (optional).</param>
        /// <param name="relative">When true, the new proxy is a relative proxy (optional).</param>
        /// <param name="router">The router proxy of the clone (optional).</param>
        /// <returns>A new proxy with the same type as this proxy.</returns>
        public static T Clone <T>(
            this T prx,
            bool?cacheConnection = null,
            bool clearLabel      = false,
            bool clearLocator    = false,
            bool clearRouter     = false,
            IReadOnlyDictionary <string, string>?context = null,
            Encoding?encoding = null,
            IEnumerable <Endpoint>?endpoints = null,
            Connection?fixedConnection       = null,
            IEnumerable <InvocationInterceptor>?invocationInterceptors = null,
            InvocationMode?invocationMode = null,
            TimeSpan?invocationTimeout    = null,
            object?label = null,
            IEnumerable <string>?location = null,
            ILocatorPrx?locator           = null,
            TimeSpan?locatorCacheTimeout  = null,
            bool?oneway = null,
            bool?preferExistingConnection = null,
            NonSecure?preferNonSecure     = null,
            bool?relative     = null,
            IRouterPrx?router = null) where T : IObjectPrx
        {
            Reference clone = prx.IceReference.Clone(cacheConnection,
                                                     clearLabel,
                                                     clearLocator,
                                                     clearRouter,
                                                     context,
                                                     encoding,
                                                     endpoints,
                                                     facet: null,
                                                     fixedConnection,
                                                     identity: null,
                                                     identityAndFacet: null,
                                                     invocationInterceptors,
                                                     invocationMode,
                                                     invocationTimeout,
                                                     label,
                                                     location,
                                                     locator,
                                                     locatorCacheTimeout,
                                                     oneway,
                                                     preferExistingConnection,
                                                     preferNonSecure,
                                                     relative,
                                                     router);

            // Reference.Clone never returns a new reference == to itself.
            return(ReferenceEquals(clone, prx.IceReference) ? prx : (T)prx.Clone(clone));
        }
예제 #7
0
파일: Proxy.cs 프로젝트: mreinart/ice
 /// <summary>Creates a clone of this proxy, with a new identity and optionally other options. The clone
 /// is identical to this proxy except for its identity and other options set through parameters.</summary>
 /// <param name="prx">The source proxy.</param>
 /// <param name="factory">The proxy factory used to manufacture the clone.</param>
 /// <param name="cacheConnection">Determines whether or not the clone caches its connection (optional).</param>
 /// <param name="clearLabel">When set to true, the clone does not have an associated label (optional).</param>
 /// <param name="clearLocator">When set to true, the clone does not have an associated locator proxy (optional).
 /// </param>
 /// <param name="clearRouter">When set to true, the clone does not have an associated router proxy (optional).
 /// </param>
 /// <param name="context">The context of the clone (optional).</param>
 /// <param name="encoding">The encoding of the clone (optional).</param>
 /// <param name="endpoints">The endpoints of the clone (optional).</param>
 /// <param name="facet">The facet of the clone (optional).</param>
 /// <param name="fixedConnection">The connection of the clone (optional). When specified, the clone is a fixed
 /// proxy. You can clone a non-fixed proxy into a fixed proxy but not vice-versa.</param>
 /// <param name="identity">The identity of the clone.</param>
 /// <param name="identityAndFacet">A relative URI string [category/]identity[#facet].</param>
 /// <param name="invocationInterceptors">A collection of <see cref="InvocationInterceptor"/> that will be
 /// executed with each invocation</param>
 /// <param name="invocationMode">The invocation mode of the clone (optional). Applies only to ice1 proxies.
 /// </param>
 /// <param name="invocationTimeout">The invocation timeout of the clone (optional).</param>
 /// <param name="label">The label of the clone (optional).</param>
 /// <param name="location">The location of the clone (optional).</param>
 /// <param name="locator">The locator proxy of the clone (optional).</param>
 /// <param name="locatorCacheTimeout">The locator cache timeout of the clone (optional).</param>
 /// <param name="oneway">Determines whether the clone is oneway or twoway (optional).</param>
 /// <param name="preferExistingConnection">Determines whether or not the clone prefer using an existing
 /// connection.</param>
 /// <param name="preferNonSecure">Determines whether the clone prefers non-secure connections over secure
 /// connections (optional).</param>
 /// <param name="relative">When true, the new proxy is a relative proxy (optional).</param>
 /// <param name="router">The router proxy of the clone (optional).</param>
 /// <returns>A new proxy manufactured by the proxy factory (see factory parameter).</returns>
 public static T Clone <T>(
     this IObjectPrx prx,
     ProxyFactory <T> factory,
     bool?cacheConnection = null,
     bool clearLabel      = false,
     bool clearLocator    = false,
     bool clearRouter     = false,
     IReadOnlyDictionary <string, string>?context = null,
     Encoding?encoding = null,
     IEnumerable <Endpoint>?endpoints = null,
     string?facet = null,
     Connection?fixedConnection = null,
     Identity?identity          = null,
     string?identityAndFacet    = null,
     IEnumerable <InvocationInterceptor>?invocationInterceptors = null,
     InvocationMode?invocationMode = null,
     TimeSpan?invocationTimeout    = null,
     object?label = null,
     IEnumerable <string>?location = null,
     ILocatorPrx?locator           = null,
     TimeSpan?locatorCacheTimeout  = null,
     bool?oneway = null,
     bool?preferExistingConnection = null,
     NonSecure?preferNonSecure     = null,
     bool?relative     = null,
     IRouterPrx?router = null) where T : class, IObjectPrx =>
 factory(prx.IceReference.Clone(cacheConnection,
                                clearLabel,
                                clearLocator,
                                clearRouter,
                                context,
                                encoding,
                                endpoints,
                                facet,
                                fixedConnection,
                                identity,
                                identityAndFacet,
                                invocationInterceptors,
                                invocationMode,
                                invocationTimeout,
                                label,
                                location,
                                locator,
                                locatorCacheTimeout,
                                oneway,
                                preferExistingConnection,
                                preferNonSecure,
                                relative,
                                router));
예제 #8
0
파일: Proxy.cs 프로젝트: jk990803/ice
 /// <summary>Creates a clone of this proxy, with a new facet and optionally other options. The clone is
 /// identical to this proxy except for its facet and other options set through parameters.</summary>
 /// <param name="prx">The source proxy.</param>
 /// <param name="facet">The facet of the clone.</param>
 /// <param name="factory">The proxy factory used to manufacture the clone.</param>
 /// <param name="adapterId">The adapter ID of the clone (optional).</param>
 /// <param name="cacheConnection">Determines whether or not the clone caches its connection (optional).</param>
 /// <param name="clearLocator">When set to true, the clone does not have an associated locator proxy (optional).
 /// </param>
 /// <param name="clearRouter">When set to true, the clone does not have an associated router proxy (optional).
 /// </param>
 /// <param name="compress">Determines whether or not the clone compresses requests (optional).</param>
 /// <param name="connectionId">The connection ID of the clone (optional).</param>
 /// <param name="connectionTimeout">The connection timeout of the clone (optional).</param>
 /// <param name="context">The context of the clone (optional).</param>
 /// <param name="encoding">The encoding of the clone (optional).</param>
 /// <param name="endpointSelection">The encoding selection policy of the clone (optional).</param>
 /// <param name="endpoints">The endpoints of the clone (optional).</param>
 /// <param name="fixedConnection">The connection of the clone (optional). When specified, the clone is a fixed
 /// proxy. You can clone a non-fixed proxy into a fixed proxy but not vice-versa.</param>
 /// <param name="invocationMode">The invocation mode of the clone (optional).</param>
 /// <param name="invocationTimeout">The invocation timeout of the clone (optional).</param>
 /// <param name="locator">The locator proxy of the clone (optional).</param>
 /// <param name="locatorCacheTimeout">The locator cache timeout of the clone (optional).</param>
 /// <param name="oneway">Determines whether the clone is oneway or twoway (optional). This is a simplified
 /// version of the invocationMode parameter.</param>
 /// <param name="preferNonSecure">Determines whether the clone prefers non-secure connections over secure
 /// connections (optional).</param>
 /// <param name="protocol">The Ice protocol of the clone (optional).</param>
 /// <param name="router">The router proxy of the clone (optional).</param>
 /// <returns>A new proxy manufactured by the proxy factory (see factory parameter).</returns>
 public static T Clone <T>(this IObjectPrx prx,
                           string facet,
                           ProxyFactory <T> factory,
                           string?adapterId      = null,
                           bool?cacheConnection  = null,
                           bool clearLocator     = false,
                           bool clearRouter      = false,
                           bool?compress         = null,
                           string?connectionId   = null,
                           int?connectionTimeout = null,
                           IReadOnlyDictionary <string, string>?context = null,
                           Encoding?encoding = null,
                           EndpointSelectionType?endpointSelection = null,
                           IEnumerable <Endpoint>?endpoints        = null,
                           Connection?fixedConnection    = null,
                           InvocationMode?invocationMode = null,
                           int?invocationTimeout         = null,
                           ILocatorPrx?locator           = null,
                           TimeSpan?locatorCacheTimeout  = null,
                           bool?oneway          = null,
                           bool?preferNonSecure = null,
                           Protocol?protocol    = null,
                           IRouterPrx?router    = null) where T : class, IObjectPrx
 {
     return(factory(prx.IceReference.Clone(adapterId,
                                           cacheConnection,
                                           clearLocator,
                                           clearRouter,
                                           compress,
                                           connectionId,
                                           connectionTimeout,
                                           context,
                                           encoding,
                                           endpointSelection,
                                           endpoints,
                                           facet,
                                           fixedConnection,
                                           identity: null,
                                           invocationMode,
                                           invocationTimeout,
                                           locator,
                                           locatorCacheTimeout,
                                           oneway,
                                           preferNonSecure,
                                           protocol,
                                           router)));
 }
예제 #9
0
파일: Proxy.cs 프로젝트: keno1213/ice
        /// <summary>Creates a clone of this proxy. The clone is identical to this proxy except for options set
        /// through parameters. This method returns this proxy instead of a new proxy in the event none of the options
        /// specified through the parameters change this proxy's options.</summary>
        /// <param name="prx">The source proxy.</param>
        /// <param name="adapterId">The adapter ID of the clone (optional).</param>
        /// <param name="cacheConnection">Determines whether or not the clone caches its connection (optional).</param>
        /// <param name="clearLocator">When set to true, the clone does not have an associated locator proxy (optional).
        /// </param>
        /// <param name="clearRouter">When set to true, the clone does not have an associated router proxy (optional).
        /// </param>
        /// <param name="connectionId">The connection ID of the clone (optional).</param>
        /// <param name="context">The context of the clone (optional).</param>
        /// <param name="encoding">The encoding of the clone (optional).</param>
        /// <param name="endpointSelection">The encoding selection policy of the clone (optional).</param>
        /// <param name="endpoints">The endpoints of the clone (optional).</param>
        /// <param name="fixedConnection">The connection of the clone (optional). When specified, the clone is a fixed
        /// proxy. You can clone a non-fixed proxy into a fixed proxy but not vice-versa.</param>
        /// <param name="invocationMode">The invocation mode of the clone (optional).</param>
        /// <param name="locator">The locator proxy of the clone (optional).</param>
        /// <param name="locatorCacheTimeout">The locator cache timeout of the clone (optional).</param>
        /// <param name="oneway">Determines whether the clone is oneway or twoway (optional). This is a simplified
        /// version of the invocationMode parameter.</param>
        /// <param name="preferNonSecure">Determines whether the clone prefers non-secure connections over secure
        /// connections (optional).</param>
        /// <param name="router">The router proxy of the clone (optional).</param>
        /// <returns>A new proxy with the same type as this proxy.</returns>
        public static T Clone <T>(
            this T prx,
            string?adapterId     = null,
            bool?cacheConnection = null,
            bool clearLocator    = false,
            bool clearRouter     = false,
            string?connectionId  = null,
            IReadOnlyDictionary <string, string>?context = null,
            Encoding?encoding = null,
            EndpointSelectionType?endpointSelection = null,
            IEnumerable <Endpoint>?endpoints        = null,
            Connection?fixedConnection    = null,
            InvocationMode?invocationMode = null,
            ILocatorPrx?locator           = null,
            TimeSpan?locatorCacheTimeout  = null,
            bool?oneway          = null,
            bool?preferNonSecure = null,
            IRouterPrx?router    = null) where T : IObjectPrx
        {
            Reference clone = prx.IceReference.Clone(adapterId,
                                                     cacheConnection,
                                                     clearLocator,
                                                     clearRouter,
                                                     connectionId,
                                                     context,
                                                     encoding,
                                                     endpointSelection,
                                                     endpoints,
                                                     facet: null,
                                                     fixedConnection,
                                                     identity: null,
                                                     identityAndFacet: null,
                                                     invocationMode,
                                                     locator,
                                                     locatorCacheTimeout,
                                                     oneway,
                                                     preferNonSecure,
                                                     router);

            // Reference.Clone never returns a new reference == to itself.
            return(ReferenceEquals(clone, prx.IceReference) ? prx : (T)prx.Clone(clone));
        }
예제 #10
0
        private void DestroyInternal()
        {
            IRouterPrx   router;
            Communicator?communicator;

            lock (_mutex)
            {
                Debug.Assert(_destroy);
                if (_router == null)
                {
                    return;
                }
                router  = _router;
                _router = null;

                communicator = _communicator;

                Debug.Assert(communicator != null);
            }

            try
            {
                router.DestroySession();
            }
            catch (ConnectionLostException)
            {
                // Expected if another thread invoked on an object from the session concurrently.
            }
            catch (SessionNotExistException)
            {
                // This can also occur.
            }
            catch (Exception e)
            {
                communicator.Logger.Warning("SessionHelper: unexpected exception when destroying the session:\n" + e);
            }

            communicator.Dispose();

            // Notify the callback that the session is gone.
            _callback.Disconnected(this);
        }
예제 #11
0
        private ObjectAdapter CreateObjectAdapter(
            string name,
            bool serializeDispatch,
            TaskScheduler?taskScheduler,
            IRouterPrx?router)
        {
            if (name.Length == 0)
            {
                throw new ArgumentException("the empty string is not a valid object adapter name", nameof(name));
            }

            lock (_mutex)
            {
                if (IsDisposed)
                {
                    throw new CommunicatorDisposedException();
                }
                if (_shutdownTask != null)
                {
                    throw new InvalidOperationException("ShutdownAsync has been called on this communicator");
                }

                if (!_adapterNamesInUse.Add(name))
                {
                    throw new ArgumentException($"an object adapter with name `{name}' was already created",
                                                nameof(name));
                }

                try
                {
                    var adapter = new ObjectAdapter(this, name, serializeDispatch, taskScheduler, router);
                    _adapters.Add(adapter);
                    return(adapter);
                }
                catch
                {
                    _adapterNamesInUse.Remove(name);
                    throw;
                }
            }
        }
예제 #12
0
파일: RouterInfo.cs 프로젝트: bailudata/ice
        //
        // Returns router info for a given router. Automatically creates
        // the router info if it doesn't exist yet.
        //
        public RouterInfo?erase(IRouterPrx?rtr)
        {
            RouterInfo?info = null;

            if (rtr != null)
            {
                //
                // The router cannot be routed.
                //
                IRouterPrx router = rtr.Clone(clearRouter: true);

                lock (this)
                {
                    if (_table.TryGetValue(router, out info))
                    {
                        _table.Remove(router);
                    }
                }
            }
            return(info);
        }
예제 #13
0
        private void Connected(IRouterPrx router, ISessionPrx session)
        {
            // Remote invocation should be done without acquiring a mutex lock.
            Debug.Assert(router != null);
            Debug.Assert(_communicator != null);

            // 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();
            }

            string category = router.GetCategoryForClient();

            lock (_mutex)
            {
                _router = router;

                if (_destroy)
                {
                    // Run destroyInternal in a thread because it makes remote invocations.
                    var 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;
            }

            // When using Ice1, we need to figure out the router's acm/session timeout and configure the connection
            // accordingly. With Ice2, this is no longer necessary, the idle timeout is negotiated on connection
            // establishment.
            Connection connection = router.GetConnection();

            if (router.Protocol == Protocol.Ice1)
            {
                TimeSpan idleTimeout = TimeSpan.Zero;
                try
                {
                    idleTimeout = TimeSpan.FromSeconds(router.GetACMTimeout());
                }
                catch (OperationNotExistException)
                {
                }

                if (idleTimeout == TimeSpan.Zero)
                {
                    idleTimeout = TimeSpan.FromSeconds(router.GetSessionTimeout());
                }

                if (idleTimeout != TimeSpan.Zero)
                {
                    connection.IdleTimeout = idleTimeout;
                }
            }

            connection.Closed += (sender, args) => Destroy();

            try
            {
                _callback.Connected(this);
            }
            catch (SessionNotExistException)
            {
                Destroy();
            }
        }
예제 #14
0
        private void Connected(IRouterPrx router, ISessionPrx session)
        {
            // Remote invocation should be done without acquiring a mutex lock.
            Debug.Assert(router != null);
            Debug.Assert(_communicator != null);
            Connection?conn       = router.GetCachedConnection();
            string     category   = router.GetCategoryForClient();
            TimeSpan   acmTimeout = TimeSpan.Zero;

            try
            {
                acmTimeout = TimeSpan.FromSeconds(router.GetACMTimeout());
            }
            catch (OperationNotExistException)
            {
            }

            if (acmTimeout == TimeSpan.Zero)
            {
                acmTimeout = TimeSpan.FromSeconds(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.
                    var 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 != TimeSpan.Zero)
                {
                    Connection?connection = _router.GetCachedConnection();
                    Debug.Assert(connection != null);
                    connection.Acm     = new Acm(acmTimeout, connection.Acm.Close, AcmHeartbeat.Always);
                    connection.Closed += (sender, args) => Destroy();
                }
            }

            try
            {
                _callback.Connected(this);
            }
            catch (SessionNotExistException)
            {
                Destroy();
            }
        }
예제 #15
0
        internal ObjectAdapter CreateObjectAdapter(string name, IRouterPrx?router)
        {
            lock (this)
            {
                if (_isShutdown)
                {
                    throw new CommunicatorDestroyedException();
                }

                if (name.Length > 0)
                {
                    if (_adapterNamesInUse.Contains(name))
                    {
                        throw new System.ArgumentException($"An object adapter with name `{name}' is already registered",
                                                           nameof(name));
                    }
                    _adapterNamesInUse.Add(name);
                }
            }

            //
            // Must be called outside the synchronization since initialize can make client invocations
            // on the router if it's set.
            //
            ObjectAdapter?adapter = null;

            try
            {
                if (name.Length == 0)
                {
                    string uuid = System.Guid.NewGuid().ToString();
                    adapter = new ObjectAdapter(this, uuid, null, true);
                }
                else
                {
                    adapter = new ObjectAdapter(this, name, router, false);
                }

                lock (this)
                {
                    if (_isShutdown)
                    {
                        throw new CommunicatorDestroyedException();
                    }
                    _adapters.Add(adapter);
                }
            }
            catch (CommunicatorDestroyedException)
            {
                if (adapter != null)
                {
                    adapter.Destroy();
                }
                throw;
            }
            catch (System.Exception)
            {
                if (name.Length > 0)
                {
                    lock (this)
                    {
                        _adapterNamesInUse.Remove(name);
                    }
                }
                throw;
            }

            return(adapter);
        }
예제 #16
0
        private async ValueTask <ObjectAdapter> CreateObjectAdapterAsync(
            string name,
            bool serializeDispatch,
            TaskScheduler?taskScheduler,
            IRouterPrx?router,
            CancellationToken cancel)
        {
            if (name.Length == 0)
            {
                throw new ArgumentException("the empty string is not a valid object adapter name", nameof(name));
            }

            lock (_mutex)
            {
                if (IsDisposed)
                {
                    throw new CommunicatorDisposedException();
                }

                if (!_adapterNamesInUse.Add(name))
                {
                    throw new ArgumentException($"an object adapter with name `{name}' was already created",
                                                nameof(name));
                }
            }

            ObjectAdapter adapter;

            try
            {
                adapter = await ObjectAdapter.CreateAsync(this, name, serializeDispatch, taskScheduler, router, cancel).
                          ConfigureAwait(false);
            }
            catch
            {
                lock (_mutex)
                {
                    _adapterNamesInUse.Remove(name);
                }
                throw;
            }

            bool disposed;

            lock (_mutex)
            {
                disposed = IsDisposed;
                if (!disposed)
                {
                    _adapters.Add(adapter);
                }
            }

            if (disposed)
            {
                await adapter.DisposeAsync().ConfigureAwait(false);

                throw new CommunicatorDisposedException();
            }
            else
            {
                return(adapter);
            }
        }