summaryrefslogtreecommitdiff
path: root/internal/server/handlers/channelless_adapter.go
blob: 40c072f16f1974eedc19bb318c029fa59cae3b98 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package handlers

import (
	"bytes"

	"github.com/mimecast/dtail/internal/io/line"
)

// ChannellessLineProcessor adapts the channel-less processor to work with the existing handler infrastructure
type ChannellessLineProcessor struct {
	lines      chan<- *line.Line
	globID     string
	lineCount  uint64
}

var _ line.Processor = (*ChannellessLineProcessor)(nil)

// NewChannellessLineProcessor creates a processor that sends lines to the existing channel
func NewChannellessLineProcessor(lines chan<- *line.Line, globID string) *ChannellessLineProcessor {
	return &ChannellessLineProcessor{
		lines:  lines,
		globID: globID,
	}
}

// ProcessLine sends a line through the channel
func (p *ChannellessLineProcessor) ProcessLine(lineContent *bytes.Buffer, lineNum uint64, sourceID string) error {
	p.lineCount++
	
	// Create a line object that matches what the original implementation expects
	l := line.New(lineContent, lineNum, 100, sourceID)
	
	// Send through the channel (blocking to ensure no lines are lost)
	p.lines <- l
	return nil
}

// Flush does nothing for this implementation
func (p *ChannellessLineProcessor) Flush() error {
	return nil
}

// Close does nothing for this implementation
func (p *ChannellessLineProcessor) Close() error {
	return nil
}