Extract ChangeBuffer to own file
This commit is contained in:
38
backend/src/Model/ChangeBuffer.ts
Normal file
38
backend/src/Model/ChangeBuffer.ts
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
import { MqttMessage } from '../../../events'
|
||||||
|
|
||||||
|
export class ChangeBuffer {
|
||||||
|
private buffer: MqttMessage[] = []
|
||||||
|
private size = 0
|
||||||
|
private maxSize = 100_000_000 // ~100MB
|
||||||
|
public length = 0
|
||||||
|
public estimatedMessageOverhead = 24
|
||||||
|
|
||||||
|
public push(val: MqttMessage) {
|
||||||
|
if (!this.isFull()) {
|
||||||
|
this.buffer.push(val)
|
||||||
|
this.size += this.estimatedMessageOverhead + (val.payload ? val.payload.length : 0)
|
||||||
|
this.length += 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public getSize() {
|
||||||
|
return this.size
|
||||||
|
}
|
||||||
|
|
||||||
|
public isFull() {
|
||||||
|
return this.size >= this.maxSize
|
||||||
|
}
|
||||||
|
|
||||||
|
public fillState() {
|
||||||
|
return this.size / this.maxSize
|
||||||
|
}
|
||||||
|
|
||||||
|
public popAll(): MqttMessage[] {
|
||||||
|
const tmpBuffer = this.buffer
|
||||||
|
this.buffer = []
|
||||||
|
this.size = 0
|
||||||
|
this.length = 0
|
||||||
|
|
||||||
|
return tmpBuffer
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,44 +1,13 @@
|
|||||||
|
import { ChangeBuffer } from './ChangeBuffer'
|
||||||
|
import {
|
||||||
|
EventBusInterface,
|
||||||
|
EventDispatcher,
|
||||||
|
makeConnectionMessageEvent,
|
||||||
|
MqttMessage
|
||||||
|
} from '../../../events'
|
||||||
import { TreeNode } from './'
|
import { TreeNode } from './'
|
||||||
import { EventBusInterface, makeConnectionMessageEvent, MqttMessage, EventDispatcher } from '../../../events'
|
|
||||||
import { TreeNodeFactory } from './TreeNodeFactory'
|
import { TreeNodeFactory } from './TreeNodeFactory'
|
||||||
|
|
||||||
class ChangeBuffer {
|
|
||||||
private buffer: MqttMessage[] = []
|
|
||||||
private size = 0
|
|
||||||
private maxSize = 100_000_000 // ~100MB
|
|
||||||
public length = 0
|
|
||||||
public estimatedMessageOverhead = 24
|
|
||||||
|
|
||||||
public push(val: MqttMessage) {
|
|
||||||
if (!this.isFull()) {
|
|
||||||
this.buffer.push(val)
|
|
||||||
this.size += this.estimatedMessageOverhead + (val.payload ? val.payload.length : 0)
|
|
||||||
this.length += 1
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public getSize() {
|
|
||||||
return this.size
|
|
||||||
}
|
|
||||||
|
|
||||||
public isFull() {
|
|
||||||
return this.size >= this.maxSize
|
|
||||||
}
|
|
||||||
|
|
||||||
public fillState() {
|
|
||||||
return this.size / this.maxSize
|
|
||||||
}
|
|
||||||
|
|
||||||
public popAll(): MqttMessage[] {
|
|
||||||
const tmpBuffer = this.buffer
|
|
||||||
this.buffer = []
|
|
||||||
this.size = 0
|
|
||||||
this.length = 0
|
|
||||||
|
|
||||||
return tmpBuffer
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export class Tree<ViewModel> extends TreeNode<ViewModel> {
|
export class Tree<ViewModel> extends TreeNode<ViewModel> {
|
||||||
public connectionId?: string
|
public connectionId?: string
|
||||||
public updateSource?: EventBusInterface
|
public updateSource?: EventBusInterface
|
||||||
|
|||||||
Reference in New Issue
Block a user