~ubuntu-branches/ubuntu/quantal/zeroc-ice/quantal

« back to all changes in this revision

Viewing changes to cs/src/Ice/Reference.cs

  • Committer: Bazaar Package Importer
  • Author(s): Cleto Martin Angelina
  • Date: 2011-04-25 18:44:24 UTC
  • mfrom: (6.1.14 sid)
  • Revision ID: james.westby@ubuntu.com-20110425184424-sep9i9euu434vq4c
Tags: 3.4.1-7
* Bug fix: "libdb5.1-java.jar was renamed to db.jar", thanks to Ondřej
  Surý (Closes: #623555).
* Bug fix: "causes noise in php5", thanks to Jayen Ashar (Closes:
  #623533).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
// **********************************************************************
2
2
//
3
 
// Copyright (c) 2003-2009 ZeroC, Inc. All rights reserved.
 
3
// Copyright (c) 2003-2010 ZeroC, Inc. All rights reserved.
4
4
//
5
5
// This copy of Ice is licensed to you under the terms described in the
6
6
// ICE_LICENSE file included in this distribution.
12
12
using System.Collections.Generic;
13
13
using System.Diagnostics;
14
14
using System.Text;
 
15
using System.Globalization;
15
16
 
16
17
namespace IceInternal
17
18
{
62
63
            return context_;
63
64
        }
64
65
 
65
 
        public Reference defaultContext()
66
 
        {
67
 
            Reference r = instance_.referenceFactory().copy(this);
68
 
            r.context_ = instance_.getDefaultContext();
69
 
            return r;
70
 
        }
71
 
 
72
66
        public Ice.Communicator getCommunicator()
73
67
        {
74
68
            return communicator_;
83
77
        public abstract bool getPreferSecure();
84
78
        public abstract Ice.EndpointSelectionType getEndpointSelection();
85
79
        public abstract int getLocatorCacheTimeout();
 
80
        public abstract String getConnectionId();
86
81
 
87
82
        //
88
83
        // The change* methods (here and in derived classes) create
260
255
            // the identity string in quotes.
261
256
            //
262
257
            string id = instance_.identityToString(identity_);
263
 
            if(IceUtilInternal.StringUtil.findFirstOf(id, " \t\n\r:@") != -1)
 
258
            if(IceUtilInternal.StringUtil.findFirstOf(id, " :@") != -1)
264
259
            {
265
260
                s.Append('"');
266
261
                s.Append(id);
280
275
                //
281
276
                s.Append(" -f ");
282
277
                string fs = IceUtilInternal.StringUtil.escapeString(facet_, "");
283
 
                if(IceUtilInternal.StringUtil.findFirstOf(fs, " \t\n\r:@") != -1)
 
278
                if(IceUtilInternal.StringUtil.findFirstOf(fs, " :@") != -1)
284
279
                {
285
280
                    s.Append('"');
286
281
                    s.Append(fs);
335
330
            // Derived class writes the remainder of the string.
336
331
        }
337
332
 
 
333
        public abstract Dictionary<string, string> toProperty(string prefix);
 
334
 
338
335
        public abstract Ice.ConnectionI getConnection(out bool comp);
339
336
        public abstract void getConnection(GetConnectionCallback callback);
340
337
 
409
406
        protected Reference(Instance instance,
410
407
                            Ice.Communicator communicator,
411
408
                            Ice.Identity identity,
412
 
                            Dictionary<string, string> context,
413
409
                            string facet,
414
410
                            Mode mode,
415
411
                            bool secure)
425
421
            communicator_ = communicator;
426
422
            mode_ = mode;
427
423
            identity_ = identity;
428
 
            context_ = context == null ? _emptyContext : context;
 
424
            context_ = _emptyContext;
429
425
            facet_ = facet;
430
426
            secure_ = secure;
431
427
            hashInitialized_ = false;
441
437
        public FixedReference(Instance instance,
442
438
                              Ice.Communicator communicator,
443
439
                              Ice.Identity identity,
444
 
                              Dictionary<string, string> context,
445
440
                              string facet,
446
441
                              Reference.Mode mode,
447
442
                              bool secure,
448
443
                              Ice.ConnectionI connection)
449
 
            : base(instance, communicator, identity, context, facet, mode, secure)
 
444
            : base(instance, communicator, identity, facet, mode, secure)
450
445
        {
451
446
            _fixedConnection = connection;
452
447
        }
453
448
 
454
449
        public override EndpointI[] getEndpoints()
455
450
        {
456
 
            return new EndpointI[0];
 
451
            return _emptyEndpoints;
457
452
        }
458
453
 
459
454
        public override string getAdapterId()
496
491
            return 0;
497
492
        }
498
493
 
 
494
        public override string getConnectionId()
 
495
        {
 
496
            return "";
 
497
        }
 
498
 
499
499
        public override Reference changeEndpoints(EndpointI[] newEndpoints)
500
500
        {
501
501
            throw new Ice.FixedProxyException();
571
571
            throw new Ice.FixedProxyException();
572
572
        }
573
573
 
 
574
        public override Dictionary<string, string> toProperty(string prefix)
 
575
        {
 
576
            throw new Ice.FixedProxyException();
 
577
        }
 
578
 
574
579
        public override Ice.ConnectionI getConnection(out bool compress)
575
580
        {
576
581
            switch(getMode())
653
658
            {
654
659
                return true;
655
660
            }
656
 
            if(!(obj is FixedReference))
 
661
            FixedReference rhs = obj as FixedReference;
 
662
            if(rhs == null)
657
663
            {
658
664
                return false;
659
665
            }
660
 
            FixedReference rhs = (FixedReference)obj;
661
666
            if(!base.Equals(rhs))
662
667
            {
663
668
                return false;
674
679
        }
675
680
 
676
681
        private Ice.ConnectionI _fixedConnection;
 
682
        private static EndpointI[] _emptyEndpoints = new EndpointI[0];
677
683
    }
678
684
 
679
685
    public class RoutableReference : Reference
723
729
            return _locatorCacheTimeout;
724
730
        }
725
731
 
 
732
        public override string getConnectionId()
 
733
        {
 
734
            return _connectionId;
 
735
        }
 
736
 
726
737
        public override Reference changeCompress(bool newCompress)
727
738
        {
728
739
            RoutableReference r = (RoutableReference)base.changeCompress(newCompress);
947
958
                // the adapter id string in quotes.
948
959
                //
949
960
                string a = IceUtilInternal.StringUtil.escapeString(_adapterId, null);
950
 
                if(IceUtilInternal.StringUtil.findFirstOf(a, " \t\n\r") != -1)
 
961
                if(IceUtilInternal.StringUtil.findFirstOf(a, " :@") != -1)
951
962
                {
952
963
                    s.Append('"');
953
964
                    s.Append(a);
961
972
            return s.ToString();
962
973
        }
963
974
 
 
975
        public override Dictionary<string, string> toProperty(string prefix)
 
976
        {
 
977
            Dictionary<string, string> properties = new Dictionary<string, string>();
 
978
 
 
979
            properties[prefix] = ToString();
 
980
            properties[prefix + ".CollocationOptimized"] = _collocationOptimized ? "1" : "0";
 
981
            properties[prefix + ".ConnectionCached"] = _cacheConnection ? "1" : "0";
 
982
            properties[prefix + ".PreferSecure"] = _preferSecure ? "1" : "0";
 
983
            properties[prefix + ".EndpointSelection"] =
 
984
                       _endpointSelection == Ice.EndpointSelectionType.Random ? "Random" : "Ordered";
 
985
            properties[prefix + ".LocatorCacheTimeout"] = _locatorCacheTimeout.ToString(CultureInfo.InvariantCulture);
 
986
 
 
987
            if(_routerInfo != null)
 
988
            {
 
989
                Ice.ObjectPrxHelperBase h = (Ice.ObjectPrxHelperBase)_routerInfo.getRouter();
 
990
                Dictionary<String, String> routerProperties = h.reference__().toProperty(prefix + ".Router");
 
991
                foreach(KeyValuePair<string, string> entry in routerProperties)
 
992
                {
 
993
                    properties[entry.Key] = entry.Value;
 
994
                }
 
995
            }
 
996
 
 
997
            if(_locatorInfo != null)
 
998
            {
 
999
                Ice.ObjectPrxHelperBase h = (Ice.ObjectPrxHelperBase)_locatorInfo.getLocator();
 
1000
                Dictionary<String, String> locatorProperties = h.reference__().toProperty(prefix + ".Locator");
 
1001
                foreach(KeyValuePair<string, string> entry in locatorProperties)
 
1002
                {
 
1003
                    properties[entry.Key] = entry.Value;
 
1004
                }
 
1005
            }
 
1006
 
 
1007
            return properties;
 
1008
        }
 
1009
        
964
1010
        //
965
1011
        // If we override Equals, we must also override GetHashCode.
966
1012
        //
985
1031
            {
986
1032
                return true;
987
1033
            }
988
 
            if(!(obj is RoutableReference))
 
1034
 
 
1035
            RoutableReference rhs = obj as RoutableReference;
 
1036
            if(rhs == null)
989
1037
            {
990
1038
                return false;
991
1039
            }
995
1043
                return false;
996
1044
            }
997
1045
 
998
 
            RoutableReference rhs = (RoutableReference)obj; // Guaranteed to succeed.
999
1046
            if(_locatorInfo == null ? rhs._locatorInfo != null : !_locatorInfo.Equals(rhs._locatorInfo))
1000
1047
            {
1001
1048
                return false;
1087
1134
                {
1088
1135
                    return createConnection(endpts, out comp);
1089
1136
                }
1090
 
                catch(Ice.NoEndpointException ex)
 
1137
                catch(Ice.NoEndpointException)
1091
1138
                {
1092
 
                    throw ex; // No need to retry if there's no endpoints.
 
1139
                    throw; // No need to retry if there's no endpoints.
1093
1140
                }
1094
1141
                catch(Ice.LocalException ex)
1095
1142
                {
1256
1303
        public RoutableReference(Instance instance,
1257
1304
                                 Ice.Communicator communicator,
1258
1305
                                 Ice.Identity identity,
1259
 
                                 Dictionary<string, string> context,
1260
1306
                                 string facet,
1261
1307
                                 Reference.Mode mode,
1262
1308
                                 bool secure,
1269
1315
                                 bool preferSecure,
1270
1316
                                 Ice.EndpointSelectionType endpointSelection,
1271
1317
                                 int locatorCacheTimeout)
1272
 
            : base(instance, communicator, identity, context, facet, mode, secure)
 
1318
            : base(instance, communicator, identity, facet, mode, secure)
1273
1319
        {
1274
1320
            _endpoints = endpoints;
1275
1321
            _adapterId = adapterId;
1321
1367
            //
1322
1368
            for(int i = 0; i < allEndpoints.Length; i++)
1323
1369
            {
1324
 
                if(!allEndpoints[i].unknown())
 
1370
                if(!(allEndpoints[i] is IceInternal.OpaqueEndpointI))
1325
1371
                {
1326
1372
                    endpoints.Add(allEndpoints[i]);
1327
1373
                }
1377
1423
            {
1378
1424
                case Ice.EndpointSelectionType.Random:
1379
1425
                {
1380
 
                    for(int i = 0; i < endpoints.Count - 2; ++i)
 
1426
                    lock(rand_)
1381
1427
                    {
1382
 
                        int r = rand_.Next(endpoints.Count - i) + i;
1383
 
                        Debug.Assert(r >= i && r < endpoints.Count);
1384
 
                        if(r != i)
 
1428
                        for(int i = 0; i < endpoints.Count - 1; ++i)
1385
1429
                        {
1386
 
                            object tmp = endpoints[i];
1387
 
                            endpoints[i] = endpoints[r];
1388
 
                            endpoints[r] = tmp;
 
1430
                            int r = rand_.Next(endpoints.Count - i) + i;
 
1431
                            Debug.Assert(r >= i && r < endpoints.Count);
 
1432
                            if(r != i)
 
1433
                            {
 
1434
                                object tmp = endpoints[i];
 
1435
                                endpoints[i] = endpoints[r];
 
1436
                                endpoints[r] = tmp;
 
1437
                            }
1389
1438
                        }
1390
1439
                    }
1391
1440
                    break;