-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Properly scope server connections on a per-frontend basis
- Create one ModelServiceImpl per frontend connection - Improve connection reporting for server clients - Replace temporary workspace files with port commands -- Query command contributed by extension -- Extension forwards command execution to language server
- Loading branch information
1 parent
b9adbdb
commit 8460854
Showing
15 changed files
with
198 additions
and
248 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
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
This file was deleted.
Oops, something went wrong.
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 was deleted.
Oops, something went wrong.
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
94 changes: 94 additions & 0 deletions
94
packages/glsp-client/src/node/crossmodel-diagram-connection-handler.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,94 @@ | ||
/******************************************************************************** | ||
* Copyright (c) 2023 CrossBreeze. | ||
********************************************************************************/ | ||
import { GLSP_PORT_COMMAND } from '@crossbreeze/protocol'; | ||
import { GLSPContribution } from '@eclipse-glsp/theia-integration/lib/common'; | ||
import { SocketConnectionForwarder } from '@eclipse-glsp/theia-integration/lib/node'; | ||
import { Channel, CommandService, ConnectionHandler, Disposable, MessageService } from '@theia/core'; | ||
import { ForwardingChannel } from '@theia/core/lib/common/message-rpc/channel'; | ||
import { Deferred } from '@theia/core/lib/common/promise-util'; | ||
import { inject, injectable } from '@theia/core/shared/inversify'; | ||
import * as net from 'net'; | ||
import { CrossModelDiagramLanguage } from '../common/crossmodel-diagram-language'; | ||
|
||
@injectable() | ||
export class CrossModelDiagramGLSPConnectionHandler implements ConnectionHandler { | ||
path = GLSPContribution.servicePath + '/' + CrossModelDiagramLanguage.contributionId; | ||
|
||
@inject(MessageService) protected messageService: MessageService; | ||
@inject(CommandService) protected commandService: CommandService; | ||
|
||
onConnection(connection: Channel): void { | ||
this.initializeServerConnection(connection); | ||
} | ||
|
||
protected async initializeServerConnection(channel: Channel): Promise<void> { | ||
const progress = await this.messageService.showProgress({ | ||
text: 'Connecting to Graphical Server', | ||
options: { cancelable: false } | ||
}); | ||
try { | ||
progress.report({ message: 'Waiting for port information...' }); | ||
const port = await this.findPort(); | ||
progress.report({ message: 'Waiting for connection on port ' + port + '...' }); | ||
await this.connectToServer(channel, port); | ||
progress.cancel(); | ||
this.messageService.info('Connected to Graphical Server on port ' + port, { timeout: 3000 }); | ||
} catch (error) { | ||
progress.cancel(); | ||
this.messageService.error('Could not connect to Graphical Server: ' + error); | ||
} | ||
} | ||
|
||
protected async findPort(timeout = 500, attempts = -1): Promise<number> { | ||
const pendingContent = new Deferred<number>(); | ||
let counter = 0; | ||
const tryQueryingPort = (): void => { | ||
setTimeout(async () => { | ||
try { | ||
const port = await this.commandService.executeCommand<number>(GLSP_PORT_COMMAND); | ||
if (port) { | ||
pendingContent.resolve(port); | ||
} | ||
} catch (error) { | ||
counter++; | ||
if (attempts >= 0 && counter > attempts) { | ||
pendingContent.reject(error); | ||
} else { | ||
tryQueryingPort(); | ||
} | ||
} | ||
}, timeout); | ||
}; | ||
tryQueryingPort(); | ||
return pendingContent.promise; | ||
} | ||
|
||
protected async connectToServer(channel: Channel, port: number): Promise<any> { | ||
// Create the deferred object which exposes the Promise of the connection with the ModelServer. | ||
const connected = new Deferred<void>(); | ||
|
||
// Create the socket, reader, writer and rpc-connection. | ||
const socket = new net.Socket(); | ||
|
||
// Configure connection promise results for the socket. | ||
socket.on('ready', () => connected.resolve()); | ||
socket.on('close', () => connected.reject('Socket from Graphical Client to Graphical Server was closed.')); | ||
socket.on('error', error => console.error('Error occurred with the Graphical socket: %s; %s', error.name, error.message)); | ||
|
||
this.forwardToSocketConnection(channel, socket); | ||
if (channel instanceof ForwardingChannel) { | ||
socket.on('error', error => channel.onErrorEmitter.fire(error)); | ||
} | ||
|
||
// Connect to the ModelServer on the given port. | ||
socket.connect({ port }); | ||
|
||
setTimeout(() => connected.reject('Timeout reached.'), 10000); | ||
return connected.promise; | ||
} | ||
|
||
protected forwardToSocketConnection(clientChannel: Channel, socket: net.Socket): Disposable { | ||
return new SocketConnectionForwarder(clientChannel, socket); | ||
} | ||
} |
43 changes: 0 additions & 43 deletions
43
packages/glsp-client/src/node/crossmodel-diagram-server-contribution.ts
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.