UNPKG

3.53 kBTypeScriptView Raw
1/// <reference types="node" />
2import { CallCredentials } from "./call-credentials";
3import { Status } from "./constants";
4import { Deadline } from "./deadline";
5import { Metadata } from "./metadata";
6import { CallConfig } from "./resolver";
7import { Call, InterceptingListener, MessageContext } from "./call-interface";
8import { InternalChannel } from "./internal-channel";
9export declare class RetryThrottler {
10 private readonly maxTokens;
11 private readonly tokenRatio;
12 private tokens;
13 constructor(maxTokens: number, tokenRatio: number, previousRetryThrottler?: RetryThrottler);
14 addCallSucceeded(): void;
15 addCallFailed(): void;
16 canRetryCall(): boolean;
17}
18export declare class MessageBufferTracker {
19 private totalLimit;
20 private limitPerCall;
21 private totalAllocated;
22 private allocatedPerCall;
23 constructor(totalLimit: number, limitPerCall: number);
24 allocate(size: number, callId: number): boolean;
25 free(size: number, callId: number): void;
26 freeAll(callId: number): void;
27}
28export declare class RetryingCall implements Call {
29 private readonly channel;
30 private readonly callConfig;
31 private readonly methodName;
32 private readonly host;
33 private readonly credentials;
34 private readonly deadline;
35 private readonly callNumber;
36 private readonly bufferTracker;
37 private readonly retryThrottler?;
38 private state;
39 private listener;
40 private initialMetadata;
41 private underlyingCalls;
42 private writeBuffer;
43 /**
44 * The offset of message indices in the writeBuffer. For example, if
45 * writeBufferOffset is 10, message 10 is in writeBuffer[0] and message 15
46 * is in writeBuffer[5].
47 */
48 private writeBufferOffset;
49 /**
50 * Tracks whether a read has been started, so that we know whether to start
51 * reads on new child calls. This only matters for the first read, because
52 * once a message comes in the child call becomes committed and there will
53 * be no new child calls.
54 */
55 private readStarted;
56 private transparentRetryUsed;
57 /**
58 * Number of attempts so far
59 */
60 private attempts;
61 private hedgingTimer;
62 private committedCallIndex;
63 private initialRetryBackoffSec;
64 private nextRetryBackoffSec;
65 constructor(channel: InternalChannel, callConfig: CallConfig, methodName: string, host: string, credentials: CallCredentials, deadline: Deadline, callNumber: number, bufferTracker: MessageBufferTracker, retryThrottler?: RetryThrottler | undefined);
66 getCallNumber(): number;
67 private trace;
68 private reportStatus;
69 cancelWithStatus(status: Status, details: string): void;
70 getPeer(): string;
71 private getBufferEntry;
72 private getNextBufferIndex;
73 private clearSentMessages;
74 private commitCall;
75 private commitCallWithMostMessages;
76 private isStatusCodeInList;
77 private getNextRetryBackoffMs;
78 private maybeRetryCall;
79 private countActiveCalls;
80 private handleProcessedStatus;
81 private getPushback;
82 private handleChildStatus;
83 private maybeStartHedgingAttempt;
84 private maybeStartHedgingTimer;
85 private startNewAttempt;
86 start(metadata: Metadata, listener: InterceptingListener): void;
87 private handleChildWriteCompleted;
88 private sendNextChildMessage;
89 sendMessageWithContext(context: MessageContext, message: Buffer): void;
90 startRead(): void;
91 halfClose(): void;
92 setCredentials(newCredentials: CallCredentials): void;
93 getMethod(): string;
94 getHost(): string;
95}