< Summary

Information
Class: Ice.Internal.ObjectAdapterFactory
Assembly: Ice
File(s): /home/runner/work/ice/ice/csharp/src/Ice/Internal/ObjectAdapterFactory.cs
Tag: 71_18251537082
Line coverage
94%
Covered lines: 112
Uncovered lines: 7
Coverable lines: 119
Total lines: 284
Line coverage: 94.1%
Branch coverage
89%
Covered branches: 34
Total branches: 38
Branch coverage: 89.4%
Method coverage
100%
Covered methods: 11
Total methods: 11
Method coverage: 100%

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
shutdown()100%44100%
waitForShutdown()100%44100%
isShutdown()100%11100%
destroy()100%22100%
updateConnectionObservers()100%22100%
updateThreadObservers()100%22100%
createObjectAdapter(...)71.43%14.331488.1%
findObjectAdapter(...)100%6.13684.62%
removeObjectAdapter(...)100%22100%
flushAsyncBatchRequests(...)100%22100%
.ctor(...)100%11100%

File(s)

/home/runner/work/ice/ice/csharp/src/Ice/Internal/ObjectAdapterFactory.cs

#LineLine coverage
 1// Copyright (c) ZeroC, Inc.
 2
 3using System.Net.Security;
 4
 5namespace Ice.Internal;
 6
 7public sealed class ObjectAdapterFactory
 8{
 9    public void shutdown()
 10    {
 11        List<Ice.ObjectAdapter> adapters;
 112        lock (_mutex)
 13        {
 14            //
 15            // Ignore shutdown requests if the object adapter factory has
 16            // already been shut down.
 17            //
 118            if (_instance == null)
 19            {
 120                return;
 21            }
 22
 123            adapters = new List<Ice.ObjectAdapter>(_adapters);
 24
 125            _instance = null;
 126            _communicator = null;
 27
 128            System.Threading.Monitor.PulseAll(_mutex);
 129        }
 30
 31        //
 32        // Deactivate outside the thread synchronization, to avoid
 33        // deadlocks.
 34        //
 135        foreach (Ice.ObjectAdapter adapter in adapters)
 36        {
 137            adapter.deactivate();
 38        }
 139    }
 40
 41    public void waitForShutdown()
 42    {
 43        List<Ice.ObjectAdapter> adapters;
 144        lock (_mutex)
 45        {
 46            //
 47            // First we wait for the shutdown of the factory itself.
 48            //
 149            while (_instance != null)
 50            {
 151                System.Threading.Monitor.Wait(_mutex);
 52            }
 53
 154            adapters = new List<Ice.ObjectAdapter>(_adapters);
 155        }
 56
 57        //
 58        // Now we wait for deactivation of each object adapter.
 59        //
 160        foreach (Ice.ObjectAdapter adapter in adapters)
 61        {
 162            adapter.waitForDeactivate();
 63        }
 164    }
 65
 66    public bool isShutdown()
 67    {
 168        lock (_mutex)
 69        {
 170            return _instance == null;
 71        }
 172    }
 73
 74    public void destroy()
 75    {
 76        //
 77        // First wait for shutdown to finish.
 78        //
 179        waitForShutdown();
 80
 81        List<Ice.ObjectAdapter> adapters;
 182        lock (_mutex)
 83        {
 184            adapters = new List<Ice.ObjectAdapter>(_adapters);
 185        }
 86
 187        foreach (Ice.ObjectAdapter adapter in adapters)
 88        {
 189            adapter.destroy();
 90        }
 91
 192        lock (_mutex)
 93        {
 194            _adapters.Clear();
 195        }
 196    }
 97
 98    public void
 99    updateConnectionObservers()
 100    {
 101        List<Ice.ObjectAdapter> adapters;
 1102        lock (_mutex)
 103        {
 1104            adapters = new List<Ice.ObjectAdapter>(_adapters);
 1105        }
 106
 1107        foreach (Ice.ObjectAdapter adapter in adapters)
 108        {
 1109            adapter.updateConnectionObservers();
 110        }
 1111    }
 112
 113    public void
 114    updateThreadObservers()
 115    {
 116        List<Ice.ObjectAdapter> adapters;
 1117        lock (_mutex)
 118        {
 1119            adapters = new List<Ice.ObjectAdapter>(_adapters);
 1120        }
 121
 1122        foreach (Ice.ObjectAdapter adapter in adapters)
 123        {
 1124            adapter.updateThreadObservers();
 125        }
 1126    }
 127
 128    public Ice.ObjectAdapter createObjectAdapter(
 129        string name,
 130        Ice.RouterPrx router,
 131        SslServerAuthenticationOptions serverAuthenticationOptions)
 132    {
 1133        lock (_mutex)
 134        {
 1135            if (_instance == null)
 136            {
 0137                throw new Ice.CommunicatorDestroyedException();
 138            }
 139
 1140            if (name.Length > 0)
 141            {
 1142                if (_adapterNamesInUse.Contains(name))
 143                {
 1144                    throw new AlreadyRegisteredException("object adapter", name);
 145                }
 1146                _adapterNamesInUse.Add(name);
 147            }
 1148        }
 149
 150        //
 151        // Must be called outside the synchronization since initialize can make client invocations
 152        // on the router if it's set.
 153        //
 1154        Ice.ObjectAdapter adapter = null;
 155        try
 156        {
 1157            if (name.Length == 0)
 158            {
 1159                adapter = new Ice.ObjectAdapter(
 1160                    _instance,
 1161                    _communicator,
 1162                    this,
 1163                    System.Guid.NewGuid().ToString(),
 1164                    null,
 1165                    true,
 1166                    serverAuthenticationOptions);
 167            }
 168            else
 169            {
 1170                adapter = new Ice.ObjectAdapter(
 1171                    _instance,
 1172                    _communicator,
 1173                    this,
 1174                    name,
 1175                    router,
 1176                    false,
 1177                    serverAuthenticationOptions);
 178            }
 179
 1180            lock (_mutex)
 181            {
 1182                if (_instance == null)
 183                {
 0184                    throw new Ice.CommunicatorDestroyedException();
 185                }
 1186                _adapters.Add(adapter);
 1187            }
 1188        }
 0189        catch (Ice.CommunicatorDestroyedException)
 190        {
 0191            adapter?.destroy();
 0192            throw;
 193        }
 1194        catch (Ice.LocalException)
 195        {
 1196            if (name.Length > 0)
 197            {
 1198                lock (_mutex)
 199                {
 1200                    _adapterNamesInUse.Remove(name);
 1201                }
 202            }
 1203            throw;
 204        }
 205
 1206        return adapter;
 207    }
 208
 209    public Ice.ObjectAdapter findObjectAdapter(Reference reference)
 210    {
 211        List<Ice.ObjectAdapter> adapters;
 1212        lock (_mutex)
 213        {
 1214            if (_instance == null)
 215            {
 1216                return null;
 217            }
 218
 1219            adapters = new List<Ice.ObjectAdapter>(_adapters);
 1220        }
 221
 1222        foreach (Ice.ObjectAdapter adapter in adapters)
 223        {
 224            try
 225            {
 1226                if (adapter.isLocal(reference))
 227                {
 1228                    return adapter;
 229                }
 1230            }
 0231            catch (Ice.ObjectAdapterDestroyedException)
 232            {
 233                // Ignore.
 0234            }
 235        }
 236
 1237        return null;
 1238    }
 239
 240    public void removeObjectAdapter(Ice.ObjectAdapter adapter)
 241    {
 1242        lock (_mutex)
 243        {
 1244            if (_instance == null)
 245            {
 1246                return;
 247            }
 248
 1249            _adapters.Remove(adapter);
 1250            _adapterNamesInUse.Remove(adapter.getName());
 1251        }
 1252    }
 253
 254    public void flushAsyncBatchRequests(Ice.CompressBatch compressBatch, CommunicatorFlushBatchAsync outAsync)
 255    {
 256        List<Ice.ObjectAdapter> adapters;
 1257        lock (_mutex)
 258        {
 1259            adapters = new List<Ice.ObjectAdapter>(_adapters);
 1260        }
 261
 1262        foreach (Ice.ObjectAdapter adapter in adapters)
 263        {
 1264            adapter.flushAsyncBatchRequests(compressBatch, outAsync);
 265        }
 1266    }
 267
 268    //
 269    // Only for use by Instance.
 270    //
 1271    internal ObjectAdapterFactory(Instance instance, Ice.Communicator communicator)
 272    {
 1273        _instance = instance;
 1274        _communicator = communicator;
 1275        _adapterNamesInUse = new HashSet<string>();
 1276        _adapters = new List<Ice.ObjectAdapter>();
 1277    }
 278
 279    private Instance _instance;
 280    private Ice.Communicator _communicator;
 281    private readonly HashSet<string> _adapterNamesInUse;
 282    private readonly List<Ice.ObjectAdapter> _adapters;
 1283    private readonly object _mutex = new();
 284}