UNPKG

3.27 kBTypeScriptView Raw
1import { Subchannel } from './subchannel';
2import { StatusObject } from './call-stream';
3import { Metadata } from './metadata';
4import { LoadBalancer } from './load-balancer';
5import { FilterFactory, Filter } from './filter';
6export declare enum PickResultType {
7 COMPLETE = 0,
8 QUEUE = 1,
9 TRANSIENT_FAILURE = 2,
10 DROP = 3
11}
12export interface PickResult {
13 pickResultType: PickResultType;
14 /**
15 * The subchannel to use as the transport for the call. Only meaningful if
16 * `pickResultType` is COMPLETE. If null, indicates that the call should be
17 * dropped.
18 */
19 subchannel: Subchannel | null;
20 /**
21 * The status object to end the call with. Populated if and only if
22 * `pickResultType` is TRANSIENT_FAILURE.
23 */
24 status: StatusObject | null;
25 /**
26 * Extra FilterFactory (can be multiple encapsulated in a FilterStackFactory)
27 * provided by the load balancer to be used with the call. For technical
28 * reasons filters from this factory will not see sendMetadata events.
29 */
30 extraFilterFactories: FilterFactory<Filter>[];
31 onCallStarted: (() => void) | null;
32}
33export interface CompletePickResult extends PickResult {
34 pickResultType: PickResultType.COMPLETE;
35 subchannel: Subchannel | null;
36 status: null;
37 extraFilterFactories: FilterFactory<Filter>[];
38 onCallStarted: (() => void) | null;
39}
40export interface QueuePickResult extends PickResult {
41 pickResultType: PickResultType.QUEUE;
42 subchannel: null;
43 status: null;
44 extraFilterFactories: [];
45 onCallStarted: null;
46}
47export interface TransientFailurePickResult extends PickResult {
48 pickResultType: PickResultType.TRANSIENT_FAILURE;
49 subchannel: null;
50 status: StatusObject;
51 extraFilterFactories: [];
52 onCallStarted: null;
53}
54export interface DropCallPickResult extends PickResult {
55 pickResultType: PickResultType.DROP;
56 subchannel: null;
57 status: StatusObject;
58 extraFilterFactories: [];
59 onCallStarted: null;
60}
61export interface PickArgs {
62 metadata: Metadata;
63 extraPickInfo: {
64 [key: string]: string;
65 };
66}
67/**
68 * A proxy object representing the momentary state of a load balancer. Picks
69 * subchannels or returns other information based on that state. Should be
70 * replaced every time the load balancer changes state.
71 */
72export interface Picker {
73 pick(pickArgs: PickArgs): PickResult;
74}
75/**
76 * A standard picker representing a load balancer in the TRANSIENT_FAILURE
77 * state. Always responds to every pick request with an UNAVAILABLE status.
78 */
79export declare class UnavailablePicker implements Picker {
80 private status;
81 constructor(status?: StatusObject);
82 pick(pickArgs: PickArgs): TransientFailurePickResult;
83}
84/**
85 * A standard picker representing a load balancer in the IDLE or CONNECTING
86 * state. Always responds to every pick request with a QUEUE pick result
87 * indicating that the pick should be tried again with the next `Picker`. Also
88 * reports back to the load balancer that a connection should be established
89 * once any pick is attempted.
90 */
91export declare class QueuePicker {
92 private loadBalancer;
93 private calledExitIdle;
94 constructor(loadBalancer: LoadBalancer);
95 pick(pickArgs: PickArgs): QueuePickResult;
96}
97
\No newline at end of file