Press n or j to go to the next uncovered block, b, p or k for the previous block.
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 | 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 67x 67x 67x 67x 67x 67x 67x 67x 67x 67x 67x 67x 41x 41x 65x 65x 65x 65x 65x 65x 65x 65x 65x 41x 41x 65x 65x 65x 65x 41x 41x 41x 41x 41x 1579x 1579x 1579x 1579x 1579x 1579x 1579x 1579x 1260x 1260x 1579x 319x 319x 1579x 41x 41x 4x 4x 4x 4x 4x 4x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 6x 4x 4x 2x 2x 4x 4x 41x 41x 26x 14x 14x 12x 22x 3x 3x 12x 26x 41x 41x 6x 6x 6x 12x 12x 12x 12x 6x 6x 6x 6x 41x 41x 2x 2x 41x 41x 2x 2x 41x 41x 1898x 1898x 1898x 1898x 1898x 2053x 2053x 2053x 2053x 2053x 2053x 787x 787x 1266x 1266x 1266x 1260x 1260x 1260x 1266x 6x 638x 638x 1898x 41x 41x 319x 319x 319x 319x 319x 319x 319x 319x 319x 319x 319x 41x 41x 319x 319x 319x 319x 41x 41x 319x 319x 319x 319x 319x 319x 319x 318x 318x 318x 318x 319x 319x 319x 41x 41x 335x 335x 335x 335x 335x 335x 335x 335x 335x 335x 335x 335x 335x 335x 335x 335x 335x 335x 335x 335x 335x 335x 335x 335x 335x 335x 41x 41x 335x 335x 335x 41x 41x 243x 243x 243x 243x 243x 243x 243x 243x 243x 303x 303x 303x 303x 1x 1x 1x 1x 1x 303x 303x 243x 243x 243x 244x 244x 244x 243x 243x 243x 243x 243x 243x 243x 243x 243x 41x 41x 75x 75x 75x 75x 75x 75x 75x 75x 75x 79x 79x 79x 79x 79x 79x 75x 75x 75x 75x 75x 75x 75x 75x 41x 41x 319x 319x 319x 319x 319x 383x 383x 1x 1x 1x 1x 1x 319x 319x 319x 1x 1x 318x 318x 318x 318x 382x 382x 382x 318x 318x 318x 319x 41x 41x 244x 244x 304x 304x 244x 244x 41x 41x 92x 92x 56x 56x 56x 56x 44x 56x 12x 12x 56x 56x 56x 92x 41x 41x 448x 448x 448x 448x 383x 383x 65x 65x 65x 114x 114x 114x 65x 65x 65x 65x 65x 448x 41x 41x 41x 41x 41x 41x 41x 67x 67x 41x 41x 670x 670x 666x 666x 666x 670x 670x 670x 670x 41x 41x 670x 670x 670x 670x 670x 670x 666x 666x 670x 41x 41x 71x 71x 71x 71x 41x 41x 150x 268x 268x 150x 41x 41x 41x 41x 319x 319x 319x 319x 319x 319x 319x 41x 41x 41x 41x 41x 243x 243x 243x 41x 41x 92x 92x 17x 17x 92x 41x 41x 244x 244x 244x 244x 244x 244x 244x 41x 41x 75x 75x 75x 75x 75x 75x 41x 41x 1x 1x 41x 41x 1x 1x 41x 41x 41x 41x 244x 244x 41x 41x 319x 319x 319x 319x 319x 319x 319x 319x 319x 319x 319x 319x 41x 41x 319x 319x 319x 319x 319x 319x 319x 319x 41x 41x 335x 335x 335x 243x 335x 335x 92x 335x 335x 335x 335x 335x 335x 335x 335x 335x 335x 335x 241x 241x 241x 241x 241x 241x 241x 335x 335x 335x 335x 335x 335x 41x 41x 92x 92x 92x 92x 92x 92x 17x 92x 17x 17x 75x 75x 75x 92x 41x | // Copyright (c) ZeroC, Inc. import { ConnectionI } from "./ConnectionI.js"; import { HashMap } from "./HashMap.js"; import { Promise } from "./Promise.js"; import { LocalException } from "./LocalException.js"; import { CommunicatorDestroyedException } from "./LocalExceptions.js"; import { ConnectTimeoutException } from "./LocalExceptions.js"; // // Only for use by Instance. // export class OutgoingConnectionFactory { constructor(communicator, instance) { this._communicator = communicator; this._instance = instance; this._destroyed = false; this._defaultObjectAdapter = null; this._connectionOptions = instance.clientConnectionOptions; this._connectionsByEndpoint = new ConnectionListMap(); // map<EndpointI, Array<Ice.ConnectionI>> this._pending = new HashMap(HashMap.compareEquals); // map<EndpointI, Array<ConnectCallback>> this._pendingConnectCount = 0; this._waitPromise = null; } destroy() { if (this._destroyed) { return; } this._connectionsByEndpoint.forEach(connection => connection.destroy()); this._destroyed = true; this._communicator = null; this._defaultObjectAdapter = null; this.checkFinished(); } waitUntilFinished() { this._waitPromise = new Promise(); this.checkFinished(); return this._waitPromise; } // // Returns a promise, success callback receives the connection // create(endpoints, hasMore) { console.assert(endpoints.length > 0); // // Try to find a connection to one of the given endpoints. // try { const connection = this.findConnectionByEndpoint(endpoints); if (connection !== null) { return Promise.resolve(connection); } } catch (ex) { return Promise.reject(ex); } return new ConnectCallback(this, endpoints, hasMore).start(); } setRouterInfo(routerInfo) { return Promise.resolve() .then(() => { if (this._destroyed) { throw new CommunicatorDestroyedException(); } return routerInfo.getClientEndpoints(); }) .then(endpoints => { // // Search for connections to the router's client proxy // endpoints, and update the object adapter for such // connections, so that callbacks from the router can be // received over such connections. // const adapter = routerInfo.getAdapter(); endpoints.forEach(endpoint => { // // The Connection object does not take the compression flag of // endpoints into account, but instead gets the information // about whether messages should be compressed or not from // other sources. In order to allow connection sharing for // endpoints that differ in the value of the compression flag // only, we always set the compression flag to false here in // this connection factory. We also clear the timeout as it is // no longer used for Ice 3.8. // endpoint = endpoint.changeCompress(false).changeTimeout(-1); this._connectionsByEndpoint.forEach(connection => { if (connection.endpoint().equals(endpoint)) { connection.setAdapter(adapter); } }); }); }); } removeAdapter(adapter) { if (this._destroyed) { return; } this._connectionsByEndpoint.forEach(connection => { if (connection.getAdapter() === adapter) { connection.setAdapter(null); } }); } async flushAsyncBatchRequests() { if (!this._destroyed) { await Promise.all( this._connectionsByEndpoint.map(connection => { if (connection.isActiveOrHolding()) { return connection.flushBatchRequests().catch(ex => { if (ex instanceof LocalException) { // Ignore } else { throw ex; } }); } }), ); } } getDefaultObjectAdapter() { return this._defaultObjectAdapter; } setDefaultObjectAdapter(adapter) { this._defaultObjectAdapter = adapter; } findConnectionByEndpoint(endpoints) { if (this._destroyed) { throw new CommunicatorDestroyedException(); } console.assert(endpoints.length > 0); for (const endpoint of endpoints) { const proxyEndpoint = endpoint.changeTimeout(-1); if (this._pending.has(proxyEndpoint)) { continue; } const connectionList = this._connectionsByEndpoint.get(proxyEndpoint); if (connectionList === undefined) { continue; } for (let j = 0; j < connectionList.length; ++j) { if (connectionList[j].isActiveOrHolding()) { // Don't return destroyed or un-validated connections return connectionList[j]; } } } return null; } incPendingConnectCount() { // // Keep track of the number of pending connects. The outgoing connection factory // waitUntilFinished() method waits for all the pending connects to terminate before // to return. This ensures that the communicator client thread pool isn't destroyed // too soon and will still be available to execute the ice_exception() callbacks for // the asynchronous requests waiting on a connection to be established. // if (this._destroyed) { throw new CommunicatorDestroyedException(); } ++this._pendingConnectCount; } decPendingConnectCount() { --this._pendingConnectCount; console.assert(this._pendingConnectCount >= 0); if (this._destroyed && this._pendingConnectCount === 0) { this.checkFinished(); } } getConnection(endpoints, cb) { if (this._destroyed) { throw new CommunicatorDestroyedException(); } // Search for an existing connections matching one of the given endpoints. const connection = this.findConnectionByEndpoint(endpoints); if (connection !== null) { return connection; } if (!this.addToPending(cb, endpoints)) { // No connection is currently pending to one of our endpoints, call nextEndpoint to start the connection // establishment. cb.nextEndpoint(); } // Return null to indicate to the caller that the connection is being established. return null; } createConnection(transceiver, endpoint) { console.assert(this._pending.has(endpoint) && transceiver !== null); // // Create and add the connection to the connection map. Adding the connection to the map // is necessary to support the interruption of the connection initialization and validation // in case the communicator is destroyed. // let connection = null; try { if (this._destroyed) { throw new CommunicatorDestroyedException(); } connection = new ConnectionI( this._communicator, this._instance, transceiver, endpoint.changeCompress(false).changeTimeout(-1), this._defaultObjectAdapter, connection => this.removeConnection(connection), this._connectionOptions, ); } catch (ex) { console.assert(ex instanceof LocalException); transceiver.close(); throw ex; } this._connectionsByEndpoint.set(connection.endpoint(), connection); this._connectionsByEndpoint.set(connection.endpoint().changeCompress(true), connection); return connection; } removeConnection(connection) { this._connectionsByEndpoint.removeConnection(connection.endpoint(), connection); this._connectionsByEndpoint.removeConnection(connection.endpoint().changeCompress(true), connection); } finishGetConnection(endpoints, endpoint, connection, cb) { // cb is-a ConnectCallback const connectionCallbacks = []; if (cb !== null) { connectionCallbacks.push(cb); } const callbacks = []; endpoints.forEach(endpt => { const cbs = this._pending.get(endpt); if (cbs !== undefined) { this._pending.delete(endpt); cbs.forEach(cc => { if (cc.hasEndpoint(endpoint)) { if (connectionCallbacks.indexOf(cc) === -1) { connectionCallbacks.push(cc); } } else if (callbacks.indexOf(cc) === -1) { callbacks.push(cc); } }); } }); connectionCallbacks.forEach(cc => { cc.removeFromPending(); const idx = callbacks.indexOf(cc); if (idx !== -1) { callbacks.splice(idx, 1); } }); callbacks.forEach(cc => cc.removeFromPending()); callbacks.forEach(cc => cc.getConnection()); connectionCallbacks.forEach(cc => cc.setConnection(connection)); this.checkFinished(); } finishGetConnectionEx(endpoints, ex, cb) { // cb is-a ConnectCallback const failedCallbacks = []; if (cb !== null) { failedCallbacks.push(cb); } const callbacks = []; endpoints.forEach(endpt => { const cbs = this._pending.get(endpt); if (cbs !== undefined) { this._pending.delete(endpt); cbs.forEach(cc => { if (cc.removeEndpoints(endpoints)) { if (failedCallbacks.indexOf(cc) === -1) { failedCallbacks.push(cc); } } else if (callbacks.indexOf(cc) === -1) { callbacks.push(cc); } }); } }); callbacks.forEach(cc => { console.assert(failedCallbacks.indexOf(cc) === -1); cc.removeFromPending(); }); this.checkFinished(); callbacks.forEach(cc => cc.getConnection()); failedCallbacks.forEach(cc => cc.setException(ex)); } addToPending(cb, endpoints) { console.assert(cb !== null); // Add the callback to each pending list. let found = false; endpoints.forEach(p => { const cbs = this._pending.get(p); if (cbs !== undefined) { found = true; if (cbs.indexOf(cb) === -1) { cbs.push(cb); // Add the callback to each pending endpoint. } } }); if (found) { return true; } // If there's no pending connection for the given endpoints, we're responsible for its establishment. We add an // empty pending lists, other callbacks to the same endpoints will be queued. endpoints.forEach(p => { if (!this._pending.has(p)) { this._pending.set(p, []); } }); return false; } removeFromPending(cb, endpoints) { // cb is-a ConnectCallback endpoints.forEach(p => { const cbs = this._pending.get(p); if (cbs !== undefined) { const idx = cbs.indexOf(cb); if (idx !== -1) { cbs.splice(idx, 1); } } }); } handleConnectionException(ex, hasMore) { const traceLevels = this._instance.traceLevels(); if (traceLevels.network >= 2) { const s = []; s.push("connection to endpoint failed"); if (ex instanceof CommunicatorDestroyedException) { s.push("\n"); } else if (hasMore) { s.push(", trying next endpoint\n"); } else { s.push(" and no more endpoints to try\n"); } s.push(ex.toString()); this._instance.initializationData().logger.trace(traceLevels.networkCat, s.join("")); } } async checkFinished() { // // Can't continue until the factory is destroyed and there are no pending connections. // if (!this._waitPromise || !this._destroyed || this._pending.size > 0 || this._pendingConnectCount > 0) { return; } await Promise.all( this._connectionsByEndpoint.map(async connection => { try { await connection.waitUntilFinished(); } catch (ex) { console.assert(false, ex); } }), ); console.assert(this._waitPromise !== null); this._waitPromise.resolve(); } } // // Value is a Vector<Ice.ConnectionI> // class ConnectionListMap extends HashMap { constructor(h) { super(h || HashMap.compareEquals); } set(key, value) { let list = this.get(key); if (list === undefined) { list = []; super.set(key, list); } console.assert(value instanceof ConnectionI); list.push(value); return undefined; } removeConnection(key, conn) { const list = this.get(key); console.assert(list !== null); const idx = list.indexOf(conn); console.assert(idx !== -1); list.splice(idx, 1); if (list.length === 0) { this.delete(key); } } map(fn) { const arr = []; this.forEach(c => arr.push(fn(c))); return arr; } forEach(fn) { for (const connections of this.values()) { connections.forEach(fn); } } } class ConnectCallback { constructor(f, endpoints, more) { this._factory = f; this._endpoints = endpoints; this._hasMore = more; this._promise = new Promise(); this._index = 0; this._current = null; } // // Methods from ConnectionI_StartCallback // connectionStartCompleted(connection) { connection.activate(); this._factory.finishGetConnection(this._endpoints, this._current, connection, this); } connectionStartFailed(ex) { console.assert(this._current !== null); if (this.connectionStartFailedImpl(ex)) { this.nextEndpoint(); } } setConnection(connection) { // // Callback from the factory: the connection to one of the callback // connectors has been established. // this._promise.resolve(connection); this._factory.decPendingConnectCount(); // Must be called last. } setException(ex) { // // Callback from the factory: connection establishment failed. // this._promise.reject(ex); this._factory.decPendingConnectCount(); // Must be called last. } hasEndpoint(endpoint) { return this.findEndpoint(endpoint) !== -1; } findEndpoint(endpoint) { return this._endpoints.findIndex(value => endpoint.equals(value)); } removeEndpoints(endpoints) { endpoints.forEach(endpoint => { const idx = this.findEndpoint(endpoint); if (idx !== -1) { this._endpoints.splice(idx, 1); } }); this._index = 0; return this._endpoints.length === 0; } removeFromPending() { this._factory.removeFromPending(this, this._endpoints); } start() { try { // // Notify the factory that there's an async connect pending. This is necessary // to prevent the outgoing connection factory to be destroyed before all the // pending asynchronous connects are finished. // this._factory.incPendingConnectCount(); } catch (ex) { this._promise.reject(ex); return; } this.getConnection(); return this._promise; } getConnection() { try { const connection = this._factory.getConnection(this._endpoints, this); if (connection === null) { // A null return value from getConnection indicates that the connection is being established, and the // callback will be notified when the connection establishment is done. return; } this._promise.resolve(connection); this._factory.decPendingConnectCount(); // Must be called last. } catch (ex) { this._promise.reject(ex); this._factory.decPendingConnectCount(); // Must be called last. } } nextEndpoint() { const start = connection => { connection.start().then( () => { this.connectionStartCompleted(connection); }, ex => { this.connectionStartFailed(ex); }, ); }; while (true) { const traceLevels = this._factory._instance.traceLevels(); try { console.assert(this._index < this._endpoints.length); this._current = this._endpoints[this._index++]; if (traceLevels.network >= 2) { const s = []; s.push("trying to establish "); s.push(this._current.protocol()); s.push(" connection to "); s.push(this._current.toConnectorString()); this._factory._instance.initializationData().logger.trace(traceLevels.networkCat, s.join("")); } start(this._factory.createConnection(this._current.connect(), this._current)); } catch (ex) { if (traceLevels.network >= 2) { const s = []; s.push("failed to establish "); s.push(this._current.protocol()); s.push(" connection to "); s.push(this._current.toString()); s.push("\n"); s.push(ex.toString()); this._factory._instance.initializationData().logger.trace(traceLevels.networkCat, s.join("")); } if (this.connectionStartFailedImpl(ex)) { continue; } } break; } } connectionStartFailedImpl(ex) { this._factory.handleConnectionException(ex, this._hasMore || this._index < this._endpoints.length); // We stop on ConnectTimeoutException to fail reasonably fast when the endpoint has many connectors // (IP addresses). if ( this._index < this._endpoints.length && !(ex instanceof CommunicatorDestroyedException || ex instanceof ConnectTimeoutException) ) { return true; // keep going } this._factory.finishGetConnectionEx(this._endpoints, ex, this); return false; } } |