import * as http from 'http';
import * as https from 'https';
import * as express from 'express';
import * as yargs from 'yargs';
import { type interfaces } from 'inversify';
import { ContributionProvider, MaybePromise, Stopwatch } from '../common';
import { CliContribution } from './cli';
import { AddressInfo } from 'net';
import { ProcessUtils } from './process-utils';
/**
 * The path to the application project directory. This is the directory where the application code is located.
 * Mostly contains the `package.json` file and the `lib` directory.
 */
export declare const BackendApplicationPath: string;
/**
 * Private injection token for the backend's root Inversify {@link Container}.
 */
export declare const RootContainer: unique symbol;
export type DnsResultOrder = 'ipv4first' | 'verbatim' | 'nodeDefault';
export declare const BackendApplicationServer: unique symbol;
/**
 * This service is responsible for serving the frontend files.
 *
 * When not bound, `@theia/cli` generators will bind it on the fly to serve files according to its own layout.
 */
export interface BackendApplicationServer extends BackendApplicationContribution {
}
export declare const BackendApplicationContribution: unique symbol;
/**
 * Contribution for hooking into the backend lifecycle:
 *
 * - `initialize()`
 * - `configure(expressApp)`
 * - `onStart(httpServer)`
 * - `onStop()`
 */
export interface BackendApplicationContribution {
    /**
     * Called during the initialization of the backend application.
     * Use this for functionality which has to run as early as possible.
     *
     * The implementation may be async, however it will still block the
     * initialization step until it's resolved.
     *
     * @returns either `undefined` or a Promise resolving to `undefined`.
     */
    initialize?(): MaybePromise<void>;
    /**
     * Called after the initialization of the backend application is complete.
     * Use this to configure the Express app before it is started, for example
     * to offer additional endpoints.
     *
     * The implementation may be async, however it will still block the
     * configuration step until it's resolved.
     *
     * @param app the express application to configure.
     *
     * @returns either `undefined` or a Promise resolving to `undefined`.
     */
    configure?(app: express.Application): MaybePromise<void>;
    /**
     * Called right after the server for the Express app is started.
     * Use this to additionally configure the server or as ready-signal for your service.
     *
     * The implementation may be async, however it will still block the
     * startup step until it's resolved.
     *
     * @param server the backend server running the express app.
     *
     * @returns either `undefined` or a Promise resolving to `undefined`.
     */
    onStart?(server: http.Server | https.Server): MaybePromise<void>;
    /**
     * Called when the backend application shuts down.
     *
     * When shutdown is initiated via `SIGINT`/`SIGTERM`, contributions are dispatched
     * in parallel and any returned promise is awaited up to `SHUTDOWN_TIMEOUT_MS`
     * milliseconds while injected services from the root container are still
     * resolvable.
     *
     * On synchronous-exit fallback paths (uncaught exceptions, server bind failures,
     * or normal process exit), the hook is invoked synchronously and any returned
     * promise is discarded. Implementations should be resilient to either path.
     *
     * Contributions must be independent of one another during stop because they are
     * dispatched in parallel.
     *
     * @param app the express application.
     */
    onStop?(app?: express.Application): MaybePromise<void>;
}
export declare class BackendApplicationCliContribution implements CliContribution {
    port: number;
    hostname: string | undefined;
    dnsDefaultResultOrder: DnsResultOrder;
    ssl: boolean | undefined;
    cert: string | undefined;
    certkey: string | undefined;
    /** @deprecated Use the `BackendApplicationPath` constant or `process.env.THEIA_APP_PROJECT_PATH` environment variable instead */
    projectPath: string;
    configure(conf: yargs.Argv): void;
    setArguments(args: yargs.Arguments): void;
}
/**
 * The main entry point for Theia applications.
 */
export declare class BackendApplication {
    protected readonly contributionsProvider: ContributionProvider<BackendApplicationContribution>;
    protected readonly cliParams: BackendApplicationCliContribution;
    protected readonly app: express.Application;
    protected readonly processUtils: ProcessUtils;
    protected readonly stopwatch: Stopwatch;
    protected readonly rootContainer: interfaces.Container;
    private _configured;
    private stoppedContributions;
    private shuttingDown;
    private settlementContext?;
    constructor(contributionsProvider: ContributionProvider<BackendApplicationContribution>, cliParams: BackendApplicationCliContribution);
    protected initialize(): Promise<void>;
    get configured(): Promise<void>;
    protected init(): void;
    protected configure(): Promise<void>;
    use(...handlers: express.Handler[]): void;
    start(port?: number, hostname?: string): Promise<http.Server | https.Server>;
    protected getHttpUrl({ address, port, family }: AddressInfo, ssl?: boolean): string;
    /**
     * Performs an asynchronous shutdown of the backend in two phases:
     *
     * 1. Contributions' {@link BackendApplicationContribution.onStop onStop} hooks are
     *    dispatched in parallel and awaited so that they can still resolve services
     *    from the root Inversify container while it is bound.
     * 2. All services in the root container are unbound, running their `@preDestroy`
     *    hooks.
     *
     * Each phase has its own {@link SHUTDOWN_TIMEOUT_MS} budget to avoid hanging on a
     * misbehaving hook. Late-resolving promises from a timed-out phase may still
     * settle in the background and could log noisily or interact with a partly
     * unbound container; this is accepted because the process is exiting.
     *
     * Idempotent: a second invocation is a no-op. Exits the process with code 1 so
     * that the `process.on('exit')` handler runs for fallback cleanup such as
     * {@link ProcessUtils.terminateProcessTree}; the exit handler does not re-invoke
     * contribution `onStop()` hooks that this method already dispatched.
     */
    protected gracefulShutdown(): Promise<void>;
    protected stopContributions(): Promise<void>;
    protected onStop(): void;
    protected serveGzipped(contentType: string, req: express.Request, res: express.Response, next: express.NextFunction): Promise<void>;
    protected measureContribution<T>(contribution: BackendApplicationContribution, hook: string, fn: () => MaybePromise<T>): Promise<T>;
    protected measure<T>(name: string, fn: () => MaybePromise<T>): Promise<T>;
    protected handleUncaughtError(error: Error): void;
}
//# sourceMappingURL=backend-application.d.ts.map