/
fmiworker.go
61 lines (55 loc) · 1.44 KB
/
fmiworker.go
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
//
// Task Wroker
// Connects PULL socket to tcp://localhost:5557
// Collects workloads from ventilator via that socket
// Connects PUSH socket to tcp://localhost:5558
// Sends results to sink via that socket
//
package main
import (
fmi "github.com/CoralGao/fmindex"
"github.com/CoralGao/DistSys"
"strings"
"fmt"
"strconv"
"os"
// "log"
)
type fmiworker struct {
flag int
}
var idx *fmi.Index
var filename string
func (I fmiworker) Analyze(message []byte) []byte {
element := strings.Split(string(message), " ")
if element[0] != filename {
sequencename := strings.TrimRight(element[0], ".fm")
if _, err := os.Stat(element[0]); os.IsNotExist(err) {
if _, err := os.Stat(sequencename); os.IsNotExist(err) {
return []byte(fmt.Sprintf("No such index: %s, need to build it first. But no such sequence: %s!", filename, sequencename))
// log.Fatal("Exit!")
} else {
filename = element[0]
fmt.Printf("No such index: %s, build it now!\n", filename)
idx = fmi.Build(sequencename)
}
} else {
filename = element[0]
idx = fmi.Load(element[0])
fmt.Println("Download the index file.")
}
}
result := fmi.Search(idx, []byte(element[2]))
return format_result(element[1], result)
}
func format_result(index string, intarray []int) []byte{
str := index
for i := 0; i < len(intarray); i++ {
str = str + strconv.Itoa(intarray[i]) + " "
}
return []byte(str)
}
func main() {
x := fmiworker{0}
DistSys.Startworkers(x)
}