Skip to content

Commit

Permalink
Need to clean up disposals w/ heartbeat
Browse files Browse the repository at this point in the history
  • Loading branch information
stricklandrbls committed Aug 1, 2024
1 parent a2762cf commit 12948d7
Show file tree
Hide file tree
Showing 10 changed files with 64 additions and 70 deletions.
10 changes: 8 additions & 2 deletions src/dataEditor/core/editor/dataEditor.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ExtensionContext } from 'vscode'
import { Disposable, ExtensionContext } from 'vscode'
import { DataSource, EditServiceClient } from '../service/editService'
import { DataEditorUI } from './editorUI'

Expand All @@ -11,7 +11,7 @@ export type EditorCommand = {
initializer: DataEditorInitializer
}

export abstract class DataEditor {
export abstract class DataEditor implements Disposable {
constructor(
protected serviceClient: EditServiceClient,
protected ui: DataEditorUI
Expand All @@ -23,6 +23,12 @@ export abstract class DataEditor {
ui.onInputEvent = (input) => {
this.serviceClient.request(input)
}
ui.onClosed(() => {
this.dispose()
})
}
dispose() {
this.serviceClient.close()
}
dataSource(): DataSource {
throw ''
Expand Down
3 changes: 3 additions & 0 deletions src/dataEditor/omegaEdit/server/heartbeat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,7 @@ export class Heartbeat {
getLast() {
return this.lastHeartbeat
}
stop() {
clearInterval(this.intervalId)
}
}
13 changes: 12 additions & 1 deletion src/dataEditor/omegaEdit/server/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const ServerDisposeAll = {

export class OmegaEditServer {
private service: OmegaEditService
private disposables: Array<() => any> = []
constructor(
private client: EditorClient,
readonly config: ServerConfig,
Expand All @@ -50,14 +51,24 @@ export class OmegaEditServer {
this.service.onAllSessionsClosed(() => {
serverStop(this.config)
})
this.disposables.push(
() => {
heartbeat.stop()
},
() => {
serverStop(this.config)
}
)
}
getService(): Promise<OmegaEditService> {
return new Promise((res, rej) => {
this.service ? res(this.service) : rej('No service was initialzied!')
})
}
readonly dispose = () => {
serverStop(this.config)
this.disposables.forEach((disposal) => {
disposal()
})
}
}

Expand Down
63 changes: 14 additions & 49 deletions src/dataEditor/omegaEdit/service/editService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,12 @@ export class OmegaEditService implements EditService {
private heartbeat_: Heartbeat,
readonly serviceInfo: ServiceInfo,
readonly checkpointDirectory: FilePath = FilePath.SystemTmpDirectory()
) {}
) {
this.Events.on('allSessionsClosed', () => {
clearInterval(this.heartbeatInterval)
})
}
onAllSessionsClosed(listener: () => void) {
clearInterval(this.heartbeatInterval)
this.Events.on('allSessionsClosed', () => {
listener()
})
Expand Down Expand Up @@ -91,12 +94,6 @@ export class OmegaEditService implements EditService {
.on('error', (err) => {
console.log('Viewport Subscribe err: ', err)
})
.on('status', (status) => {
console.log(status.details)
})
.on('resume', () => {
console.log('Viewport Events Resuming')
})
getViewportData(vpId).then((r) => {
session.onDidProcess({
command: 20,
Expand Down Expand Up @@ -133,9 +130,11 @@ export class OmegaEditService implements EditService {

const id = response.getSessionId()
this.activeSessions.set(id, file)

const requestHandlerFn = async (req) => {
return this.requestHandler(req)
}

const sessionCloseCallback = () => {
this.removeSession(id)
}
Expand All @@ -157,50 +156,16 @@ export class OmegaEditService implements EditService {
this.activeSessions.get(request.sessionId)!
)
case 'getServerHeartbeat':
return ServiceRequestHandler.getHandle('getServerHeartbeat')()
return new Promise((res, rej) => {
res({
command: 4,
data: { ...this.heartbeat_.getLast(), ...this.serviceInfo },
})
})
default:
return new Promise((_, rej) => {
rej('Unknown request command')
rej(`Unknown request command: ${request.command}`)
})
}
// const handler = ServiceRequestHandler.getHandle('viewportSeekTo')
// return new Promise(async (res, rej) => {

// if (request.command === 'getServerHeartbeat') {
// res({
// command: 4,
// data: { ...this.heartbeat_.getLast(), ...this.serviceInfo },
// })
// }
// if (request.command === 'getFileInfo') {
// const count = await getCounts(sessionId, [
// 1, //CountKind.COUNT_COMPUTED_FILE_SIZE,
// 7, //CountKind.COUNT_CHANGE_TRANSACTIONS,
// 8, //CountKind.COUNT_UNDO_TRANSACTIONS,
// ])
// const file = this.activeSessions.get(sessionId)
// let data = {
// fileName: file ? file.fullPath() : 'No file',
// computedFileSize: 0,
// changeCount: 0,
// undoCount: 0,
// }
// count.forEach((count) => {
// switch (count.getKind()) {
// case 1: //CountKind.COUNT_COMPUTED_FILE_SIZE:
// data.computedFileSize = count.getCount()
// break
// case 7: //CountKind.COUNT_CHANGE_TRANSACTIONS:
// data.changeCount = count.getCount()
// break
// case 8: //CountKind.COUNT_UNDO_TRANSACTIONS:
// data.undoCount = count.getCount()
// break
// }
// })
// res({ command: 3, data: data })
// }
// rej({ msg: `no ${request.command} handler found` })
// })
}
}
16 changes: 8 additions & 8 deletions src/dataEditor/omegaEdit/service/requests.ts/requestHandler.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
import { getCounts } from '@omega-edit/client'
import { getCounts, IServerHeartbeat } from '@omega-edit/client'
import { FilePath } from '../..'
import { SessionIdType } from '../session'
import { ViewportCreateHandler } from './viewport'

type CommandResponse<Args, ResponseType> = (
args?: Args
) => Promise<ResponseType>
const ServerHeartbeatHandler: CommandResponse<undefined, {}> = () => {
return new Promise((res, rej) => {
res({
command: 4,
data: {},
})
})

interface ServiceRequest {
readonly command: string
}

const ServerHeartbeatHandler = (hb: IServerHeartbeat) => {}

type FileInfo = {
name: string
computedFileSize: number
changeCount: number
undoCount: number
}

const FileInfoHandler = (sessionId: SessionIdType, file: FilePath) => {
return new Promise(async (res, rej) => {
const count = await getCounts(sessionId, [
Expand Down
8 changes: 7 additions & 1 deletion src/dataEditor/omegaEdit/service/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export class OmegaEditSession implements EditServiceClient {
constructor(
private sessionId: SessionIdType,
private serviceRequestHandler: (request: any) => Promise<any>,
readonly close: () => void
readonly onClose: () => void
) {
this.heartbeatInterval = setInterval(() => {
this.request({ command: 'getServerHeartbeat' })
Expand Down Expand Up @@ -55,6 +55,12 @@ export class OmegaEditSession implements EditServiceClient {
this.onDidProcess(response)
this.onRequestProcessed
}
close() {
clearInterval(this.heartbeatInterval)
this.requestResponseCallbacks = []
this.responseBacklog = []
this.onClose()
}
}

export class OmegaEditSessionNotifier {
Expand Down
6 changes: 2 additions & 4 deletions src/dataEditor/standalone/standaloneEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ export class StandaloneEditor extends DataEditor implements vscode.Disposable {
}
this.serviceClient.request({ command: 'getFileInfo' })
}
dispose() {
// this.editService.dispose()
}
}

export class StandaloneInitializer extends DataEditorInitializer<StandaloneEditor> {
Expand All @@ -42,8 +39,9 @@ export class StandaloneInitializer extends DataEditorInitializer<StandaloneEdito
extractConfigurationVariables
)
const service = await server.getService()

const session = await service.register(target)
ctx.subscriptions.push(server)

resolve(
new StandaloneEditor(
session,
Expand Down
9 changes: 7 additions & 2 deletions src/dataEditor/webview/editorWebviewPanel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ export class WebviewPanelEditorUI implements DataEditorUI {
}

updateUI(data: any) {
this.panel.webview.postMessage(data)
this.panel.webview.postMessage(data).then(undefined, (rejected) => {
console.log(`Panel rejected postMessage: ${rejected}`)
})
}

/// `postMessage` can only send JSON serializable data
Expand All @@ -45,6 +47,9 @@ export class WebviewPanelEditorUI implements DataEditorUI {
})
}
onClosed(disposal: (e: void) => any) {
this.panel.onDidDispose(disposal)
this.panel.onDidDispose(() => {
disposal()
this.panel.dispose()
})
}
}
4 changes: 2 additions & 2 deletions src/svelte/src/components/Header/fieldsets/FileMetrics.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ limitations under the License.
// reset the profiler if changes have been made
isProfilerOpen = false
startOffset = length = 0
if ('fileName' in msg.data.data) {
$fileMetrics.name = msg.data.data.fileName
if ('name' in msg.data.data) {
$fileMetrics.name = msg.data.data.name
}
if ('type' in msg.data.data) {
$fileMetrics.type = msg.data.data.type
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ limitations under the License.
heartbeat.jvmVendor = msg.data.data.server.jvmVendor
heartbeat.jvmPath = msg.data.data.server.jvmPath
heartbeat.availableProcessors =
msg.data.data.serverInfo.availableProcessors
msg.data.data.server.availableProcessors
// set the serverTimestamp to 0 after 5 seconds of no heartbeat to indicate that no heartbeat has been received
clearTimeout(timerId)
Expand Down

0 comments on commit 12948d7

Please sign in to comment.