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
|
// **********************************************************************
//
// Copyright (c) 2003-2016 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.
//
// **********************************************************************
#include <IceUtil/DisableWarnings.h>
#include <Ice/LocatorInfo.h>
#include <Ice/Locator.h>
#include <Ice/LocalException.h>
#include <Ice/Instance.h>
#include <Ice/TraceLevels.h>
#include <Ice/LoggerUtil.h>
#include <Ice/EndpointI.h>
#include <Ice/Reference.h>
#include <Ice/Functional.h>
#include <Ice/Properties.h>
#include <Ice/Comparable.h>
#include <iterator>
using namespace std;
using namespace Ice;
using namespace IceInternal;
IceUtil::Shared* IceInternal::upCast(LocatorManager* p) { return p; }
IceUtil::Shared* IceInternal::upCast(LocatorInfo* p) { return p; }
IceUtil::Shared* IceInternal::upCast(LocatorTable* p) { return p; }
namespace
{
class ObjectRequest : public LocatorInfo::Request
{
public:
ObjectRequest(const LocatorInfoPtr& locatorInfo, const ReferencePtr& ref) : LocatorInfo::Request(locatorInfo, ref)
{
assert(ref->isWellKnown());
}
virtual void send()
{
try
{
#ifdef ICE_CPP11_MAPPING
LocatorInfo::RequestPtr request = this;
_locatorInfo->getLocator()->findObjectByIdAsync(
_ref->getIdentity(),
[request](const ObjectPrxPtr& object)
{
request->response(object);
},
[request](exception_ptr e)
{
try
{
rethrow_exception(e);
}
catch(const Exception& ex)
{
request->exception(ex);
}
});
#else
_locatorInfo->getLocator()->begin_findObjectById(
_ref->getIdentity(),
newCallback_Locator_findObjectById(static_cast<LocatorInfo::Request*>(this),
&LocatorInfo::Request::response,
&LocatorInfo::Request::exception));
#endif
}
catch(const Ice::Exception& ex)
{
exception(ex);
}
}
};
class AdapterRequest : public LocatorInfo::Request
{
public:
AdapterRequest(const LocatorInfoPtr& locatorInfo, const ReferencePtr& ref) : LocatorInfo::Request(locatorInfo, ref)
{
assert(ref->isIndirect() && !ref->isWellKnown());
}
virtual void send()
{
try
{
#ifdef ICE_CPP11_MAPPING
LocatorInfo::RequestPtr request = this;
_locatorInfo->getLocator()->findAdapterByIdAsync(_ref->getAdapterId(),
[request](const shared_ptr<Ice::ObjectPrx>& object)
{
request->response(object);
},
[request](exception_ptr e)
{
try
{
rethrow_exception(e);
}
catch(const Exception& ex)
{
request->exception(ex);
}
});
#else
_locatorInfo->getLocator()->begin_findAdapterById(
_ref->getAdapterId(),
newCallback_Locator_findAdapterById(static_cast<LocatorInfo::Request*>(this),
&LocatorInfo::Request::response,
&LocatorInfo::Request::exception));
#endif
}
catch(const Ice::Exception& ex)
{
exception(ex);
}
}
};
}
IceInternal::LocatorManager::LocatorManager(const Ice::PropertiesPtr& properties) :
_background(properties->getPropertyAsInt("Ice.BackgroundLocatorCacheUpdates") > 0),
_tableHint(_table.end())
{
}
void
IceInternal::LocatorManager::destroy()
{
IceUtil::Mutex::Lock sync(*this);
#ifdef ICE_CPP11_MAPPING
for_each(_table.begin(), _table.end(), [](pair<shared_ptr<Ice::LocatorPrx>, LocatorInfoPtr> it){ it.second->destroy(); });
#else
for_each(_table.begin(), _table.end(), Ice::secondVoidMemFun<const LocatorPrx, LocatorInfo>(&LocatorInfo::destroy));
#endif
_table.clear();
_tableHint = _table.end();
_locatorTables.clear();
}
LocatorInfoPtr
IceInternal::LocatorManager::get(const LocatorPrxPtr& loc)
{
if(!loc)
{
return 0;
}
LocatorPrxPtr locator = loc->ice_locator(0); // The locator can't be located.
//
// TODO: reap unused locator info objects?
//
IceUtil::Mutex::Lock sync(*this);
LocatorInfoTable::iterator p = _table.end();
if(_tableHint != _table.end())
{
if(targetEqualTo(_tableHint->first, locator))
{
p = _tableHint;
}
}
if(p == _table.end())
{
p = _table.find(locator);
}
if(p == _table.end())
{
//
// Rely on locator identity for the adapter table. We want to
// have only one table per locator (not one per locator
// proxy).
//
pair<Identity, EncodingVersion> locatorKey(locator->ice_getIdentity(), locator->ice_getEncodingVersion());
map<pair<Identity, EncodingVersion>, LocatorTablePtr>::iterator t = _locatorTables.find(locatorKey);
if(t == _locatorTables.end())
{
t = _locatorTables.insert(_locatorTables.begin(),
pair<const pair<Identity, EncodingVersion>, LocatorTablePtr>(
locatorKey, new LocatorTable()));
}
_tableHint = _table.insert(_tableHint,
pair<const LocatorPrxPtr, LocatorInfoPtr>(locator,
new LocatorInfo(locator, t->second,
_background)));
}
else
{
_tableHint = p;
}
return _tableHint->second;
}
IceInternal::LocatorTable::LocatorTable()
{
}
void
IceInternal::LocatorTable::clear()
{
IceUtil::Mutex::Lock sync(*this);
_adapterEndpointsMap.clear();
_objectMap.clear();
}
bool
IceInternal::LocatorTable::getAdapterEndpoints(const string& adapter, int ttl, vector<EndpointIPtr>& endpoints)
{
if(ttl == 0) // No locator cache.
{
return false;
}
IceUtil::Mutex::Lock sync(*this);
map<string, pair<IceUtil::Time, vector<EndpointIPtr> > >::iterator p = _adapterEndpointsMap.find(adapter);
if(p != _adapterEndpointsMap.end())
{
endpoints = p->second.second;
return checkTTL(p->second.first, ttl);
}
return false;
}
void
IceInternal::LocatorTable::addAdapterEndpoints(const string& adapter, const vector<EndpointIPtr>& endpoints)
{
IceUtil::Mutex::Lock sync(*this);
map<string, pair<IceUtil::Time, vector<EndpointIPtr> > >::iterator p = _adapterEndpointsMap.find(adapter);
if(p != _adapterEndpointsMap.end())
{
p->second = make_pair(IceUtil::Time::now(IceUtil::Time::Monotonic), endpoints);
}
else
{
_adapterEndpointsMap.insert(
make_pair(adapter, make_pair(IceUtil::Time::now(IceUtil::Time::Monotonic), endpoints)));
}
}
vector<EndpointIPtr>
IceInternal::LocatorTable::removeAdapterEndpoints(const string& adapter)
{
IceUtil::Mutex::Lock sync(*this);
map<string, pair<IceUtil::Time, vector<EndpointIPtr> > >::iterator p = _adapterEndpointsMap.find(adapter);
if(p == _adapterEndpointsMap.end())
{
return vector<EndpointIPtr>();
}
vector<EndpointIPtr> endpoints = p->second.second;
_adapterEndpointsMap.erase(p);
return endpoints;
}
bool
IceInternal::LocatorTable::getObjectReference(const Identity& id, int ttl, ReferencePtr& ref)
{
if(ttl == 0) // No locator cache
{
return false;
}
IceUtil::Mutex::Lock sync(*this);
map<Identity, pair<IceUtil::Time, ReferencePtr> >::iterator p = _objectMap.find(id);
if(p != _objectMap.end())
{
ref = p->second.second;
return checkTTL(p->second.first, ttl);
}
return false;
}
void
IceInternal::LocatorTable::addObjectReference(const Identity& id, const ReferencePtr& ref)
{
IceUtil::Mutex::Lock sync(*this);
map<Identity, pair<IceUtil::Time, ReferencePtr> >::iterator p = _objectMap.find(id);
if(p != _objectMap.end())
{
p->second = make_pair(IceUtil::Time::now(IceUtil::Time::Monotonic), ref);
}
else
{
_objectMap.insert(make_pair(id, make_pair(IceUtil::Time::now(IceUtil::Time::Monotonic), ref)));
}
}
ReferencePtr
IceInternal::LocatorTable::removeObjectReference(const Identity& id)
{
IceUtil::Mutex::Lock sync(*this);
map<Identity, pair<IceUtil::Time, ReferencePtr> >::iterator p = _objectMap.find(id);
if(p == _objectMap.end())
{
return 0;
}
ReferencePtr ref = p->second.second;
_objectMap.erase(p);
return ref;
}
bool
IceInternal::LocatorTable::checkTTL(const IceUtil::Time& time, int ttl) const
{
assert(ttl != 0);
if (ttl < 0) // TTL = infinite
{
return true;
}
else
{
return IceUtil::Time::now(IceUtil::Time::Monotonic) - time <= IceUtil::Time::seconds(ttl);
}
}
void
IceInternal::LocatorInfo::RequestCallback::response(const LocatorInfoPtr& locatorInfo, const Ice::ObjectPrxPtr& proxy)
{
vector<EndpointIPtr> endpoints;
if(proxy)
{
ReferencePtr r = proxy->_getReference();
if(_ref->isWellKnown() && !isSupported(_ref->getEncoding(), r->getEncoding()))
{
//
// If a well-known proxy and the returned proxy encoding
// isn't supported, we're done: there's no compatible
// endpoint we can use.
//
}
else if(!r->isIndirect())
{
endpoints = r->getEndpoints();
}
else if(_ref->isWellKnown() && !r->isWellKnown())
{
//
// We're resolving the endpoints of a well-known object and the proxy returned
// by the locator is an indirect proxy. We now need to resolve the endpoints
// of this indirect proxy.
//
locatorInfo->getEndpoints(r, _ref, _ttl, _callback);
return;
}
}
if(_ref->getInstance()->traceLevels()->location >= 1)
{
locatorInfo->getEndpointsTrace(_ref, endpoints, false);
}
if(_callback)
{
_callback->setEndpoints(endpoints, false);
}
}
void
IceInternal::LocatorInfo::RequestCallback::exception(const LocatorInfoPtr& locatorInfo, const Ice::Exception& exc)
{
try
{
locatorInfo->getEndpointsException(_ref, exc); // This throws.
}
catch(const Ice::LocalException& ex)
{
if(_callback)
{
_callback->setException(ex);
}
}
}
IceInternal::LocatorInfo::RequestCallback::RequestCallback(const ReferencePtr& ref,
int ttl,
const GetEndpointsCallbackPtr& cb) :
_ref(ref), _ttl(ttl), _callback(cb)
{
}
void
IceInternal::LocatorInfo::Request::addCallback(const ReferencePtr& ref,
const ReferencePtr& wellKnownRef,
int ttl,
const GetEndpointsCallbackPtr& cb)
{
RequestCallbackPtr callback = new RequestCallback(ref, ttl, cb);
{
IceUtil::Monitor<IceUtil::Mutex>::Lock sync(_monitor);
if(!_response && !_exception)
{
_callbacks.push_back(callback);
if(wellKnownRef) // This request is to resolve the endpoints of a cached well-known object reference
{
_wellKnownRefs.push_back(wellKnownRef);
}
if(!_sent)
{
_sent = true;
sync.release();
send(); // send() might call exception() from this thread so we need to release the mutex.
}
return;
}
}
if(_response)
{
callback->response(_locatorInfo, _proxy);
}
else
{
assert(_exception);
callback->exception(_locatorInfo, *_exception);
}
}
IceInternal::LocatorInfo::Request::Request(const LocatorInfoPtr& locatorInfo, const ReferencePtr& ref) :
_locatorInfo(locatorInfo), _ref(ref), _sent(false), _response(false)
{
}
void
IceInternal::LocatorInfo::Request::response(const Ice::ObjectPrxPtr& proxy)
{
{
IceUtil::Monitor<IceUtil::Mutex>::Lock sync(_monitor);
_locatorInfo->finishRequest(_ref, _wellKnownRefs, proxy, false);
_response = true;
_proxy = proxy;
_monitor.notifyAll();
}
for(vector<RequestCallbackPtr>::const_iterator p = _callbacks.begin(); p != _callbacks.end(); ++p)
{
(*p)->response(_locatorInfo, proxy);
}
}
void
IceInternal::LocatorInfo::Request::exception(const Ice::Exception& ex)
{
{
IceUtil::Monitor<IceUtil::Mutex>::Lock sync(_monitor);
_locatorInfo->finishRequest(_ref, _wellKnownRefs, 0, dynamic_cast<const Ice::UserException*>(&ex));
ICE_SET_EXCEPTION_FROM_CLONE(_exception, ex.ice_clone());
_monitor.notifyAll();
}
for(vector<RequestCallbackPtr>::const_iterator p = _callbacks.begin(); p != _callbacks.end(); ++p)
{
(*p)->exception(_locatorInfo, ex);
}
}
IceInternal::LocatorInfo::LocatorInfo(const LocatorPrxPtr& locator, const LocatorTablePtr& table, bool background) :
_locator(locator),
_table(table),
_background(background)
{
assert(_locator);
assert(_table);
}
void
IceInternal::LocatorInfo::destroy()
{
IceUtil::Mutex::Lock sync(*this);
_locatorRegistry = 0;
_table->clear();
}
bool
IceInternal::LocatorInfo::operator==(const LocatorInfo& rhs) const
{
return Ice::targetEqualTo(_locator, rhs._locator);
}
bool
IceInternal::LocatorInfo::operator<(const LocatorInfo& rhs) const
{
return Ice::targetLess(_locator, rhs._locator);
}
LocatorRegistryPrxPtr
IceInternal::LocatorInfo::getLocatorRegistry()
{
{
IceUtil::Mutex::Lock sync(*this);
if(_locatorRegistry)
{
return _locatorRegistry;
}
}
//
// Do not make locator calls from within sync.
//
LocatorRegistryPrxPtr locatorRegistry = _locator->getRegistry();
if(!locatorRegistry)
{
return 0;
}
{
IceUtil::Mutex::Lock sync(*this);
//
// The locator registry can't be located. We use ordered
// endpoint selection in case the locator returned a proxy
// with some endpoints which are prefered to be tried first.
//
_locatorRegistry = locatorRegistry->ice_locator(0)->ice_endpointSelection(Ice::ICE_ENUM(EndpointSelectionType, Ordered));
return _locatorRegistry;
}
}
void
IceInternal::LocatorInfo::getEndpoints(const ReferencePtr& ref,
const ReferencePtr& wellKnownRef,
int ttl,
const GetEndpointsCallbackPtr& callback)
{
assert(ref->isIndirect());
vector<EndpointIPtr> endpoints;
if(!ref->isWellKnown())
{
if(!_table->getAdapterEndpoints(ref->getAdapterId(), ttl, endpoints))
{
if(_background && !endpoints.empty())
{
getAdapterRequest(ref)->addCallback(ref, wellKnownRef, ttl, 0);
}
else
{
getAdapterRequest(ref)->addCallback(ref, wellKnownRef, ttl, callback);
return;
}
}
}
else
{
ReferencePtr r;
if(!_table->getObjectReference(ref->getIdentity(), ttl, r))
{
if(_background && r)
{
getObjectRequest(ref)->addCallback(ref, 0, ttl, 0);
}
else
{
getObjectRequest(ref)->addCallback(ref, 0, ttl, callback);
return;
}
}
if(!r->isIndirect())
{
endpoints = r->getEndpoints();
}
else if(!r->isWellKnown())
{
getEndpoints(r, ref, ttl, callback);
return;
}
}
assert(!endpoints.empty());
if(ref->getInstance()->traceLevels()->location >= 1)
{
getEndpointsTrace(ref, endpoints, true);
}
if(callback)
{
callback->setEndpoints(endpoints, true);
}
}
void
IceInternal::LocatorInfo::clearCache(const ReferencePtr& ref)
{
assert(ref->isIndirect());
if(!ref->isWellKnown())
{
vector<EndpointIPtr> endpoints = _table->removeAdapterEndpoints(ref->getAdapterId());
if(!endpoints.empty() && ref->getInstance()->traceLevels()->location >= 2)
{
trace("removed endpoints from locator table", ref, endpoints);
}
}
else
{
ReferencePtr r = _table->removeObjectReference(ref->getIdentity());
if(r)
{
if(!r->isIndirect())
{
if(ref->getInstance()->traceLevels()->location >= 2)
{
trace("removed endpoints from locator table", ref, r->getEndpoints());
}
}
else if(!r->isWellKnown())
{
clearCache(r);
}
}
}
}
void
IceInternal::LocatorInfo::getEndpointsException(const ReferencePtr& ref, const Ice::Exception& exc)
{
assert(ref->isIndirect());
try
{
exc.ice_throw();
}
catch(const AdapterNotFoundException&)
{
if(ref->getInstance()->traceLevels()->location >= 1)
{
Trace out(ref->getInstance()->initializationData().logger,
ref->getInstance()->traceLevels()->locationCat);
out << "adapter not found" << "\n";
out << "adapter = " << ref->getAdapterId();
}
NotRegisteredException ex(__FILE__, __LINE__);
ex.kindOfObject = "object adapter";
ex.id = ref->getAdapterId();
throw ex;
}
catch(const ObjectNotFoundException&)
{
if(ref->getInstance()->traceLevels()->location >= 1)
{
Trace out(ref->getInstance()->initializationData().logger,
ref->getInstance()->traceLevels()->locationCat);
out << "object not found" << "\n";
out << "object = " << Ice::identityToString(ref->getIdentity(),
ref->getInstance()->toStringMode());
}
NotRegisteredException ex(__FILE__, __LINE__);
ex.kindOfObject = "object";
ex.id = Ice::identityToString(ref->getIdentity(), ref->getInstance()->toStringMode());
throw ex;
}
catch(const NotRegisteredException&)
{
throw;
}
catch(const LocalException& ex)
{
if(ref->getInstance()->traceLevels()->location >= 1)
{
Trace out(ref->getInstance()->initializationData().logger, ref->getInstance()->traceLevels()->locationCat);
out << "couldn't contact the locator to retrieve adapter endpoints\n";
if(ref->getAdapterId().empty())
{
out << "object = " << Ice::identityToString(ref->getIdentity(), ref->getInstance()->toStringMode())
<< "\n";
}
else
{
out << "adapter = " << ref->getAdapterId() << "\n";
}
out << "reason = " << ex;
}
throw;
}
}
void
IceInternal::LocatorInfo::getEndpointsTrace(const ReferencePtr& ref,
const vector<EndpointIPtr>& endpoints,
bool cached)
{
if(!endpoints.empty())
{
if(cached)
{
trace("found endpoints in locator table", ref, endpoints);
}
else
{
trace("retrieved endpoints from locator, adding to locator table", ref, endpoints);
}
}
else
{
Trace out(ref->getInstance()->initializationData().logger, ref->getInstance()->traceLevels()->locationCat);
out << "no endpoints configured for ";
if(ref->getAdapterId().empty())
{
out << "object\n";
out << "object = " << Ice::identityToString(ref->getIdentity(), ref->getInstance()->toStringMode());
}
else
{
out << "adapter\n";
out << "adapter = " << ref->getAdapterId();
}
}
}
void
IceInternal::LocatorInfo::trace(const string& msg, const ReferencePtr& ref, const vector<EndpointIPtr>& endpoints)
{
assert(ref->isIndirect());
Trace out(ref->getInstance()->initializationData().logger, ref->getInstance()->traceLevels()->locationCat);
out << msg << '\n';
if(!ref->isWellKnown())
{
out << "adapter = " << ref->getAdapterId() << '\n';
}
else
{
out << "object = " << Ice::identityToString(ref->getIdentity(), ref->getInstance()->toStringMode())
<< '\n';
}
const char* sep = endpoints.size() > 1 ? ":" : "";
ostringstream o;
transform(endpoints.begin(), endpoints.end(), ostream_iterator<string>(o, sep),
Ice::constMemFun(&Endpoint::toString));
out << "endpoints = " << o.str();
}
IceInternal::LocatorInfo::RequestPtr
IceInternal::LocatorInfo::getAdapterRequest(const ReferencePtr& ref)
{
IceUtil::Mutex::Lock sync(*this);
if(ref->getInstance()->traceLevels()->location >= 1)
{
Trace out(ref->getInstance()->initializationData().logger, ref->getInstance()->traceLevels()->locationCat);
out << "searching for adapter by id\nadapter = " << ref->getAdapterId();
}
map<string, RequestPtr>::const_iterator p = _adapterRequests.find(ref->getAdapterId());
if(p != _adapterRequests.end())
{
return p->second;
}
RequestPtr request = new AdapterRequest(this, ref);
_adapterRequests.insert(make_pair(ref->getAdapterId(), request));
return request;
}
IceInternal::LocatorInfo::RequestPtr
IceInternal::LocatorInfo::getObjectRequest(const ReferencePtr& ref)
{
IceUtil::Mutex::Lock sync(*this);
if(ref->getInstance()->traceLevels()->location >= 1)
{
Trace out(ref->getInstance()->initializationData().logger, ref->getInstance()->traceLevels()->locationCat);
out << "searching for object by id\nobject = " << Ice::identityToString(ref->getIdentity(),
ref->getInstance()->toStringMode());
}
map<Ice::Identity, RequestPtr>::const_iterator p = _objectRequests.find(ref->getIdentity());
if(p != _objectRequests.end())
{
return p->second;
}
RequestPtr request = new ObjectRequest(this, ref);
_objectRequests.insert(make_pair(ref->getIdentity(), request));
return request;
}
void
IceInternal::LocatorInfo::finishRequest(const ReferencePtr& ref,
const vector<ReferencePtr>& wellKnownRefs,
const Ice::ObjectPrxPtr& proxy,
bool notRegistered)
{
if(!proxy || proxy->_getReference()->isIndirect())
{
//
// Remove the cached references of well-known objects for which we tried
// to resolved the endpoints if these endpoints are empty.
//
for(vector<ReferencePtr>::const_iterator q = wellKnownRefs.begin(); q != wellKnownRefs.end(); ++q)
{
_table->removeObjectReference((*q)->getIdentity());
}
}
if(!ref->isWellKnown())
{
if(proxy && !proxy->_getReference()->isIndirect()) // Cache the adapter endpoints.
{
_table->addAdapterEndpoints(ref->getAdapterId(), proxy->_getReference()->getEndpoints());
}
else if(notRegistered) // If the adapter isn't registered anymore, remove it from the cache.
{
_table->removeAdapterEndpoints(ref->getAdapterId());
}
IceUtil::Mutex::Lock sync(*this);
assert(_adapterRequests.find(ref->getAdapterId()) != _adapterRequests.end());
_adapterRequests.erase(ref->getAdapterId());
}
else
{
if(proxy && !proxy->_getReference()->isWellKnown()) // Cache the well-known object reference.
{
_table->addObjectReference(ref->getIdentity(), proxy->_getReference());
}
else if(notRegistered) // If the well-known object isn't registered anymore, remove it from the cache.
{
_table->removeObjectReference(ref->getIdentity());
}
IceUtil::Mutex::Lock sync(*this);
assert(_objectRequests.find(ref->getIdentity()) != _objectRequests.end());
_objectRequests.erase(ref->getIdentity());
}
}
|