PoolCluster.d.ts 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import Connection = require('./Connection');
  2. import PoolConnection = require('./PoolConnection');
  3. import {EventEmitter} from 'events';
  4. declare namespace PoolCluster {
  5. export interface PoolClusterOptions {
  6. /**
  7. * If true, PoolCluster will attempt to reconnect when connection fails. (Default: true)
  8. */
  9. canRetry?: boolean;
  10. /**
  11. * If connection fails, node's errorCount increases. When errorCount is greater than removeNodeErrorCount,
  12. * remove a node in the PoolCluster. (Default: 5)
  13. */
  14. removeNodeErrorCount?: number;
  15. /**
  16. * If connection fails, specifies the number of milliseconds before another connection attempt will be made.
  17. * If set to 0, then node will be removed instead and never re-used. (Default: 0)
  18. */
  19. restoreNodeTimeout?: number;
  20. /**
  21. * The default selector. (Default: RR)
  22. * RR: Select one alternately. (Round-Robin)
  23. * RANDOM: Select the node by random function.
  24. * ORDER: Select the first node available unconditionally.
  25. */
  26. defaultSelector?: string;
  27. }
  28. }
  29. declare class PoolCluster extends EventEmitter {
  30. config: PoolCluster.PoolClusterOptions;
  31. add(config: PoolCluster.PoolClusterOptions): void;
  32. add(group: string, config: PoolCluster.PoolClusterOptions): void;
  33. end(): void;
  34. getConnection(callback: (err: NodeJS.ErrnoException | null, connection: PoolConnection) => void): void;
  35. getConnection(group: string, callback: (err: NodeJS.ErrnoException | null, connection: PoolConnection) => void): void;
  36. getConnection(group: string, selector: string, callback: (err: NodeJS.ErrnoException | null, connection: PoolConnection) => void): void;
  37. of(pattern: string, selector?: string): PoolCluster;
  38. on(event: string, listener: Function): this;
  39. on(event: 'remove', listener: (nodeId: number) => void): this;
  40. on(event: 'connection', listener: (connection: PoolConnection) => void): this;
  41. }
  42. export = PoolCluster;