-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Theia spawns as many nsfw servers as there are clients, maybe more. This commit replaces this behaviour by centralizing everything into the same service process in order to optimize resources (watch handles are a limited resource on a given Linux host). Some notes on the current design: - Everytime someone requests to watch an `(uri, options)` couple we will re-use the same watch handle (and actual nsfw instance). This allows for resource allocation optimizations. - Since a given service can only serve a single client, I added an event dispatcher named `FileSystemWatcherServiceDispatcher`. You must register yourself with some unique id you will use to make requests. - The new `.watchUriChanges` function now takes a `clientId` so that when events are sent to the dispatcher it then gets routed back to your own client. - Added a `--nsfw-watcher-verbose` backend argument to enable verbose logging for the watcher server. Signed-off-by: Paul Maréchal <[email protected]>
- Loading branch information
1 parent
8ff85ba
commit b190927
Showing
14 changed files
with
886 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
examples/api-samples/src/browser/file-watching/sample-file-watching-contribution.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
/******************************************************************************** | ||
* Copyright (C) 2020 Ericsson and others. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* This Source Code may also be made available under the following Secondary | ||
* Licenses when the conditions for such availability set forth in the Eclipse | ||
* Public License v. 2.0 are satisfied: GNU General Public License, version 2 | ||
* with the GNU Classpath Exception which is available at | ||
* https://www.gnu.org/software/classpath/license.html. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 | ||
********************************************************************************/ | ||
|
||
import { postConstruct, injectable, inject, interfaces } from 'inversify'; | ||
import { | ||
createPreferenceProxy, FrontendApplicationContribution, LabelProvider, | ||
PreferenceContribution, PreferenceProxy, PreferenceSchema, PreferenceService | ||
} from '@theia/core/lib/browser'; | ||
import { FileService } from '@theia/filesystem/lib/browser/file-service'; | ||
import { WorkspaceService } from '@theia/workspace/lib/browser'; | ||
|
||
export function bindSampleFileWatching(bind: interfaces.Bind): void { | ||
bind(FrontendApplicationContribution).to(SampleFileWatchingContribution).inSingletonScope(); | ||
bind(PreferenceContribution).toConstantValue({ schema: FileWatchingPreferencesSchema }); | ||
bind(FileWatchingPreferences).toDynamicValue( | ||
ctx => createPreferenceProxy(ctx.container.get(PreferenceService), FileWatchingPreferencesSchema) | ||
); | ||
} | ||
|
||
const FileWatchingPreferences = Symbol('FileWatchingPreferences'); | ||
type FileWatchingPreferences = PreferenceProxy<FileWatchingPreferencesSchema>; | ||
|
||
interface FileWatchingPreferencesSchema { | ||
'sample.file-watching.verbose': boolean | ||
} | ||
const FileWatchingPreferencesSchema: PreferenceSchema = { | ||
type: 'object', | ||
properties: { | ||
'sample.file-watching.verbose': { | ||
type: 'boolean', | ||
default: false, | ||
description: 'Enable verbose file watching logs.' | ||
} | ||
} | ||
}; | ||
|
||
@injectable() | ||
class SampleFileWatchingContribution implements FrontendApplicationContribution { | ||
|
||
protected verbose: boolean; | ||
|
||
@inject(FileService) | ||
protected readonly fileService: FileService; | ||
|
||
@inject(LabelProvider) | ||
protected readonly labelProvider: LabelProvider; | ||
|
||
@inject(WorkspaceService) | ||
protected readonly workspaceService: WorkspaceService; | ||
|
||
@inject(FileWatchingPreferences) | ||
protected readonly fileWatchingPreferences: FileWatchingPreferences; | ||
|
||
@postConstruct() | ||
protected postConstruct(): void { | ||
this.verbose = this.fileWatchingPreferences['sample.file-watching.verbose']; | ||
this.fileWatchingPreferences.onPreferenceChanged(e => { | ||
if (e.preferenceName === 'sample.file-watching.verbose') { | ||
this.verbose = e.newValue!; | ||
} | ||
}); | ||
} | ||
|
||
onStart(): void { | ||
this.fileService.onDidFilesChange(event => { | ||
// Only log if the verbose preference is set. | ||
if (this.verbose) { | ||
// Get the workspace roots for the current frontend: | ||
const roots = this.workspaceService.tryGetRoots(); | ||
// Create some name to help find out which frontend logged the message: | ||
const workspace = roots.length > 0 | ||
? roots.map(root => this.labelProvider.getLongName(root.resource)).join('+') | ||
: '<no workspace>'; | ||
console.log(`Sample File Watching: ${event.changes.length} file(s) changed! ${workspace}`); | ||
} | ||
}); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,9 @@ | |
"mv": [ | ||
"src/typings/mv" | ||
], | ||
"nsfw": [ | ||
"src/typings/nsfw" | ||
], | ||
"trash": [ | ||
"src/typings/trash" | ||
] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.