manager.ts 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. // Copyright (c) Jupyter Development Team.
  2. // Distributed under the terms of the Modified BSD License.
  3. import {
  4. IDisposable
  5. } from '@phosphor/disposable';
  6. import {
  7. ISignal, Signal
  8. } from '@phosphor/signaling';
  9. import {
  10. Builder, BuildManager
  11. } from './builder';
  12. import {
  13. Contents, ContentsManager
  14. } from './contents';
  15. import {
  16. Kernel
  17. } from './kernel';
  18. import {
  19. Session, SessionManager
  20. } from './session';
  21. import {
  22. Setting, SettingManager
  23. } from './setting';
  24. import {
  25. TerminalSession, TerminalManager
  26. } from './terminal';
  27. import {
  28. ServerConnection
  29. } from './serverconnection';
  30. import {
  31. WorkspaceManager
  32. } from './workspace';
  33. /**
  34. * A Jupyter services manager.
  35. */
  36. export
  37. class ServiceManager implements ServiceManager.IManager {
  38. /**
  39. * Construct a new services provider.
  40. */
  41. constructor(options: ServiceManager.IOptions = {}) {
  42. this.serverSettings = (
  43. options.serverSettings || ServerConnection.makeSettings()
  44. );
  45. this.contents = new ContentsManager(options);
  46. this.sessions = new SessionManager(options);
  47. this.settings = new SettingManager(options);
  48. this.terminals = new TerminalManager(options);
  49. this.builder = new BuildManager(options);
  50. this.workspaces = new WorkspaceManager(options);
  51. this.sessions.specsChanged.connect((sender, specs) => {
  52. this._specsChanged.emit(specs);
  53. });
  54. this._readyPromise = this.sessions.ready.then(() => {
  55. if (this.terminals.isAvailable()) {
  56. return this.terminals.ready;
  57. }
  58. });
  59. this._readyPromise.then(() => { this._isReady = true; });
  60. }
  61. /**
  62. * A signal emitted when the kernel specs change.
  63. */
  64. get specsChanged(): ISignal<this, Kernel.ISpecModels> {
  65. return this._specsChanged;
  66. }
  67. /**
  68. * Test whether the service manager is disposed.
  69. */
  70. get isDisposed(): boolean {
  71. return this._isDisposed;
  72. }
  73. /**
  74. * Dispose of the resources used by the manager.
  75. */
  76. dispose(): void {
  77. if (this.isDisposed) {
  78. return;
  79. }
  80. this._isDisposed = true;
  81. Signal.clearData(this);
  82. this.contents.dispose();
  83. this.sessions.dispose();
  84. this.terminals.dispose();
  85. }
  86. /**
  87. * The kernel spec models.
  88. */
  89. get specs(): Kernel.ISpecModels | null {
  90. return this.sessions.specs;
  91. }
  92. /**
  93. * The server settings of the manager.
  94. */
  95. readonly serverSettings: ServerConnection.ISettings;
  96. /**
  97. * Get the session manager instance.
  98. */
  99. readonly sessions: SessionManager;
  100. /**
  101. * Get the setting manager instance.
  102. */
  103. readonly settings: SettingManager;
  104. /**
  105. * The builder for the manager.
  106. */
  107. readonly builder: BuildManager;
  108. /**
  109. * Get the contents manager instance.
  110. */
  111. readonly contents: ContentsManager;
  112. /**
  113. * Get the terminal manager instance.
  114. */
  115. readonly terminals: TerminalManager;
  116. /**
  117. * Get the workspace manager instance.
  118. */
  119. readonly workspaces: WorkspaceManager;
  120. /**
  121. * Test whether the manager is ready.
  122. */
  123. get isReady(): boolean {
  124. return this._isReady;
  125. }
  126. /**
  127. * A promise that fulfills when the manager is ready.
  128. */
  129. get ready(): Promise<void> {
  130. return this._readyPromise;
  131. }
  132. private _isDisposed = false;
  133. private _readyPromise: Promise<void>;
  134. private _specsChanged = new Signal<this, Kernel.ISpecModels>(this);
  135. private _isReady = false;
  136. }
  137. /**
  138. * The namespace for `ServiceManager` statics.
  139. */
  140. export
  141. namespace ServiceManager {
  142. /**
  143. * A service manager interface.
  144. */
  145. export
  146. interface IManager extends IDisposable {
  147. /**
  148. * A signal emitted when the kernel specs change.
  149. */
  150. specsChanged: ISignal<IManager, Kernel.ISpecModels>;
  151. /**
  152. * The kernel spec models.
  153. */
  154. readonly specs: Kernel.ISpecModels | null;
  155. /**
  156. * The server settings of the manager.
  157. */
  158. readonly serverSettings: ServerConnection.ISettings;
  159. /**
  160. * The session manager for the manager.
  161. */
  162. readonly sessions: Session.IManager;
  163. /**
  164. * The setting manager for the manager.
  165. */
  166. readonly settings: Setting.IManager;
  167. /**
  168. * The builder for the manager.
  169. */
  170. readonly builder: Builder.IManager;
  171. /**
  172. * The contents manager for the manager.
  173. */
  174. readonly contents: Contents.IManager;
  175. /**
  176. * The terminals manager for the manager.
  177. */
  178. readonly terminals: TerminalSession.IManager;
  179. /**
  180. * Test whether the manager is ready.
  181. */
  182. readonly isReady: boolean;
  183. /**
  184. * A promise that fulfills when the manager is initially ready.
  185. */
  186. readonly ready: Promise<void>;
  187. }
  188. /**
  189. * The options used to create a service manager.
  190. */
  191. export
  192. interface IOptions {
  193. /**
  194. * The server settings of the manager.
  195. */
  196. readonly serverSettings?: ServerConnection.ISettings;
  197. /**
  198. * The default drive for the contents manager.
  199. */
  200. readonly defaultDrive?: Contents.IDrive;
  201. }
  202. }