Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: update some logs on extension host process service #2173

Merged
merged 4 commits into from
Jan 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions packages/connection/src/node/common-channel-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,19 +121,18 @@ export class CommonChannelHandler extends WebSocketHandler {

// 心跳消息
if (msgObj.kind === 'heartbeat') {
// console.log(`heartbeat msg ${msgObj.clientId}`)
connection.send(stringify(`heartbeat ${msgObj.clientId}`));
} else if (msgObj.kind === 'client') {
const clientId = msgObj.clientId;
this.logger.log('new connection clientId', clientId);
this.logger.log(`New connection with id ${clientId}`);
connectionId = clientId;
this.connectionMap.set(clientId, connection);
this.hearbeat(connectionId, connection);
// channel 消息处理
} else if (msgObj.kind === 'open') {
const channelId = msgObj.id; // CommonChannelHandler.channelId ++;
const { path } = msgObj;
this.logger.log('new open channelId', channelId, 'channelPath', path);
this.logger.log(`Open a new connection channel ${channelId} with path ${path}`);

// 生成 channel 对象
const connectionSend = this.channelConnectionSend(connection);
Expand Down Expand Up @@ -162,14 +161,12 @@ export class CommonChannelHandler extends WebSocketHandler {

channel.ready();
} else {
// console.log('connection message', msgObj.id, msgObj.kind, this.channelMap.get(msgObj.id));

const { id } = msgObj;
const channel = this.channelMap.get(id);
if (channel) {
channel.handleMessage(msgObj);
} else {
this.logger.warn(`channel ${id} not found`);
this.logger.warn(`The channel(${id}) was not found`);
}
}
} catch (e) {
Expand All @@ -184,15 +181,15 @@ export class CommonChannelHandler extends WebSocketHandler {
clearTimeout(this.heartbeatMap.get(connectionId) as NodeJS.Timeout);
this.heartbeatMap.delete(connectionId);

this.logger.verbose(`clear heartbeat ${connectionId}`);
this.logger.verbose(`Clear heartbeat from channel ${connectionId}`);
}

Array.from(this.channelMap.values())
.filter((channel) => channel.id.toString().indexOf(connectionId) !== -1)
.forEach((channel) => {
channel.close(1, 'close');
this.channelMap.delete(channel.id);
this.logger.verbose(`remove channel ${channel.id}`);
this.logger.verbose(`Remove connection channel ${channel.id}`);
});
});
});
Expand Down
11 changes: 3 additions & 8 deletions packages/core-node/src/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export function createServerConnection2(
// 事件由 connection 的时机来触发
commonChannelPathHandler.register('RPCService', {
handler: (connection: WSChannel, clientId: string) => {
logger.log(`set rpc connection ${clientId}`);
logger.log(`New RPC connection ${clientId}`);

const serviceCenter = new RPCServiceCenter(undefined, logger);
const serviceChildInjector = bindModuleBackService(injector, modulesInstances, serviceCenter, clientId);
Expand All @@ -50,10 +50,10 @@ export function createServerConnection2(
serviceCenter.removeConnection(serverConnection);
serviceChildInjector.disposeAll();

logger.log(`remove rpc connection ${clientId} `);
logger.log(`Remove RPC connection ${clientId}`);
});
},
dispose: (connection: ws, connectionClientId: string) => {},
dispose: () => {},
});

socketRoute.registerHandler(channelHandler);
Expand All @@ -76,15 +76,12 @@ export function createNetServerConnection(server: net.Server, injector, modulesI
);

server.on('connection', (connection) => {
logger.log('set net rpc connection');
const serverConnection = createSocketConnection(connection);
serviceCenter.setConnection(serverConnection);

connection.on('close', () => {
serviceCenter.removeConnection(serverConnection);
serviceChildInjector.disposeAll();

logger.log('remove net rpc connection');
});
});

Expand All @@ -97,15 +94,13 @@ export function bindModuleBackService(
serviceCenter: RPCServiceCenter,
clientId?: string,
) {
const logger = injector.get(INodeLogger);
const { createRPCService } = initRPCService(serviceCenter);

const childInjector = injector.createChild();
for (const module of modules) {
if (module.backServices) {
for (const service of module.backServices) {
if (service.token) {
logger.log('back service', service.token);
const serviceToken = service.token;

if (!injector.creatorMap.has(serviceToken)) {
Expand Down
3 changes: 2 additions & 1 deletion packages/extension/src/browser/extension-node.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
} from '@opensumi/ide-core-browser';

import {
CONNECTION_HANDLE_BETWEEN_EXTENSION_AND_MAIN_THREAD,
ExtensionNodeServiceServerPath,
IExtension,
IExtensionHostService,
Expand Down Expand Up @@ -172,7 +173,7 @@ export class NodeExtProcessService implements AbstractNodeExtProcessService<IExt
mainThreadCenter.setConnection(createElectronClientConnection(connectPath));
} else {
const WSChannelHandler = this.injector.get(IWSChannelHandler);
const channel = await WSChannelHandler.openChannel('ExtMainThreadConnection');
const channel = await WSChannelHandler.openChannel(CONNECTION_HANDLE_BETWEEN_EXTENSION_AND_MAIN_THREAD);
mainThreadCenter.setConnection(createWebSocketConnection(channel));
}

Expand Down
1 change: 1 addition & 0 deletions packages/extension/src/common/const.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const CONNECTION_HANDLE_BETWEEN_EXTENSION_AND_MAIN_THREAD = 'ExtMainThreadConnection';
Loading