diff options
author | Benoit Foucher <benoit@zeroc.com> | 2017-03-10 15:50:20 +0100 |
---|---|---|
committer | Benoit Foucher <benoit@zeroc.com> | 2017-03-10 15:50:20 +0100 |
commit | e3965dcfae46026f3e6ef2e1ee68aeb818413a43 (patch) | |
tree | 7a20165b26d74fd698df216408fe9bc3234b6ae6 /csharp/src | |
parent | Aligned C# throwUOE with Java (diff) | |
download | ice-e3965dcfae46026f3e6ef2e1ee68aeb818413a43.tar.bz2 ice-e3965dcfae46026f3e6ef2e1ee68aeb818413a43.tar.xz ice-e3965dcfae46026f3e6ef2e1ee68aeb818413a43.zip |
Fixed ICE-7662 - Use System.Action & System.Func classes
Diffstat (limited to 'csharp/src')
-rw-r--r-- | csharp/src/Ice/InputStream.cs | 29 | ||||
-rw-r--r-- | csharp/src/Ice/Instance.cs | 18 | ||||
-rw-r--r-- | csharp/src/Ice/PropertiesAdminI.cs | 49 | ||||
-rw-r--r-- | csharp/src/Ice/ThreadHookPlugin.cs | 31 | ||||
-rw-r--r-- | csharp/src/Ice/ThreadPool.cs | 10 | ||||
-rw-r--r-- | csharp/src/Ice/Util.cs | 34 |
6 files changed, 116 insertions, 55 deletions
diff --git a/csharp/src/Ice/InputStream.cs b/csharp/src/Ice/InputStream.cs index fc9b67c76aa..c942e132a82 100644 --- a/csharp/src/Ice/InputStream.cs +++ b/csharp/src/Ice/InputStream.cs @@ -18,13 +18,6 @@ namespace Ice using Protocol = IceInternal.Protocol; /// <summary> - /// A ClassResolver translates a Slice type Id into a type using - /// an implementation-defined algorithm. - /// </summary> - /// <param name="id">A Slice type Id corresponding to a Slice value or user exception.</param> - public delegate System.Type ClassResolver(string id); - - /// <summary> /// Throws a UserException corresponding to the given Slice type Id, such as "::Module::MyException". /// If the implementation does not throw an exception, the Ice run time will fall back /// to using its default behavior for instantiating the user exception. @@ -327,7 +320,7 @@ namespace Ice /// resolver will be used by default. /// </summary> /// <param name="r">The compact ID resolver.</param> - public void setCompactIdResolver(CompactIdResolver r) + public void setCompactIdResolver(System.Func<int, string> r) { _compactIdResolver = r; } @@ -338,7 +331,7 @@ namespace Ice /// resolver will be used by default. /// </summary> /// <param name="r">The class resolver.</param> - public void setClassResolver(ClassResolver r) + public void setClassResolver(System.Func<string, Type> r) { _classResolver = r; } @@ -444,11 +437,11 @@ namespace Ice other._logger = _logger; _logger = tmpLogger; - CompactIdResolver tmpCompactIdResolver = other._compactIdResolver; + System.Func<int, string> tmpCompactIdResolver = other._compactIdResolver; other._compactIdResolver = _compactIdResolver; _compactIdResolver = tmpCompactIdResolver; - ClassResolver tmpClassResolver = other._classResolver; + System.Func<string, Type> tmpClassResolver = other._classResolver; other._classResolver = _classResolver; _classResolver = tmpClassResolver; } @@ -2741,7 +2734,7 @@ namespace Ice abstract private class EncapsDecoder { internal EncapsDecoder(InputStream stream, Encaps encaps, bool sliceValues, ValueFactoryManager f, - ClassResolver cr) + System.Func<string, Type> cr) { _stream = stream; _encaps = encaps; @@ -3009,7 +3002,7 @@ namespace Ice protected readonly Encaps _encaps; protected readonly bool _sliceValues; protected ValueFactoryManager _valueFactoryManager; - protected ClassResolver _classResolver; + protected System.Func<string, Type> _classResolver; // // Encapsulation attributes for object unmarshaling. @@ -3025,7 +3018,7 @@ namespace Ice private sealed class EncapsDecoder10 : EncapsDecoder { internal EncapsDecoder10(InputStream stream, Encaps encaps, bool sliceValues, ValueFactoryManager f, - ClassResolver cr) + System.Func<string, Type> cr) : base(stream, encaps, sliceValues, f, cr) { _sliceType = SliceType.NoSlice; @@ -3321,7 +3314,7 @@ namespace Ice private sealed class EncapsDecoder11 : EncapsDecoder { internal EncapsDecoder11(InputStream stream, Encaps encaps, bool sliceValues, ValueFactoryManager f, - ClassResolver cr, CompactIdResolver r) + System.Func<string, Type> cr, System.Func<int, string> r) : base(stream, encaps, sliceValues, f, cr) { _compactIdResolver = r; @@ -3951,7 +3944,7 @@ namespace Ice internal InstanceData next; } - private CompactIdResolver _compactIdResolver; + private System.Func<int, string> _compactIdResolver; private InstanceData _current; private int _valueIdIndex; // The ID of the next instance to unmarshal. private Dictionary<int, Type> _compactIdCache; @@ -4034,8 +4027,8 @@ namespace Ice private ValueFactoryManager _valueFactoryManager; private Logger _logger; - private CompactIdResolver _compactIdResolver; - private ClassResolver _classResolver; + private System.Func<int, string> _compactIdResolver; + private System.Func<string, Type> _classResolver; } /// <summary> diff --git a/csharp/src/Ice/Instance.cs b/csharp/src/Ice/Instance.cs index 116c07652d3..a4a1c3e7c1d 100644 --- a/csharp/src/Ice/Instance.cs +++ b/csharp/src/Ice/Instance.cs @@ -655,12 +655,13 @@ namespace IceInternal } public void - setThreadHook(Ice.ThreadNotification threadHook) + setThreadHook(System.Action threadStart, System.Action threadStop) { // // No locking, as it can only be called during plug-in loading // - _initData.threadHook = threadHook; + _initData.threadStart = threadStart; + _initData.threadStop = threadStop; } public Type resolveClass(string id) @@ -933,7 +934,18 @@ namespace IceInternal if(_initData.properties.getPropertyAsIntWithDefault("Ice.PreloadAssemblies", 0) > 0) { AssemblyUtil.preloadAssemblies(); - } + } + +#pragma warning disable 618 + if(_initData.threadStart == null && _initData.threadHook != null) + { + _initData.threadStart = _initData.threadHook.start; + } + if(_initData.threadStop == null && _initData.threadHook != null) + { + _initData.threadStop = _initData.threadHook.stop; + } +#pragma warning restore 618 } catch(Ice.LocalException) { diff --git a/csharp/src/Ice/PropertiesAdminI.cs b/csharp/src/Ice/PropertiesAdminI.cs index 5fa6a69064a..b03ba7b4ce5 100644 --- a/csharp/src/Ice/PropertiesAdminI.cs +++ b/csharp/src/Ice/PropertiesAdminI.cs @@ -20,8 +20,15 @@ public interface PropertiesAdminUpdateCallback public interface NativePropertiesAdmin { + [Obsolete("This method is deprecated. Use addUpdatecallback(System.Action<Dictionary<string, string>> changes) instead.")] void addUpdateCallback(PropertiesAdminUpdateCallback callback); + + [Obsolete("This method is deprecated. Use removeUpdatecallback(System.Action<Dictionary<string, string>> changes) instead.")] void removeUpdateCallback(PropertiesAdminUpdateCallback callback); + + void addUpdateCallback(System.Action<Dictionary<string, string>> callback); + + void removeUpdateCallback(System.Action<Dictionary<string, string>> callback); } } @@ -177,7 +184,7 @@ namespace IceInternal _properties.setProperty(e.Key, ""); } - if(_updateCallbacks.Count > 0) + if(_deprecatedUpdateCallbacks.Count > 0 || _updateCallbacks.Count > 0) { Dictionary<string, string> changes = new Dictionary<string, string>(added); foreach(KeyValuePair<string, string> e in changed) @@ -190,7 +197,7 @@ namespace IceInternal } // Copy callbacks to allow callbacks to update callbacks - foreach(var callback in new List<Ice.PropertiesAdminUpdateCallback>(_updateCallbacks)) + foreach(var callback in new List<Ice.PropertiesAdminUpdateCallback>(_deprecatedUpdateCallbacks)) { try { @@ -204,6 +211,21 @@ namespace IceInternal } } } + // Copy callbacks to allow callbacks to update callbacks + foreach(var callback in new List<System.Action<Dictionary<string, string>>>(_updateCallbacks)) + { + try + { + callback(changes); + } + catch(Exception ex) + { + if(_properties.getPropertyAsIntWithDefault("Ice.Warn.Dispatch", 1) > 1) + { + _logger.warning("properties admin update callback raised unexpected exception:\n" + ex); + } + } + } } } } @@ -212,7 +234,7 @@ namespace IceInternal { lock(this) { - _updateCallbacks.Add(cb); + _deprecatedUpdateCallbacks.Add(cb); } } @@ -220,13 +242,32 @@ namespace IceInternal { lock(this) { + _deprecatedUpdateCallbacks.Remove(cb); + } + } + + public void addUpdateCallback(System.Action<Dictionary<string, string>> cb) + { + lock(this) + { + _updateCallbacks.Add(cb); + } + } + + public void removeUpdateCallback(System.Action<Dictionary<string, string>> cb) + { + lock(this) + { _updateCallbacks.Remove(cb); } } private readonly Ice.Properties _properties; private readonly Ice.Logger _logger; - private List<Ice.PropertiesAdminUpdateCallback> _updateCallbacks = new List<Ice.PropertiesAdminUpdateCallback>(); + private List<Ice.PropertiesAdminUpdateCallback> _deprecatedUpdateCallbacks = + new List<Ice.PropertiesAdminUpdateCallback>(); + private List<System.Action<Dictionary<string, string>>> _updateCallbacks = + new List<System.Action<Dictionary<string, string>>>(); private static readonly string _traceCategory = "Admin.Properties"; } diff --git a/csharp/src/Ice/ThreadHookPlugin.cs b/csharp/src/Ice/ThreadHookPlugin.cs index d1d5a02b450..4cc1714e8a9 100644 --- a/csharp/src/Ice/ThreadHookPlugin.cs +++ b/csharp/src/Ice/ThreadHookPlugin.cs @@ -7,10 +7,12 @@ // // ********************************************************************** +using System; + namespace Ice { /// <summary> - /// Class to support thread notification hooks. Applications using + /// Class to support thread notification hooks. Applications using /// thread notification hooks instantiate a ThreadHookPlugin with a /// thread notification hook and return the instance from their /// PluginFactory implementation. @@ -18,12 +20,25 @@ namespace Ice public class ThreadHookPlugin : Plugin { /// <summary> - /// Installs a custom logger for a communicator. + /// Installs a thread hook for a communicator. /// </summary> /// <param name="communicator">The communicator using the thread notification hook.</param> /// <param name="threadHook">The thread notification hook for the communicator.</param> - public - ThreadHookPlugin(Communicator communicator, ThreadNotification threadHook) + [Obsolete("This constructor is deprecated. Use the constructur with threadStart and threadStop parameters instead.")] + public + ThreadHookPlugin(Communicator communicator, ThreadNotification threadHook) : + this(communicator, threadHook.start, threadHook.stop) + { + } + + /// <summary> + /// Installs thread hooks for a communicator. + /// </summary> + /// <param name="communicator">The communicator using the thread notification hook.</param> + /// <param name="threadStart">The start thread notification hook for the communicator.</param> + /// <param name="threadStop">The stop thread notification hook for the communicator.</param> + public + ThreadHookPlugin(Communicator communicator, System.Action threadStart, System.Action threadStop) { if(communicator == null) { @@ -31,9 +46,9 @@ namespace Ice ex.reason = "Communicator cannot be null"; throw ex; } - + IceInternal.Instance instance = IceInternal.Util.getInstance(communicator); - instance.setThreadHook(threadHook); + instance.setThreadHook(threadStart, threadStop); } /// <summary> @@ -41,11 +56,11 @@ namespace Ice /// can override this method to perform any initialization that might be required /// by the thread notification hook. /// </summary> - public void + public void initialize() { } - + /// <summary> /// Called by the Ice run time when the communicator is destroyed. The derived class /// can override this method to perform any finalization that might be required diff --git a/csharp/src/Ice/ThreadPool.cs b/csharp/src/Ice/ThreadPool.cs index 94e0ebba602..226a0f9a04a 100644 --- a/csharp/src/Ice/ThreadPool.cs +++ b/csharp/src/Ice/ThreadPool.cs @@ -741,7 +741,7 @@ namespace IceInternal } private Instance _instance; - private Ice.Dispatcher _dispatcher; + private System.Action<System.Action, Ice.Connection> _dispatcher; private bool _destroyed; private readonly string _prefix; private readonly string _threadPrefix; @@ -816,11 +816,11 @@ namespace IceInternal // SynchronizationContext.SetSynchronizationContext(new ThreadPoolSynchronizationContext(_threadPool)); - if(_threadPool._instance.initializationData().threadHook != null) + if(_threadPool._instance.initializationData().threadStart != null) { try { - _threadPool._instance.initializationData().threadHook.start(); + _threadPool._instance.initializationData().threadStart(); } catch(System.Exception ex) { @@ -845,11 +845,11 @@ namespace IceInternal _observer.detach(); } - if(_threadPool._instance.initializationData().threadHook != null) + if(_threadPool._instance.initializationData().threadStop != null) { try { - _threadPool._instance.initializationData().threadHook.stop(); + _threadPool._instance.initializationData().threadStop(); } catch(System.Exception ex) { diff --git a/csharp/src/Ice/Util.cs b/csharp/src/Ice/Util.cs index 4ec7f046d8b..bbf5784fa04 100644 --- a/csharp/src/Ice/Util.cs +++ b/csharp/src/Ice/Util.cs @@ -37,21 +37,6 @@ namespace Ice } /// <summary> - /// A delegate for the dispatcher. The dispatcher is called by the Ice - /// runtime to dispatch servant calls and AMI callbacks. - /// </summary> - public delegate void Dispatcher(System.Action call, Connection con); - - /// <summary> - /// Applications that make use of compact type IDs to conserve space - /// when marshaling class instances, and also use the streaming API to - /// extract such classes, can intercept the translation between compact - /// type IDs and their corresponding string type IDs by installing an - /// instance of CompactIdResolver in InitializationData. - /// </summary> - public delegate string CompactIdResolver(int id); - - /// <summary> /// A class that encpasulates data to initialize a communicator. /// </summary> public class InitializationData : ICloneable @@ -85,17 +70,32 @@ namespace Ice /// <summary> /// The thread hook for the communicator. /// </summary> + [Obsolete("This data member is deprecated. Use threadStart or threadStop instead.")] public ThreadNotification threadHook; /// <summary> + /// The thread start hook for the communicator. The Ice run time + /// calls this hook for each new thread it creates. The call is + /// made by the newly-started thread. + /// </summary> + public System.Action threadStart; + + /// <summary> + /// The thread stop hook for the communicator. The Ice run time + /// calls stop before it destroys a thread. The call is made by + /// thread that is about to be destroyed. + /// </summary> + public System.Action threadStop; + + /// <summary> /// The dispatcher for the communicator. /// </summary> - public Dispatcher dispatcher; + public System.Action<System.Action, Connection> dispatcher; /// <summary> /// The compact type ID resolver. /// </summary> - public CompactIdResolver compactIdResolver; + public System.Func<int, string> compactIdResolver; /// <summary> /// The batch request interceptor. |