Log Block Container Model - Manages multiple log blocks with automatic sorting and organization.

This container model manages collections of LogBlockModel instances, providing organized access to log blocks with automatic sorting by block number. It serves as the storage layer within LogStreamModel instances, handling the efficient organization and retrieval of log blocks that make up a complete log stream.

Key Features

  • Automatic Sorting - Maintains blocks sorted by block number for sequential access
  • Block Management - Add, remove, and retrieve log blocks efficiently
  • Memory Organization - Organized storage of log blocks within streams
  • Stream Integration - Essential component of LogStreamModel architecture
  • Sequential Access - Optimized for accessing blocks in chronological order

Architecture Role

The container fits into the log streaming architecture as:

  • LogStreamModel uses LogBlockContainerModel to organize its blocks
  • LogBlockContainerModel manages multiple LogBlockModel instances
  • LogBlockModel contains the actual log lines and metadata
  • Automatic sorting by blockNum ensures proper sequential log ordering

Common Use Cases

  • Stream Block Storage - Central storage for all blocks within a log stream
  • Sequential Block Access - Navigate through log blocks in chronological order
  • Block Organization - Maintain sorted collections of log segments
  • Memory Management - Efficiently organize log data for stream processing
  • Block Lifecycle - Handle adding and removing blocks as streams evolve

Example: Container Usage Within Stream

// Typically used internally by LogStreamModel
const logStream = LogStream.instance('system-logs').build();
await logStream.load();

// Access the container through the stream
const blockContainer = logStream._blocks; // Internal container
const blocks = logStream.blocks; // Public access to blocks

// Container automatically sorts blocks by blockNum
console.log(`Stream has ${blocks.length} blocks`);
blocks.forEach(block => {
console.log(`Block ${block.blockNum}: ${block.lineCount} lines`);
});

Example: Direct Container Operations

// Create container (typically done internally)
const container = LogBlockContainer.instance('log-blocks')
.options({})
.build();

// Add blocks to container
const block1 = LogBlock.instance('block-1')
.options({
nodeId: 'primary',
stream: 'app-logs',
blockNum: 1,
startLineNum: 1,
endLineNum: 100,
startTime: new Date('2024-01-01T10:00:00Z'),
endTime: new Date('2024-01-01T10:05:00Z'),
lineCount: 100
})
.build();

const block2 = LogBlock.instance('block-2')
.options({
nodeId: 'primary',
stream: 'app-logs',
blockNum: 2,
startLineNum: 101,
endLineNum: 200,
startTime: new Date('2024-01-01T10:05:00Z'),
endTime: new Date('2024-01-01T10:10:00Z'),
lineCount: 100
})
.build();

container.addModel(block1);
container.addModel(block2);

// Blocks are automatically sorted by blockNum
const sortedBlocks = container.data;
console.log(`First block: ${sortedBlocks[0].blockNum}`); // 1
console.log(`Second block: ${sortedBlocks[1].blockNum}`); // 2

Example: React Block List Component

const BlockList: React.FC<{ container: LogBlockContainerModel }> = kosComponent(({ container }) => {
return (
<div className="block-list">
<h3>Log Blocks ({container.data.length})</h3>
<div className="blocks">
{container.data.map(block => (
<div key={block.id} className="block-item">
<div className="block-header">
<span className="block-num">Block {block.blockNum}</span>
<span className="line-range">
Lines {block.startLineNum}-{block.endLineNum}
</span>
</div>
<div className="block-details">
<span>Stream: {block.stream}</span>
<span>Lines: {block.lineCount}</span>
<span>Loaded: {block.lines.length}</span>
</div>
<div className="block-time">
{block.startTime.toLocaleString()} - {block.endTime.toLocaleString()}
</div>
</div>
))}
</div>
</div>
);
});

See

interface LogBlockContainerModel {
    init(): Promise<void>;
}

Methods

Methods

  • -------------------LIFECYCLE----------------------------

    Returns Promise<void>