1 //
2 // Copyright (c) ZeroC, Inc. All rights reserved.
3 //
4 
5 namespace IceInternal
6 {
7     using System.Collections;
8     using System.Collections.Generic;
9     using System.Diagnostics;
10     using System.Text;
11     using System.Threading;
12     using System;
13 
14     public sealed class BufSizeWarnInfo
15     {
16         // Whether send size warning has been emitted
17         public bool sndWarn;
18 
19         // The send size for which the warning wwas emitted
20         public int sndSize;
21 
22         // Whether receive size warning has been emitted
23         public bool rcvWarn;
24 
25         // The receive size for which the warning wwas emitted
26         public int rcvSize;
27     }
28 
29     public sealed class Instance
30     {
31         private class ObserverUpdaterI : Ice.Instrumentation.ObserverUpdater
32         {
ObserverUpdaterI(Instance instance)33             public ObserverUpdaterI(Instance instance)
34             {
35                 _instance = instance;
36             }
37 
updateConnectionObservers()38             public void updateConnectionObservers()
39             {
40                 _instance.updateConnectionObservers();
41             }
42 
updateThreadObservers()43             public void updateThreadObservers()
44             {
45                 _instance.updateThreadObservers();
46             }
47 
48             private Instance _instance;
49         }
50 
destroyed()51         public bool destroyed()
52         {
53             return _state == StateDestroyed;
54         }
55 
initializationData()56         public Ice.InitializationData initializationData()
57         {
58             //
59             // No check for destruction. It must be possible to access the
60             // initialization data after destruction.
61             //
62             // No mutex lock, immutable.
63             //
64             return _initData;
65         }
66 
traceLevels()67         public TraceLevels traceLevels()
68         {
69             // No mutex lock, immutable.
70             Debug.Assert(_traceLevels != null);
71             return _traceLevels;
72         }
73 
defaultsAndOverrides()74         public DefaultsAndOverrides defaultsAndOverrides()
75         {
76             // No mutex lock, immutable.
77             Debug.Assert(_defaultsAndOverrides != null);
78             return _defaultsAndOverrides;
79         }
80 
routerManager()81         public RouterManager routerManager()
82         {
83             lock(this)
84             {
85                 if(_state == StateDestroyed)
86                 {
87                     throw new Ice.CommunicatorDestroyedException();
88                 }
89 
90                 Debug.Assert(_routerManager != null);
91                 return _routerManager;
92             }
93         }
94 
locatorManager()95         public LocatorManager locatorManager()
96         {
97             lock(this)
98             {
99                 if(_state == StateDestroyed)
100                 {
101                     throw new Ice.CommunicatorDestroyedException();
102                 }
103 
104                 Debug.Assert(_locatorManager != null);
105                 return _locatorManager;
106             }
107         }
108 
referenceFactory()109         public ReferenceFactory referenceFactory()
110         {
111             lock(this)
112             {
113                 if(_state == StateDestroyed)
114                 {
115                     throw new Ice.CommunicatorDestroyedException();
116                 }
117 
118                 Debug.Assert(_referenceFactory != null);
119                 return _referenceFactory;
120             }
121         }
122 
requestHandlerFactory()123         public RequestHandlerFactory requestHandlerFactory()
124         {
125             lock(this)
126             {
127                 if(_state == StateDestroyed)
128                 {
129                     throw new Ice.CommunicatorDestroyedException();
130                 }
131 
132                 Debug.Assert(_requestHandlerFactory != null);
133                 return _requestHandlerFactory;
134             }
135         }
136 
proxyFactory()137         public ProxyFactory proxyFactory()
138         {
139             lock(this)
140             {
141                 if(_state == StateDestroyed)
142                 {
143                     throw new Ice.CommunicatorDestroyedException();
144                 }
145 
146                 Debug.Assert(_proxyFactory != null);
147                 return _proxyFactory;
148             }
149         }
150 
outgoingConnectionFactory()151         public OutgoingConnectionFactory outgoingConnectionFactory()
152         {
153             lock(this)
154             {
155                 if(_state == StateDestroyed)
156                 {
157                     throw new Ice.CommunicatorDestroyedException();
158                 }
159 
160                 Debug.Assert(_outgoingConnectionFactory != null);
161                 return _outgoingConnectionFactory;
162             }
163         }
164 
objectAdapterFactory()165         public ObjectAdapterFactory objectAdapterFactory()
166         {
167             lock(this)
168             {
169                 if(_state == StateDestroyed)
170                 {
171                     throw new Ice.CommunicatorDestroyedException();
172                 }
173 
174                 Debug.Assert(_objectAdapterFactory != null);
175                 return _objectAdapterFactory;
176             }
177         }
178 
protocolSupport()179         public int protocolSupport()
180         {
181             return _protocolSupport;
182         }
183 
preferIPv6()184         public bool preferIPv6()
185         {
186             return _preferIPv6;
187         }
188 
networkProxy()189         public NetworkProxy networkProxy()
190         {
191             return _networkProxy;
192         }
193 
clientThreadPool()194         public ThreadPool clientThreadPool()
195         {
196             lock(this)
197             {
198                 if(_state == StateDestroyed)
199                 {
200                     throw new Ice.CommunicatorDestroyedException();
201                 }
202 
203                 Debug.Assert(_clientThreadPool != null);
204                 return _clientThreadPool;
205             }
206         }
207 
serverThreadPool()208         public ThreadPool serverThreadPool()
209         {
210             lock(this)
211             {
212                 if(_state == StateDestroyed)
213                 {
214                     throw new Ice.CommunicatorDestroyedException();
215                 }
216 
217                 if(_serverThreadPool == null) // Lazy initialization.
218                 {
219                     if(_state == StateDestroyInProgress)
220                     {
221                         throw new Ice.CommunicatorDestroyedException();
222                     }
223                     int timeout = _initData.properties.getPropertyAsInt("Ice.ServerIdleTime");
224                     _serverThreadPool = new ThreadPool(this, "Ice.ThreadPool.Server", timeout);
225                 }
226 
227                 return _serverThreadPool;
228             }
229         }
230 
231         public AsyncIOThread
asyncIOThread()232         asyncIOThread()
233         {
234             lock(this)
235             {
236                 if(_state == StateDestroyed)
237                 {
238                     throw new Ice.CommunicatorDestroyedException();
239                 }
240 
241                 if(_asyncIOThread == null) // Lazy initialization.
242                 {
243                     _asyncIOThread = new AsyncIOThread(this);
244                 }
245 
246                 return _asyncIOThread;
247             }
248         }
249 
endpointHostResolver()250         public EndpointHostResolver endpointHostResolver()
251         {
252             lock(this)
253             {
254                 if(_state == StateDestroyed)
255                 {
256                     throw new Ice.CommunicatorDestroyedException();
257                 }
258 
259                 Debug.Assert(_endpointHostResolver != null);
260                 return _endpointHostResolver;
261             }
262         }
263 
264         public RetryQueue
retryQueue()265         retryQueue()
266         {
267             lock(this)
268             {
269                 if(_state == StateDestroyed)
270                 {
271                     throw new Ice.CommunicatorDestroyedException();
272                 }
273 
274                 Debug.Assert(_retryQueue != null);
275                 return _retryQueue;
276             }
277         }
278 
279         public Timer
timer()280         timer()
281         {
282             lock(this)
283             {
284                 if(_state == StateDestroyed)
285                 {
286                     throw new Ice.CommunicatorDestroyedException();
287                 }
288 
289                 Debug.Assert(_timer != null);
290                 return _timer;
291             }
292         }
293 
endpointFactoryManager()294         public EndpointFactoryManager endpointFactoryManager()
295         {
296             lock(this)
297             {
298                 if(_state == StateDestroyed)
299                 {
300                     throw new Ice.CommunicatorDestroyedException();
301                 }
302 
303                 Debug.Assert(_endpointFactoryManager != null);
304                 return _endpointFactoryManager;
305             }
306         }
307 
pluginManager()308         public Ice.PluginManager pluginManager()
309         {
310             lock(this)
311             {
312                 if(_state == StateDestroyed)
313                 {
314                     throw new Ice.CommunicatorDestroyedException();
315                 }
316 
317                 Debug.Assert(_pluginManager != null);
318                 return _pluginManager;
319             }
320         }
321 
messageSizeMax()322         public int messageSizeMax()
323         {
324             // No mutex lock, immutable.
325             return _messageSizeMax;
326         }
327 
batchAutoFlushSize()328         public int batchAutoFlushSize()
329         {
330             // No mutex lock, immutable.
331             return _batchAutoFlushSize;
332         }
333 
classGraphDepthMax()334         public int classGraphDepthMax()
335         {
336             // No mutex lock, immutable.
337             return _classGraphDepthMax;
338         }
339 
340         public Ice.ToStringMode
toStringMode()341         toStringMode()
342         {
343             // No mutex lock, immutable
344             return _toStringMode;
345         }
346 
cacheMessageBuffers()347         public int cacheMessageBuffers()
348         {
349             // No mutex lock, immutable.
350             return _cacheMessageBuffers;
351         }
352 
clientACM()353         public ACMConfig clientACM()
354         {
355             // No mutex lock, immutable.
356             return _clientACM;
357         }
358 
serverACM()359         public ACMConfig serverACM()
360         {
361             // No mutex lock, immutable.
362             return _serverACM;
363         }
364 
getImplicitContext()365         public Ice.ImplicitContextI getImplicitContext()
366         {
367             return _implicitContext;
368         }
369 
370         public Ice.ObjectPrx
createAdmin(Ice.ObjectAdapter adminAdapter, Ice.Identity adminIdentity)371         createAdmin(Ice.ObjectAdapter adminAdapter, Ice.Identity adminIdentity)
372         {
373             bool createAdapter = (adminAdapter == null);
374 
375             lock(this)
376             {
377                 if(_state == StateDestroyed)
378                 {
379                     throw new Ice.CommunicatorDestroyedException();
380                 }
381 
382                 if(adminIdentity == null || string.IsNullOrEmpty(adminIdentity.name))
383                 {
384                     throw new Ice.IllegalIdentityException(adminIdentity);
385                 }
386 
387                 if(_adminAdapter != null)
388                 {
389                     throw new Ice.InitializationException("Admin already created");
390                 }
391 
392                 if(!_adminEnabled)
393                 {
394                     throw new Ice.InitializationException("Admin is disabled");
395                 }
396 
397                 if(createAdapter)
398                 {
399                     if(_initData.properties.getProperty("Ice.Admin.Endpoints").Length > 0)
400                     {
401                         adminAdapter = _objectAdapterFactory.createObjectAdapter("Ice.Admin", null);
402                     }
403                     else
404                     {
405                         throw new Ice.InitializationException("Ice.Admin.Endpoints is not set");
406                     }
407                 }
408 
409                 _adminIdentity = adminIdentity;
410                 _adminAdapter = adminAdapter;
411                 addAllAdminFacets();
412             }
413 
414             if(createAdapter)
415             {
416                 try
417                 {
418                     adminAdapter.activate();
419                 }
420                 catch(Ice.LocalException)
421                 {
422                     //
423                     // We cleanup _adminAdapter, however this error is not recoverable
424                     // (can't call again getAdmin() after fixing the problem)
425                     // since all the facets (servants) in the adapter are lost
426                     //
427                     adminAdapter.destroy();
428                     lock(this)
429                     {
430                         _adminAdapter = null;
431                     }
432                     throw;
433                 }
434             }
435             setServerProcessProxy(adminAdapter, adminIdentity);
436             return adminAdapter.createProxy(adminIdentity);
437         }
438 
439         public Ice.ObjectPrx
getAdmin()440         getAdmin()
441         {
442             Ice.ObjectAdapter adminAdapter;
443             Ice.Identity adminIdentity;
444 
445             lock(this)
446             {
447                 if(_state == StateDestroyed)
448                 {
449                     throw new Ice.CommunicatorDestroyedException();
450                 }
451 
452                 if(_adminAdapter != null)
453                 {
454                     return _adminAdapter.createProxy(_adminIdentity);
455                 }
456                 else if(_adminEnabled)
457                 {
458                     if(_initData.properties.getProperty("Ice.Admin.Endpoints").Length > 0)
459                     {
460                         adminAdapter = _objectAdapterFactory.createObjectAdapter("Ice.Admin", null);
461                     }
462                     else
463                     {
464                         return null;
465                     }
466                     adminIdentity = new Ice.Identity("admin", _initData.properties.getProperty("Ice.Admin.InstanceName"));
467                     if(adminIdentity.category.Length == 0)
468                     {
469                         adminIdentity.category = System.Guid.NewGuid().ToString();
470                     }
471 
472                     _adminIdentity = adminIdentity;
473                     _adminAdapter = adminAdapter;
474                     addAllAdminFacets();
475                     // continue below outside synchronization
476                 }
477                 else
478                 {
479                     return null;
480                 }
481             }
482 
483             try
484             {
485                 adminAdapter.activate();
486             }
487             catch(Ice.LocalException)
488             {
489                 //
490                 // We cleanup _adminAdapter, however this error is not recoverable
491                 // (can't call again getAdmin() after fixing the problem)
492                 // since all the facets (servants) in the adapter are lost
493                 //
494                 adminAdapter.destroy();
495                 lock(this)
496                 {
497                     _adminAdapter = null;
498                 }
499                 throw;
500             }
501 
502             setServerProcessProxy(adminAdapter, adminIdentity);
503             return adminAdapter.createProxy(adminIdentity);
504         }
505 
506         public void
addAdminFacet(Ice.Object servant, string facet)507         addAdminFacet(Ice.Object servant, string facet)
508         {
509             lock(this)
510             {
511                 if(_state == StateDestroyed)
512                 {
513                     throw new Ice.CommunicatorDestroyedException();
514                 }
515 
516                 if(_adminAdapter == null || (_adminFacetFilter.Count > 0 && !_adminFacetFilter.Contains(facet)))
517                 {
518                     if(_adminFacets.ContainsKey(facet))
519                     {
520                         throw new Ice.AlreadyRegisteredException("facet", facet);
521                     }
522                     _adminFacets.Add(facet, servant);
523                 }
524                 else
525                 {
526                     _adminAdapter.addFacet(servant, _adminIdentity, facet);
527                 }
528             }
529         }
530 
531         public Ice.Object
removeAdminFacet(string facet)532         removeAdminFacet(string facet)
533         {
534             lock(this)
535             {
536                 if(_state == StateDestroyed)
537                 {
538                     throw new Ice.CommunicatorDestroyedException();
539                 }
540 
541                 Ice.Object result = null;
542                 if(_adminAdapter == null || (_adminFacetFilter.Count > 0 && !_adminFacetFilter.Contains(facet)))
543                 {
544                     try
545                     {
546                         result = _adminFacets[facet];
547                     }
548                     catch(KeyNotFoundException)
549                     {
550                         throw new Ice.NotRegisteredException("facet", facet);
551                     }
552 
553                     _adminFacets.Remove(facet);
554                 }
555                 else
556                 {
557                     result = _adminAdapter.removeFacet(_adminIdentity, facet);
558                 }
559                 return result;
560             }
561         }
562 
563         public Ice.Object
findAdminFacet(string facet)564         findAdminFacet(string facet)
565         {
566             lock(this)
567             {
568                 if(_state == StateDestroyed)
569                 {
570                     throw new Ice.CommunicatorDestroyedException();
571                 }
572 
573                 Ice.Object result = null;
574                 if(_adminAdapter == null || (_adminFacetFilter.Count > 0 && !_adminFacetFilter.Contains(facet)))
575                 {
576                     try
577                     {
578                         result = _adminFacets[facet];
579                     }
580                     catch(KeyNotFoundException)
581                     {
582                     }
583                 }
584                 else
585                 {
586                     result = _adminAdapter.findFacet(_adminIdentity, facet);
587                 }
588                 return result;
589             }
590         }
591 
592         public Dictionary<string, Ice.Object>
findAllAdminFacets()593         findAllAdminFacets()
594         {
595             lock(this)
596             {
597                 if(_state == StateDestroyed)
598                 {
599                     throw new Ice.CommunicatorDestroyedException();
600                 }
601 
602                 if(_adminAdapter == null)
603                 {
604                     return new Dictionary<string, Ice.Object>(_adminFacets);
605                 }
606                 else
607                 {
608                     Dictionary<string, Ice.Object> result = _adminAdapter.findAllFacets(_adminIdentity);
609                     if(_adminFacets.Count > 0)
610                     {
611                         foreach(KeyValuePair<string, Ice.Object> p in _adminFacets)
612                         {
613                             result.Add(p.Key, p.Value);
614                         }
615                     }
616                     return result;
617                 }
618             }
619         }
620 
621         public void
setDefaultLocator(Ice.LocatorPrx locator)622         setDefaultLocator(Ice.LocatorPrx locator)
623         {
624             lock(this)
625             {
626                 if(_state == StateDestroyed)
627                 {
628                     throw new Ice.CommunicatorDestroyedException();
629                 }
630 
631                 _referenceFactory = _referenceFactory.setDefaultLocator(locator);
632             }
633         }
634 
635         public void
setDefaultRouter(Ice.RouterPrx router)636         setDefaultRouter(Ice.RouterPrx router)
637         {
638             lock(this)
639             {
640                 if(_state == StateDestroyed)
641                 {
642                     throw new Ice.CommunicatorDestroyedException();
643                 }
644 
645                 _referenceFactory = _referenceFactory.setDefaultRouter(router);
646             }
647         }
648 
649         public void
setLogger(Ice.Logger logger)650         setLogger(Ice.Logger logger)
651         {
652             //
653             // No locking, as it can only be called during plug-in loading
654             //
655             _initData.logger = logger;
656         }
657 
658         public void
setThreadHook(System.Action threadStart, System.Action threadStop)659         setThreadHook(System.Action threadStart, System.Action threadStop)
660         {
661             //
662             // No locking, as it can only be called during plug-in loading
663             //
664             _initData.threadStart = threadStart;
665             _initData.threadStop = threadStop;
666         }
667 
668         //
669         // Return the C# class associated with this Slice type-id
670         // Used for both non-local Slice classes and exceptions
671         //
resolveClass(string id)672         public Type resolveClass(string id)
673         {
674             // First attempt corresponds to no cs:namespace metadata in the
675             // enclosing top-level module
676             //
677             string className = typeToClass(id);
678             Type c = AssemblyUtil.findType(this, className);
679 
680             //
681             // If this fails, look for helper classes in the typeIdNamespaces namespace(s)
682             //
683             if(c == null && _initData.typeIdNamespaces != null)
684             {
685                 foreach(var ns in _initData.typeIdNamespaces)
686                 {
687                     Type helper = AssemblyUtil.findType(this, ns + "." + className);
688                     if(helper != null)
689                     {
690                         try
691                         {
692                             c = helper.GetProperty("targetClass").PropertyType;
693                             break; // foreach
694                         }
695                         catch(Exception)
696                         {
697                         }
698                     }
699                 }
700             }
701 
702             //
703             // Ensure the class is instantiable.
704             //
705             if(c != null && !c.IsAbstract && !c.IsInterface)
706             {
707                 return c;
708             }
709 
710             return null;
711         }
712 
resolveCompactId(int compactId)713         public string resolveCompactId(int compactId)
714         {
715             string[] defaultVal = {"IceCompactId"};
716             var compactIdNamespaces = new List<string>(defaultVal);
717 
718             if(_initData.typeIdNamespaces != null)
719             {
720                 compactIdNamespaces.AddRange(_initData.typeIdNamespaces);
721             }
722 
723             string result = "";
724 
725             foreach(var ns in compactIdNamespaces)
726             {
727                 string className = ns + ".TypeId_" + compactId;
728                 try
729                 {
730                     Type c = AssemblyUtil.findType(this, className);
731                     if(c != null)
732                     {
733                        result = (string)c.GetField("typeId").GetValue(null);
734                        break; // foreach
735                     }
736                 }
737                 catch(Exception)
738                 {
739                 }
740             }
741             return result;
742         }
743 
typeToClass(string id)744         private static string typeToClass(string id)
745         {
746             if(!id.StartsWith("::", StringComparison.Ordinal))
747             {
748                 throw new Ice.MarshalException("expected type id but received `" + id + "'");
749             }
750             return id.Substring(2).Replace("::", ".");
751         }
752 
753         //
754         // Only for use by Ice.CommunicatorI
755         //
Instance(Ice.Communicator communicator, Ice.InitializationData initData)756         public Instance(Ice.Communicator communicator, Ice.InitializationData initData)
757         {
758             _state = StateActive;
759             _initData = initData;
760 
761             try
762             {
763                 if(_initData.properties == null)
764                 {
765                     _initData.properties = Ice.Util.createProperties();
766                 }
767 
768                 lock(_staticLock)
769                 {
770                     if(!_oneOffDone)
771                     {
772                         string stdOut = _initData.properties.getProperty("Ice.StdOut");
773                         string stdErr = _initData.properties.getProperty("Ice.StdErr");
774 
775                         System.IO.StreamWriter outStream = null;
776 
777                         if(stdOut.Length > 0)
778                         {
779                             try
780                             {
781                                 outStream = System.IO.File.AppendText(stdOut);
782                             }
783                             catch(System.IO.IOException ex)
784                             {
785                                 Ice.FileException fe = new Ice.FileException(ex);
786                                 fe.path = stdOut;
787                                 throw fe;
788                             }
789                             outStream.AutoFlush = true;
790                             Console.Out.Close();
791                             Console.SetOut(outStream);
792                         }
793                         if(stdErr.Length > 0)
794                         {
795                             if(stdErr.Equals(stdOut))
796                             {
797                                 Console.SetError(outStream);
798                             }
799                             else
800                             {
801                                 System.IO.StreamWriter errStream = null;
802                                 try
803                                 {
804                                     errStream = System.IO.File.AppendText(stdErr);
805                                 }
806                                 catch(System.IO.IOException ex)
807                                 {
808                                     Ice.FileException fe = new Ice.FileException(ex);
809                                     fe.path = stdErr;
810                                     throw fe;
811                                 }
812                                 errStream.AutoFlush = true;
813                                 Console.Error.Close();
814                                 Console.SetError(errStream);
815                             }
816                         }
817 
818                         _oneOffDone = true;
819                     }
820                 }
821 
822                 if(_initData.logger == null)
823                 {
824                     string logfile = _initData.properties.getProperty("Ice.LogFile");
825                     if(logfile.Length != 0)
826                     {
827                         _initData.logger =
828                             new Ice.FileLoggerI(_initData.properties.getProperty("Ice.ProgramName"), logfile);
829                     }
830                     else if(Ice.Util.getProcessLogger() is Ice.LoggerI)
831                     {
832                         //
833                         // Ice.ConsoleListener is enabled by default.
834                         //
835                         bool console = _initData.properties.getPropertyAsIntWithDefault("Ice.ConsoleListener", 1) > 0;
836                         _initData.logger =
837                             new Ice.TraceLoggerI(_initData.properties.getProperty("Ice.ProgramName"), console);
838                     }
839                     else
840                     {
841                         _initData.logger = Ice.Util.getProcessLogger();
842                     }
843                 }
844 
845                 _traceLevels = new TraceLevels(_initData.properties);
846 
847                 _defaultsAndOverrides = new DefaultsAndOverrides(_initData.properties, _initData.logger);
848 
849                 _clientACM = new ACMConfig(_initData.properties,
850                                            _initData.logger,
851                                            "Ice.ACM.Client",
852                                            new ACMConfig(_initData.properties, _initData.logger, "Ice.ACM",
853                                                          new ACMConfig(false)));
854 
855                 _serverACM = new ACMConfig(_initData.properties,
856                                            _initData.logger,
857                                            "Ice.ACM.Server",
858                                            new ACMConfig(_initData.properties, _initData.logger, "Ice.ACM",
859                                                          new ACMConfig(true)));
860 
861                 {
862                     const int defaultMessageSizeMax = 1024;
863                     int num =
864                         _initData.properties.getPropertyAsIntWithDefault("Ice.MessageSizeMax", defaultMessageSizeMax);
865                     if(num < 1 || num > 0x7fffffff / 1024)
866                     {
867                         _messageSizeMax = 0x7fffffff;
868                     }
869                     else
870                     {
871                         _messageSizeMax = num * 1024; // Property is in kilobytes, _messageSizeMax in bytes
872                     }
873                 }
874 
875                 if(_initData.properties.getProperty("Ice.BatchAutoFlushSize").Length == 0 &&
876                    _initData.properties.getProperty("Ice.BatchAutoFlush").Length > 0)
877                 {
878                     if(_initData.properties.getPropertyAsInt("Ice.BatchAutoFlush") > 0)
879                     {
880                         _batchAutoFlushSize = _messageSizeMax;
881                     }
882                 }
883                 else
884                 {
885                     int num = _initData.properties.getPropertyAsIntWithDefault("Ice.BatchAutoFlushSize", 1024); // 1MB
886                     if(num < 1)
887                     {
888                         _batchAutoFlushSize = num;
889                     }
890                     else if(num > 0x7fffffff / 1024)
891                     {
892                         _batchAutoFlushSize = 0x7fffffff;
893                     }
894                     else
895                     {
896                         _batchAutoFlushSize = num * 1024; // Property is in kilobytes, _batchAutoFlushSize in bytes
897                     }
898                 }
899 
900                 {
901                     const int defaultValue = 100;
902                     var num = _initData.properties.getPropertyAsIntWithDefault("Ice.ClassGraphDepthMax", defaultValue);
903                     if(num < 1 || num > 0x7fffffff)
904                     {
905                         _classGraphDepthMax = 0x7fffffff;
906                     }
907                     else
908                     {
909                         _classGraphDepthMax = num;
910                     }
911                 }
912 
913                 string toStringModeStr = _initData.properties.getPropertyWithDefault("Ice.ToStringMode", "Unicode");
914                 if(toStringModeStr == "Unicode")
915                 {
916                     _toStringMode = Ice.ToStringMode.Unicode;
917                 }
918                 else if(toStringModeStr == "ASCII")
919                 {
920                     _toStringMode = Ice.ToStringMode.ASCII;
921                 }
922                 else if(toStringModeStr == "Compat")
923                 {
924                     _toStringMode = Ice.ToStringMode.Compat;
925                 }
926                 else
927                 {
928                     throw new Ice.InitializationException("The value for Ice.ToStringMode must be Unicode, ASCII or Compat");
929                 }
930 
931                 _cacheMessageBuffers = _initData.properties.getPropertyAsIntWithDefault("Ice.CacheMessageBuffers", 2);
932 
933                 _implicitContext = Ice.ImplicitContextI.create(_initData.properties.getProperty("Ice.ImplicitContext"));
934                 _routerManager = new RouterManager();
935 
936                 _locatorManager = new LocatorManager(_initData.properties);
937 
938                 _referenceFactory = new ReferenceFactory(this, communicator);
939 
940                 _proxyFactory = new ProxyFactory(this);
941 
942                 _requestHandlerFactory = new RequestHandlerFactory(this);
943 
944                 bool isIPv6Supported = Network.isIPv6Supported();
945                 bool ipv4 = _initData.properties.getPropertyAsIntWithDefault("Ice.IPv4", 1) > 0;
946                 bool ipv6 = _initData.properties.getPropertyAsIntWithDefault("Ice.IPv6", isIPv6Supported ? 1 : 0) > 0;
947                 if(!ipv4 && !ipv6)
948                 {
949                     throw new Ice.InitializationException("Both IPV4 and IPv6 support cannot be disabled.");
950                 }
951                 else if(ipv4 && ipv6)
952                 {
953                     _protocolSupport = Network.EnableBoth;
954                 }
955                 else if(ipv4)
956                 {
957                     _protocolSupport = Network.EnableIPv4;
958                 }
959                 else
960                 {
961                     _protocolSupport = Network.EnableIPv6;
962                 }
963                 _preferIPv6 = _initData.properties.getPropertyAsInt("Ice.PreferIPv6Address") > 0;
964 
965                 _networkProxy = createNetworkProxy(_initData.properties, _protocolSupport);
966 
967                 _endpointFactoryManager = new EndpointFactoryManager(this);
968 
969                 ProtocolInstance tcpInstance = new ProtocolInstance(this, Ice.TCPEndpointType.value, "tcp", false);
970                 _endpointFactoryManager.add(new TcpEndpointFactory(tcpInstance));
971 
972                 ProtocolInstance udpInstance = new ProtocolInstance(this, Ice.UDPEndpointType.value, "udp", false);
973                 _endpointFactoryManager.add(new UdpEndpointFactory(udpInstance));
974 
975                 ProtocolInstance wsInstance = new ProtocolInstance(this, Ice.WSEndpointType.value, "ws", false);
976                 _endpointFactoryManager.add(new WSEndpointFactory(wsInstance, Ice.TCPEndpointType.value));
977 
978                 ProtocolInstance wssInstance = new ProtocolInstance(this, Ice.WSSEndpointType.value, "wss", true);
979                 _endpointFactoryManager.add(new WSEndpointFactory(wssInstance, Ice.SSLEndpointType.value));
980 
981                 _pluginManager = new Ice.PluginManagerI(communicator);
982 
983                 if(_initData.valueFactoryManager == null)
984                 {
985                     _initData.valueFactoryManager = new ValueFactoryManagerI();
986                 }
987 
988                 _outgoingConnectionFactory = new OutgoingConnectionFactory(communicator, this);
989 
990                 _objectAdapterFactory = new ObjectAdapterFactory(this, communicator);
991 
992                 _retryQueue = new RetryQueue(this);
993 
994                 if(_initData.properties.getPropertyAsIntWithDefault("Ice.PreloadAssemblies", 0) > 0)
995                 {
996                     AssemblyUtil.preloadAssemblies();
997                 }
998 
999 #pragma warning disable 618
1000                 if(_initData.threadStart == null && _initData.threadHook != null)
1001                 {
1002                     _initData.threadStart = _initData.threadHook.start;
1003                 }
1004                 if(_initData.threadStop == null && _initData.threadHook != null)
1005                 {
1006                     _initData.threadStop = _initData.threadHook.stop;
1007                 }
1008 #pragma warning restore 618
1009             }
1010             catch(Ice.LocalException)
1011             {
1012                 destroy();
1013                 throw;
1014             }
1015         }
1016 
finishSetup(ref string[] args, Ice.Communicator communicator)1017         public void finishSetup(ref string[] args, Ice.Communicator communicator)
1018         {
1019             //
1020             // Load plug-ins.
1021             //
1022             Debug.Assert(_serverThreadPool == null);
1023             Ice.PluginManagerI pluginManagerImpl = (Ice.PluginManagerI)_pluginManager;
1024             pluginManagerImpl.loadPlugins(ref args);
1025 
1026             //
1027             // Initialize the endpoint factories once all the plugins are loaded. This gives
1028             // the opportunity for the endpoint factories to find underyling factories.
1029             //
1030             _endpointFactoryManager.initialize();
1031 
1032             //
1033             // Create Admin facets, if enabled.
1034             //
1035             // Note that any logger-dependent admin facet must be created after we load all plugins,
1036             // since one of these plugins can be a Logger plugin that sets a new logger during loading
1037             //
1038 
1039             if(_initData.properties.getProperty("Ice.Admin.Enabled").Length == 0)
1040             {
1041                 _adminEnabled = _initData.properties.getProperty("Ice.Admin.Endpoints").Length > 0;
1042             }
1043             else
1044             {
1045                 _adminEnabled = _initData.properties.getPropertyAsInt("Ice.Admin.Enabled") > 0;
1046             }
1047 
1048             string[] facetFilter = _initData.properties.getPropertyAsList("Ice.Admin.Facets");
1049             if(facetFilter.Length > 0)
1050             {
1051                 foreach(string s in facetFilter)
1052                 {
1053                     _adminFacetFilter.Add(s);
1054                 }
1055             }
1056 
1057             if(_adminEnabled)
1058             {
1059                 //
1060                 // Process facet
1061                 //
1062                 string processFacetName = "Process";
1063                 if(_adminFacetFilter.Count == 0 || _adminFacetFilter.Contains(processFacetName))
1064                 {
1065                     _adminFacets.Add(processFacetName, new ProcessI(communicator));
1066                 }
1067 
1068                 //
1069                 // Logger facet
1070                 //
1071                 string loggerFacetName = "Logger";
1072                 if(_adminFacetFilter.Count == 0 || _adminFacetFilter.Contains(loggerFacetName))
1073                 {
1074                     LoggerAdminLogger logger = new LoggerAdminLoggerI(_initData.properties, _initData.logger);
1075                     setLogger(logger);
1076                     _adminFacets.Add(loggerFacetName, logger.getFacet());
1077                 }
1078 
1079                 //
1080                 // Properties facet
1081                 //
1082                 string propertiesFacetName = "Properties";
1083                 PropertiesAdminI propsAdmin = null;
1084                 if(_adminFacetFilter.Count == 0 || _adminFacetFilter.Contains(propertiesFacetName))
1085                 {
1086                      propsAdmin= new PropertiesAdminI(this);
1087                     _adminFacets.Add(propertiesFacetName, propsAdmin);
1088                 }
1089 
1090                 //
1091                 // Metrics facet
1092                 //
1093                 string metricsFacetName = "Metrics";
1094                 if(_adminFacetFilter.Count == 0 || _adminFacetFilter.Contains(metricsFacetName))
1095                 {
1096                     CommunicatorObserverI observer = new CommunicatorObserverI(_initData);
1097                     _initData.observer = observer;
1098                     _adminFacets.Add(metricsFacetName, observer.getFacet());
1099 
1100                     //
1101                     // Make sure the admin plugin receives property updates.
1102                     //
1103                     if(propsAdmin != null)
1104                     {
1105                         propsAdmin.addUpdateCallback(observer.getFacet());
1106                     }
1107                 }
1108             }
1109 
1110             //
1111             // Set observer updater
1112             //
1113             if(_initData.observer != null)
1114             {
1115                 _initData.observer.setObserverUpdater(new ObserverUpdaterI(this));
1116             }
1117 
1118             //
1119             // Create threads.
1120             //
1121             try
1122             {
1123                 _timer = new Timer(this, Util.stringToThreadPriority(
1124                                                 initializationData().properties.getProperty("Ice.ThreadPriority")));
1125             }
1126             catch(Exception ex)
1127             {
1128                 string s = "cannot create thread for timer:\n" + ex;
1129                 _initData.logger.error(s);
1130                 throw;
1131             }
1132 
1133             try
1134             {
1135                 _endpointHostResolver = new EndpointHostResolver(this);
1136             }
1137             catch(Exception ex)
1138             {
1139                 string s = "cannot create thread for endpoint host resolver:\n" + ex;
1140                 _initData.logger.error(s);
1141                 throw;
1142             }
1143             _clientThreadPool = new ThreadPool(this, "Ice.ThreadPool.Client", 0);
1144 
1145             //
1146             // The default router/locator may have been set during the loading of plugins.
1147             // Therefore we make sure it is not already set before checking the property.
1148             //
1149             if(_referenceFactory.getDefaultRouter() == null)
1150             {
1151                 Ice.RouterPrx r = Ice.RouterPrxHelper.uncheckedCast(
1152                     _proxyFactory.propertyToProxy("Ice.Default.Router"));
1153                 if(r != null)
1154                 {
1155                     _referenceFactory = _referenceFactory.setDefaultRouter(r);
1156                 }
1157             }
1158 
1159             if(_referenceFactory.getDefaultLocator() == null)
1160             {
1161                 Ice.LocatorPrx l = Ice.LocatorPrxHelper.uncheckedCast(
1162                     _proxyFactory.propertyToProxy("Ice.Default.Locator"));
1163                 if(l != null)
1164                 {
1165                     _referenceFactory = _referenceFactory.setDefaultLocator(l);
1166                 }
1167             }
1168 
1169             //
1170             // Show process id if requested (but only once).
1171             //
1172             lock(this)
1173             {
1174                 if(!_printProcessIdDone && _initData.properties.getPropertyAsInt("Ice.PrintProcessId") > 0)
1175                 {
1176                     using(Process p = Process.GetCurrentProcess())
1177                     {
1178                         Console.WriteLine(p.Id);
1179                     }
1180                     _printProcessIdDone = true;
1181                 }
1182             }
1183 
1184             //
1185             // Server thread pool initialization is lazy in serverThreadPool().
1186             //
1187 
1188             //
1189             // An application can set Ice.InitPlugins=0 if it wants to postpone
1190             // initialization until after it has interacted directly with the
1191             // plug-ins.
1192             //
1193             if(_initData.properties.getPropertyAsIntWithDefault("Ice.InitPlugins", 1) > 0)
1194             {
1195                 pluginManagerImpl.initializePlugins();
1196             }
1197 
1198             //
1199             // This must be done last as this call creates the Ice.Admin object adapter
1200             // and eventually registers a process proxy with the Ice locator (allowing
1201             // remote clients to invoke on Ice.Admin facets as soon as it's registered).
1202             //
1203             if(_initData.properties.getPropertyAsIntWithDefault("Ice.Admin.DelayCreation", 0) <= 0)
1204             {
1205                 getAdmin();
1206             }
1207         }
1208 
1209         //
1210         // Only for use by Ice.CommunicatorI
1211         //
destroy()1212         public void destroy()
1213         {
1214             lock(this)
1215             {
1216                 //
1217                 // If destroy is in progress, wait for it to be done. This
1218                 // is necessary in case destroy() is called concurrently
1219                 // by multiple threads.
1220                 //
1221                 while(_state == StateDestroyInProgress)
1222                 {
1223                     Monitor.Wait(this);
1224                 }
1225 
1226                 if(_state == StateDestroyed)
1227                 {
1228                     return;
1229                 }
1230                 _state = StateDestroyInProgress;
1231             }
1232 
1233             //
1234             // Shutdown and destroy all the incoming and outgoing Ice
1235             // connections and wait for the connections to be finished.
1236             //
1237             if(_objectAdapterFactory != null)
1238             {
1239                 _objectAdapterFactory.shutdown();
1240             }
1241 
1242             if(_outgoingConnectionFactory != null)
1243             {
1244                 _outgoingConnectionFactory.destroy();
1245             }
1246 
1247             if(_objectAdapterFactory != null)
1248             {
1249                 _objectAdapterFactory.destroy();
1250             }
1251 
1252             if(_outgoingConnectionFactory != null)
1253             {
1254                 _outgoingConnectionFactory.waitUntilFinished();
1255             }
1256 
1257             if(_retryQueue != null)
1258             {
1259                 _retryQueue.destroy(); // Must be called before destroying thread pools.
1260             }
1261 
1262             if(_initData.observer != null)
1263             {
1264                 _initData.observer.setObserverUpdater(null);
1265             }
1266 
1267             {
1268                 LoggerAdminLogger logger = _initData.logger as LoggerAdminLogger;
1269                 if(logger != null)
1270                 {
1271                     logger.destroy();
1272                 }
1273             }
1274 
1275             //
1276             // Now, destroy the thread pools. This must be done *only* after
1277             // all the connections are finished (the connections destruction
1278             // can require invoking callbacks with the thread pools).
1279             //
1280             if(_serverThreadPool != null)
1281             {
1282                 _serverThreadPool.destroy();
1283             }
1284             if(_clientThreadPool != null)
1285             {
1286                 _clientThreadPool.destroy();
1287             }
1288             if(_asyncIOThread != null)
1289             {
1290                 _asyncIOThread.destroy();
1291             }
1292             if(_endpointHostResolver != null)
1293             {
1294                 _endpointHostResolver.destroy();
1295             }
1296 
1297             //
1298             // Wait for all the threads to be finished.
1299             //
1300             if(_timer != null)
1301             {
1302                 _timer.destroy();
1303             }
1304             if(_clientThreadPool != null)
1305             {
1306                 _clientThreadPool.joinWithAllThreads();
1307             }
1308             if(_serverThreadPool != null)
1309             {
1310                 _serverThreadPool.joinWithAllThreads();
1311             }
1312             if(_asyncIOThread != null)
1313             {
1314                 _asyncIOThread.joinWithThread();
1315             }
1316             if(_endpointHostResolver != null)
1317             {
1318                 _endpointHostResolver.joinWithThread();
1319             }
1320 
1321             foreach(Ice.ObjectFactory factory in _objectFactoryMap.Values)
1322             {
1323 // Disable Obsolete warning/error
1324 #pragma warning disable 612, 618
1325                 factory.destroy();
1326 #pragma warning restore 612, 618
1327             }
1328             _objectFactoryMap.Clear();
1329 
1330             if(_routerManager != null)
1331             {
1332                 _routerManager.destroy();
1333             }
1334 
1335             if(_locatorManager != null)
1336             {
1337                 _locatorManager.destroy();
1338             }
1339 
1340             if(_endpointFactoryManager != null)
1341             {
1342                 _endpointFactoryManager.destroy();
1343             }
1344 
1345             if(_initData.properties.getPropertyAsInt("Ice.Warn.UnusedProperties") > 0)
1346             {
1347                 List<string> unusedProperties = ((Ice.PropertiesI)_initData.properties).getUnusedProperties();
1348                 if (unusedProperties.Count != 0)
1349                 {
1350                     StringBuilder message = new StringBuilder("The following properties were set but never read:");
1351                     foreach (string s in unusedProperties)
1352                     {
1353                         message.Append("\n    ");
1354                         message.Append(s);
1355                     }
1356                     _initData.logger.warning(message.ToString());
1357                 }
1358             }
1359 
1360             //
1361             // Destroy last so that a Logger plugin can receive all log/traces before its destruction.
1362             //
1363             if(_pluginManager != null)
1364             {
1365                 _pluginManager.destroy();
1366             }
1367 
1368             lock(this)
1369             {
1370                 _objectAdapterFactory = null;
1371                 _outgoingConnectionFactory = null;
1372                 _retryQueue = null;
1373 
1374                 _serverThreadPool = null;
1375                 _clientThreadPool = null;
1376                 _asyncIOThread = null;
1377                 _endpointHostResolver = null;
1378                 _timer = null;
1379 
1380                 _referenceFactory = null;
1381                 _requestHandlerFactory = null;
1382                 _proxyFactory = null;
1383                 _routerManager = null;
1384                 _locatorManager = null;
1385                 _endpointFactoryManager = null;
1386                 _pluginManager = null;
1387 
1388                 _adminAdapter = null;
1389                 _adminFacets.Clear();
1390 
1391                 _state = StateDestroyed;
1392                 Monitor.PulseAll(this);
1393             }
1394 
1395             {
1396                 Ice.FileLoggerI logger = _initData.logger as Ice.FileLoggerI;
1397                 if(logger != null)
1398                 {
1399                     logger.destroy();
1400                 }
1401             }
1402         }
1403 
getBufSizeWarn(short type)1404         public BufSizeWarnInfo getBufSizeWarn(short type)
1405         {
1406             lock(_setBufSizeWarn)
1407             {
1408                 BufSizeWarnInfo info;
1409                 if(!_setBufSizeWarn.ContainsKey(type))
1410                 {
1411                     info = new BufSizeWarnInfo();
1412                     info.sndWarn = false;
1413                     info.sndSize = -1;
1414                     info.rcvWarn = false;
1415                     info.rcvSize = -1;
1416                     _setBufSizeWarn.Add(type, info);
1417                 }
1418                 else
1419                 {
1420                     info = _setBufSizeWarn[type];
1421                 }
1422                 return info;
1423             }
1424         }
1425 
setSndBufSizeWarn(short type, int size)1426         public void setSndBufSizeWarn(short type, int size)
1427         {
1428             lock(_setBufSizeWarn)
1429             {
1430                 BufSizeWarnInfo info = getBufSizeWarn(type);
1431                 info.sndWarn = true;
1432                 info.sndSize = size;
1433                 _setBufSizeWarn[type] = info;
1434             }
1435         }
1436 
setRcvBufSizeWarn(short type, int size)1437         public void setRcvBufSizeWarn(short type, int size)
1438         {
1439             lock(_setBufSizeWarn)
1440             {
1441                 BufSizeWarnInfo info = getBufSizeWarn(type);
1442                 info.rcvWarn = true;
1443                 info.rcvSize = size;
1444                 _setBufSizeWarn[type] = info;
1445             }
1446         }
1447 
addObjectFactory(Ice.ObjectFactory factory, string id)1448         public void addObjectFactory(Ice.ObjectFactory factory, string id)
1449         {
1450             lock(this)
1451             {
1452                 //
1453                 // Create a ValueFactory wrapper around the given ObjectFactory and register the wrapper
1454                 // with the value factory manager. This may raise AlreadyRegisteredException.
1455                 //
1456 // Disable Obsolete warning/error
1457 #pragma warning disable 612, 618
1458                 _initData.valueFactoryManager.add((string type) => { return factory.create(type); }, id);
1459 #pragma warning restore 612, 618
1460                 _objectFactoryMap.Add(id, factory);
1461             }
1462         }
1463 
findObjectFactory(string id)1464         public Ice.ObjectFactory findObjectFactory(string id)
1465         {
1466             lock(this)
1467             {
1468                 Ice.ObjectFactory factory = null;
1469                 _objectFactoryMap.TryGetValue(id, out factory);
1470                 return factory;
1471             }
1472         }
1473 
updateConnectionObservers()1474         internal void updateConnectionObservers()
1475         {
1476             try
1477             {
1478                 Debug.Assert(_outgoingConnectionFactory != null);
1479                 _outgoingConnectionFactory.updateConnectionObservers();
1480                 Debug.Assert(_objectAdapterFactory != null);
1481                 _objectAdapterFactory.updateConnectionObservers();
1482             }
1483             catch(Ice.CommunicatorDestroyedException)
1484             {
1485             }
1486         }
1487 
updateThreadObservers()1488         internal void updateThreadObservers()
1489         {
1490             try
1491             {
1492                 if(_clientThreadPool != null)
1493                 {
1494                     _clientThreadPool.updateObservers();
1495                 }
1496                 if(_serverThreadPool != null)
1497                 {
1498                     _serverThreadPool.updateObservers();
1499                 }
1500                 Debug.Assert(_objectAdapterFactory != null);
1501                 _objectAdapterFactory.updateThreadObservers();
1502                 if(_endpointHostResolver != null)
1503                 {
1504                     _endpointHostResolver.updateObserver();
1505                 }
1506                 if(_asyncIOThread != null)
1507                 {
1508                     _asyncIOThread.updateObserver();
1509                 }
1510                 if(_timer != null)
1511                 {
1512                     _timer.updateObserver(_initData.observer);
1513                 }
1514             }
1515             catch(Ice.CommunicatorDestroyedException)
1516             {
1517             }
1518         }
1519 
addAllAdminFacets()1520         internal void addAllAdminFacets()
1521         {
1522             lock(this)
1523             {
1524                 Dictionary<string, Ice.Object> filteredFacets = new Dictionary<string, Ice.Object>();
1525 
1526                 foreach(KeyValuePair<string, Ice.Object> entry in _adminFacets)
1527                 {
1528                     if(_adminFacetFilter.Count == 0 || _adminFacetFilter.Contains(entry.Key))
1529                     {
1530                         _adminAdapter.addFacet(entry.Value, _adminIdentity, entry.Key);
1531                     }
1532                     else
1533                     {
1534                         filteredFacets.Add(entry.Key, entry.Value);
1535                     }
1536                 }
1537                 _adminFacets = filteredFacets;
1538             }
1539         }
1540 
setServerProcessProxy(Ice.ObjectAdapter adminAdapter, Ice.Identity adminIdentity)1541         internal void setServerProcessProxy(Ice.ObjectAdapter adminAdapter, Ice.Identity adminIdentity)
1542         {
1543             Ice.ObjectPrx admin = adminAdapter.createProxy(adminIdentity);
1544             Ice.LocatorPrx locator = adminAdapter.getLocator();
1545             string serverId = _initData.properties.getProperty("Ice.Admin.ServerId");
1546 
1547             if(locator != null && serverId.Length > 0)
1548             {
1549                 Ice.ProcessPrx process = Ice.ProcessPrxHelper.uncheckedCast(admin.ice_facet("Process"));
1550                 try
1551                 {
1552                     //
1553                     // Note that as soon as the process proxy is registered, the communicator might be
1554                     // shutdown by a remote client and admin facets might start receiving calls.
1555                     //
1556                     locator.getRegistry().setServerProcessProxy(serverId, process);
1557                 }
1558                 catch(Ice.ServerNotFoundException)
1559                 {
1560                     if(_traceLevels.location >= 1)
1561                     {
1562                         System.Text.StringBuilder s = new System.Text.StringBuilder();
1563                         s.Append("couldn't register server `" + serverId + "' with the locator registry:\n");
1564                         s.Append("the server is not known to the locator registry");
1565                         _initData.logger.trace(_traceLevels.locationCat, s.ToString());
1566                     }
1567 
1568                     throw new Ice.InitializationException("Locator knows nothing about server `" + serverId + "'");
1569                 }
1570                 catch(Ice.LocalException ex)
1571                 {
1572                     if(_traceLevels.location >= 1)
1573                     {
1574                         System.Text.StringBuilder s = new System.Text.StringBuilder();
1575                         s.Append("couldn't register server `" + serverId + "' with the locator registry:\n" + ex);
1576                         _initData.logger.trace(_traceLevels.locationCat, s.ToString());
1577                     }
1578                     throw; // TODO: Shall we raise a special exception instead of a non obvious local exception?
1579                 }
1580 
1581                 if(_traceLevels.location >= 1)
1582                 {
1583                     System.Text.StringBuilder s = new System.Text.StringBuilder();
1584                     s.Append("registered server `" + serverId + "' with the locator registry");
1585                     _initData.logger.trace(_traceLevels.locationCat, s.ToString());
1586                 }
1587             }
1588         }
1589 
createNetworkProxy(Ice.Properties props, int protocolSupport)1590         private NetworkProxy createNetworkProxy(Ice.Properties props, int protocolSupport)
1591         {
1592             string proxyHost;
1593 
1594             proxyHost = props.getProperty("Ice.SOCKSProxyHost");
1595             if(proxyHost.Length > 0)
1596             {
1597                 if(protocolSupport == Network.EnableIPv6)
1598                 {
1599                     throw new Ice.InitializationException("IPv6 only is not supported with SOCKS4 proxies");
1600                 }
1601                 int proxyPort = props.getPropertyAsIntWithDefault("Ice.SOCKSProxyPort", 1080);
1602                 return new SOCKSNetworkProxy(proxyHost, proxyPort);
1603             }
1604 
1605             proxyHost = props.getProperty("Ice.HTTPProxyHost");
1606             if(proxyHost.Length > 0)
1607             {
1608                 return new HTTPNetworkProxy(proxyHost, props.getPropertyAsIntWithDefault("Ice.HTTPProxyPort", 1080));
1609             }
1610 
1611             return null;
1612         }
1613 
1614         private const int StateActive = 0;
1615         private const int StateDestroyInProgress = 1;
1616         private const int StateDestroyed = 2;
1617         private int _state;
1618         private Ice.InitializationData _initData; // Immutable, not reset by destroy().
1619         private TraceLevels _traceLevels; // Immutable, not reset by destroy().
1620         private DefaultsAndOverrides _defaultsAndOverrides; // Immutable, not reset by destroy().
1621         private int _messageSizeMax; // Immutable, not reset by destroy().
1622         private int _batchAutoFlushSize; // Immutable, not reset by destroy().
1623         private int _classGraphDepthMax; // Immutable, not reset by destroy().
1624         private Ice.ToStringMode _toStringMode; // Immutable, not reset by destroy().
1625         private int _cacheMessageBuffers; // Immutable, not reset by destroy().
1626         private ACMConfig _clientACM; // Immutable, not reset by destroy().
1627         private ACMConfig _serverACM; // Immutable, not reset by destroy().
1628         private Ice.ImplicitContextI _implicitContext; // Immutable
1629         private RouterManager _routerManager;
1630         private LocatorManager _locatorManager;
1631         private ReferenceFactory _referenceFactory;
1632         private RequestHandlerFactory _requestHandlerFactory;
1633         private ProxyFactory _proxyFactory;
1634         private OutgoingConnectionFactory _outgoingConnectionFactory;
1635         private ObjectAdapterFactory _objectAdapterFactory;
1636         private int _protocolSupport;
1637         private bool _preferIPv6;
1638         private NetworkProxy _networkProxy;
1639         private ThreadPool _clientThreadPool;
1640         private ThreadPool _serverThreadPool;
1641         private AsyncIOThread _asyncIOThread;
1642         private EndpointHostResolver _endpointHostResolver;
1643         private Timer _timer;
1644         private RetryQueue _retryQueue;
1645         private EndpointFactoryManager _endpointFactoryManager;
1646         private Ice.PluginManager _pluginManager;
1647         private bool _adminEnabled = false;
1648         private Ice.ObjectAdapter _adminAdapter;
1649         private Dictionary<string, Ice.Object> _adminFacets = new Dictionary<string, Ice.Object>();
1650         private HashSet<string> _adminFacetFilter = new HashSet<string>();
1651         private Ice.Identity _adminIdentity;
1652         private Dictionary<short, BufSizeWarnInfo> _setBufSizeWarn = new Dictionary<short, BufSizeWarnInfo>();
1653         private static bool _printProcessIdDone = false;
1654         private static bool _oneOffDone = false;
1655         private Dictionary<string, Ice.ObjectFactory> _objectFactoryMap = new Dictionary<string, Ice.ObjectFactory>();
1656         private static object _staticLock = new object();
1657     }
1658 }
1659