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