コード例 #1
0
ファイル: eventsrv.go プロジェクト: vsysoev/goeventstore
func main() {
	f, err := os.Create("currentsrv.prof")
	if err != nil {
		log.Fatal(err)
	}
	pprof.StartCPUProfile(f)
	defer pprof.StopCPUProfile()
	c := make(chan os.Signal, 1)
	signal.Notify(c, os.Interrupt)
	go func() {
		select {
		case <-c:
			log.Println("Stop profiling")
			pprof.StopCPUProfile()
			syscall.Exit(0)
		}
	}()

	props := property.Init()
	evStore, err := evstore.Dial(props["mongodb.url"], props["mongodb.db"], props["mongodb.stream"])
	if err != nil {
		log.Fatalln("Error connecting to event store. ", err)
	}
	wsServer := wsock.NewServer(props["events.uri"])
	if wsServer == nil {
		log.Fatalln("Error creating new websocket server")
	}
	go processClientConnection(wsServer, evStore)
	go wsServer.Listen()

	//http.Handle(props["static.url"], http.FileServer(http.Dir("webroot")))
	err = http.ListenAndServe(props["events.url"], nil)
	evStore.Close()
}
コード例 #2
0
ファイル: configsrv.go プロジェクト: vsysoev/goeventstore
func main() {
	var id string
	flag.StringVar(&id, "id", "", "ID to subscribe from")
	flag.Parse()
	props := property.Init()

	evStore, err := evstore.Dial(props["mongodb.url"], props["mongodb.db"], props["mongodb.stream"])
	if err != nil {
		log.Fatalln("Error connecting to event store. ", err)
	}
	wsServer := wsock.NewServer(props["configsrv.uri"])
	if wsServer == nil {
		log.Fatalln("Error creating new websocket server")
	}
	currentConfig = Config{}
	currentConfig.mx = &sync.Mutex{}
	isCurrent = false
	stateUpdateChannel := make(chan *bson.M, 256)
	err = evStore.Listenner2().Subscribe2("config", configHandler)
	if err != nil {
		log.Fatalln("Error subscribing for config changes", err)
	}
	ctx1, cancel := context.WithCancel(context.Background())
	ctx := context.WithValue(ctx1, "stateUpdateChannel", stateUpdateChannel)
	defer cancel()
	log.Println("Before Listen call")
	go evStore.Listenner2().Listen(ctx, id)

	go processClientConnection(ctx, wsServer)
	go wsServer.Listen()

	//http.Handle(props["static.url"], http.FileServer(http.Dir("webroot")))
	err = http.ListenAndServe(props["configsrv.url"], nil)
	evStore.Close()
}
コード例 #3
0
ファイル: rpceventsrv.go プロジェクト: vsysoev/goeventstore
func main() {

	props := property.Init()
	evStore, err := evstore.Dial(props["mongodb.url"], props["mongodb.db"], props["mongodb.stream"])
	if err != nil {
		log.Fatalln("Error connecting to event store. ", err)
	}
	f := RPCFunction{evStore}
	wsServer := wsock.NewServer(props["rpceventsrv.uri"])
	if wsServer == nil {
		log.Fatalln("Error creating new websocket server")
	}
	go processClientConnection(wsServer, &f)
	go wsServer.Listen()

	//http.Handle(props["static.url"], http.FileServer(http.Dir("webroot")))
	err = http.ListenAndServe(props["rpceventsrv.url"], nil)
	evStore.Close()
}
コード例 #4
0
func main() {
	c := make(chan os.Signal, 1)
	signal.Notify(c, os.Interrupt)
	go func() {
		select {
		case <-c:
			syscall.Exit(0)
		}
	}()
	props := property.Init()
	wsServer := wsock.NewServer(props["submitevents.uri"])
	if wsServer == nil {
		log.Fatalln("Error creating new websocket server")
	}
	go processClientConnection(wsServer, props)
	go wsServer.Listen()
	http.HandleFunc(props["postevents.uri"], handlePostRequest)
	go http.ListenAndServe(props["submitevents.url"], nil)
	err := http.ListenAndServeTLS(props["securepostevents.url"], "server.pem", "server.key", nil)
	if err != nil {
		log.Fatalln("Error while ListenAndServer", err)
	}
}
コード例 #5
0
ファイル: currentsrv.go プロジェクト: vsysoev/goeventstore
func main() {
	var id string
	flag.StringVar(&id, "id", "", "ID to subscribe from")
	flag.Parse()
	props := property.Init()

	evStore, err := evstore.Dial(props["mongodb.url"], props["mongodb.db"], props["mongodb.stream"])
	if err != nil {
		log.Fatalln("Error connecting to event store. ", err)
	}
	wsServer := wsock.NewServer(props["current.uri"])
	if wsServer == nil {
		log.Fatalln("Error creating new websocket server")
	}
	sState = ScalarState{}
	sState.state = make(map[int]map[int]*bson.M)
	sState.mx = &sync.Mutex{}
	isCurrent = false
	stateUpdate := pubsub.NewPublisher(time.Millisecond*100, 1024)
	err = evStore.Listenner2().Subscribe2("scalar", scalarHandler)
	if err != nil {
		log.Fatalln("Error subscribing for changes", err)
	}
	ctx1, cancel := context.WithCancel(context.Background())
	ctx := context.WithValue(ctx1, "stateUpdate", stateUpdate)
	defer cancel()
	sState.lastID = evStore.Listenner2().GetLastID()
	log.Println("Before Listen call")
	go evStore.Listenner2().Listen(ctx, id)

	go processClientConnection(ctx, wsServer)
	go wsServer.Listen()

	//http.Handle(props["static.url"], http.FileServer(http.Dir("webroot")))
	err = http.ListenAndServe(props["current.url"], nil)
	evStore.Close()
}