subchannel-interface.js 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. "use strict";
  2. /*
  3. * Copyright 2022 gRPC authors.
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. *
  17. */
  18. Object.defineProperty(exports, "__esModule", { value: true });
  19. exports.BaseSubchannelWrapper = void 0;
  20. class BaseSubchannelWrapper {
  21. constructor(child) {
  22. this.child = child;
  23. this.healthy = true;
  24. this.healthListeners = new Set();
  25. child.addHealthStateWatcher(childHealthy => {
  26. /* A change to the child health state only affects this wrapper's overall
  27. * health state if this wrapper is reporting healthy. */
  28. if (this.healthy) {
  29. this.updateHealthListeners();
  30. }
  31. });
  32. }
  33. updateHealthListeners() {
  34. for (const listener of this.healthListeners) {
  35. listener(this.isHealthy());
  36. }
  37. }
  38. getConnectivityState() {
  39. return this.child.getConnectivityState();
  40. }
  41. addConnectivityStateListener(listener) {
  42. this.child.addConnectivityStateListener(listener);
  43. }
  44. removeConnectivityStateListener(listener) {
  45. this.child.removeConnectivityStateListener(listener);
  46. }
  47. startConnecting() {
  48. this.child.startConnecting();
  49. }
  50. getAddress() {
  51. return this.child.getAddress();
  52. }
  53. throttleKeepalive(newKeepaliveTime) {
  54. this.child.throttleKeepalive(newKeepaliveTime);
  55. }
  56. ref() {
  57. this.child.ref();
  58. }
  59. unref() {
  60. this.child.unref();
  61. }
  62. getChannelzRef() {
  63. return this.child.getChannelzRef();
  64. }
  65. isHealthy() {
  66. return this.healthy && this.child.isHealthy();
  67. }
  68. addHealthStateWatcher(listener) {
  69. this.healthListeners.add(listener);
  70. }
  71. removeHealthStateWatcher(listener) {
  72. this.healthListeners.delete(listener);
  73. }
  74. setHealthy(healthy) {
  75. if (healthy !== this.healthy) {
  76. this.healthy = healthy;
  77. /* A change to this wrapper's health state only affects the overall
  78. * reported health state if the child is healthy. */
  79. if (this.child.isHealthy()) {
  80. this.updateHealthListeners();
  81. }
  82. }
  83. }
  84. getRealSubchannel() {
  85. return this.child.getRealSubchannel();
  86. }
  87. realSubchannelEquals(other) {
  88. return this.getRealSubchannel() === other.getRealSubchannel();
  89. }
  90. }
  91. exports.BaseSubchannelWrapper = BaseSubchannelWrapper;
  92. //# sourceMappingURL=subchannel-interface.js.map