UNPKG

4.33 kBJavaScriptView Raw
1"use strict";
2// Copyright (c) Jupyter Development Team.
3// Distributed under the terms of the Modified BSD License.
4Object.defineProperty(exports, "__esModule", { value: true });
5exports.ServiceManager = void 0;
6const signaling_1 = require("@lumino/signaling");
7const builder_1 = require("./builder");
8const contents_1 = require("./contents");
9const event_1 = require("./event");
10const kernel_1 = require("./kernel");
11const kernelspec_1 = require("./kernelspec");
12const nbconvert_1 = require("./nbconvert");
13const serverconnection_1 = require("./serverconnection");
14const session_1 = require("./session");
15const setting_1 = require("./setting");
16const terminal_1 = require("./terminal");
17const user_1 = require("./user");
18const workspace_1 = require("./workspace");
19/**
20 * A Jupyter services manager.
21 */
22class ServiceManager {
23 /**
24 * Construct a new services provider.
25 */
26 constructor(options = {}) {
27 var _a, _b;
28 this._isDisposed = false;
29 this._connectionFailure = new signaling_1.Signal(this);
30 this._isReady = false;
31 const defaultDrive = options.defaultDrive;
32 const serverSettings = (_a = options.serverSettings) !== null && _a !== void 0 ? _a : serverconnection_1.ServerConnection.makeSettings();
33 const standby = (_b = options.standby) !== null && _b !== void 0 ? _b : 'when-hidden';
34 const normalized = { defaultDrive, serverSettings, standby };
35 this.serverSettings = serverSettings;
36 this.contents = options.contents || new contents_1.ContentsManager(normalized);
37 this.events = options.events || new event_1.EventManager(normalized);
38 this.kernels = options.kernels || new kernel_1.KernelManager(normalized);
39 this.sessions =
40 options.sessions ||
41 new session_1.SessionManager({
42 ...normalized,
43 kernelManager: this.kernels
44 });
45 this.settings = options.settings || new setting_1.SettingManager(normalized);
46 this.terminals = options.terminals || new terminal_1.TerminalManager(normalized);
47 this.builder = options.builder || new builder_1.BuildManager(normalized);
48 this.workspaces = options.workspaces || new workspace_1.WorkspaceManager(normalized);
49 this.nbconvert = options.nbconvert || new nbconvert_1.NbConvertManager(normalized);
50 this.kernelspecs = options.kernelspecs || new kernelspec_1.KernelSpecManager(normalized);
51 this.user = options.user || new user_1.UserManager(normalized);
52 // Proxy all connection failures from the individual service managers.
53 this.kernelspecs.connectionFailure.connect(this._onConnectionFailure, this);
54 this.sessions.connectionFailure.connect(this._onConnectionFailure, this);
55 this.terminals.connectionFailure.connect(this._onConnectionFailure, this);
56 // Define promises that need to be resolved before service manager is ready.
57 const readyList = [this.sessions.ready, this.kernelspecs.ready];
58 if (this.terminals.isAvailable()) {
59 readyList.push(this.terminals.ready);
60 }
61 this._readyPromise = Promise.all(readyList).then(() => {
62 this._isReady = true;
63 });
64 }
65 /**
66 * A signal emitted when there is a connection failure with the kernel.
67 */
68 get connectionFailure() {
69 return this._connectionFailure;
70 }
71 /**
72 * Test whether the service manager is disposed.
73 */
74 get isDisposed() {
75 return this._isDisposed;
76 }
77 /**
78 * Dispose of the resources used by the manager.
79 */
80 dispose() {
81 if (this.isDisposed) {
82 return;
83 }
84 this._isDisposed = true;
85 signaling_1.Signal.clearData(this);
86 this.contents.dispose();
87 this.events.dispose();
88 this.sessions.dispose();
89 this.terminals.dispose();
90 }
91 /**
92 * Test whether the manager is ready.
93 */
94 get isReady() {
95 return this._isReady;
96 }
97 /**
98 * A promise that fulfills when the manager is ready.
99 */
100 get ready() {
101 return this._readyPromise;
102 }
103 _onConnectionFailure(sender, err) {
104 this._connectionFailure.emit(err);
105 }
106}
107exports.ServiceManager = ServiceManager;
108//# sourceMappingURL=manager.js.map
\No newline at end of file