-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathiceblue.go
More file actions
65 lines (49 loc) · 1.23 KB
/
iceblue.go
File metadata and controls
65 lines (49 loc) · 1.23 KB
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
62
63
64
65
package main
import (
"fmt"
"iceblue/pkg/process"
"iceblue/pkg/storage"
"log"
"os"
"os/signal"
"sync"
"syscall"
)
var defaultPort = "11508"
var iceblueInfo info
type info struct {
port string
}
func stats() {
/* FIXME change the way of print stats to operation response */
fmt.Printf("port = %s\n", iceblueInfo.port)
}
func initializeInfo() {
iceblueInfo.port = defaultPort
}
func handleSignal(signalChannel chan os.Signal, doneChannel chan bool) {
signal := <-signalChannel
log.Printf("Receive signal. %v", signal)
doneChannel <- true
}
func main() {
log.Printf("Start IceBlue Simple Key-value in memory storage.\n")
initializeInfo()
storage.InitializeStore()
process.InitializeProcessRoutine()
success := process.InitializeNetworkModule(iceblueInfo.port)
if !success {
log.Panic("Fail initialize network module")
}
signalChannel := make(chan os.Signal, 1)
quit := make(chan bool, 1)
var waitGroups sync.WaitGroup
waitGroups.Add(1)
signal.Notify(signalChannel, syscall.SIGINT, syscall.SIGTERM, syscall.SIGKILL)
go handleSignal(signalChannel, quit)
go process.AcceptNetworkProcess(&waitGroups, quit)
waitGroups.Wait()
process.DestroyNetworkModule()
process.DestroyProcessRoutine()
storage.DestroyStore()
}