Skip to content
Snippets Groups Projects
Commit e53cfef0 authored by Luca Moser's avatar Luca Moser
Browse files

removes daemon.Events.Shutdown listeners

parent d592db29
No related branches found
No related tags found
No related merge requests found
...@@ -5,8 +5,6 @@ import ( ...@@ -5,8 +5,6 @@ import (
"github.com/iotaledger/goshimmer/plugins/analysis/client" "github.com/iotaledger/goshimmer/plugins/analysis/client"
"github.com/iotaledger/goshimmer/plugins/analysis/server" "github.com/iotaledger/goshimmer/plugins/analysis/server"
"github.com/iotaledger/goshimmer/plugins/analysis/webinterface" "github.com/iotaledger/goshimmer/plugins/analysis/webinterface"
"github.com/iotaledger/hive.go/daemon"
"github.com/iotaledger/hive.go/events"
"github.com/iotaledger/hive.go/logger" "github.com/iotaledger/hive.go/logger"
"github.com/iotaledger/hive.go/node" "github.com/iotaledger/hive.go/node"
) )
...@@ -18,10 +16,6 @@ func configure(plugin *node.Plugin) { ...@@ -18,10 +16,6 @@ func configure(plugin *node.Plugin) {
if parameter.NodeConfig.GetInt(server.CFG_SERVER_PORT) != 0 { if parameter.NodeConfig.GetInt(server.CFG_SERVER_PORT) != 0 {
webinterface.Configure(plugin) webinterface.Configure(plugin)
server.Configure(plugin) server.Configure(plugin)
daemon.Events.Shutdown.Attach(events.NewClosure(func() {
server.Shutdown(plugin)
}))
} }
} }
...@@ -35,7 +29,6 @@ func run(plugin *node.Plugin) { ...@@ -35,7 +29,6 @@ func run(plugin *node.Plugin) {
if parameter.NodeConfig.GetString(client.CFG_SERVER_ADDRESS) != "" { if parameter.NodeConfig.GetString(client.CFG_SERVER_ADDRESS) != "" {
client.Run(plugin) client.Run(plugin)
log.Info("Stopping Analysis-Client ... done")
} else { } else {
log.Info("Starting Plugin: Analysis ... client is disabled (server-address is empty)") log.Info("Starting Plugin: Analysis ... client is disabled (server-address is empty)")
} }
......
...@@ -41,14 +41,16 @@ func Configure(plugin *node.Plugin) { ...@@ -41,14 +41,16 @@ func Configure(plugin *node.Plugin) {
func Run(plugin *node.Plugin) { func Run(plugin *node.Plugin) {
daemon.BackgroundWorker("Analysis Server", func(shutdownSignal <-chan struct{}) { daemon.BackgroundWorker("Analysis Server", func(shutdownSignal <-chan struct{}) {
log.Infof("Starting Server (port %d) ... done", parameter.NodeConfig.GetInt(CFG_SERVER_PORT)) log.Infof("Starting Server (port %d) ... done", parameter.NodeConfig.GetInt(CFG_SERVER_PORT))
server.Listen(parameter.NodeConfig.GetInt(CFG_SERVER_PORT)) go server.Listen(parameter.NodeConfig.GetInt(CFG_SERVER_PORT))
<-shutdownSignal
Shutdown()
}) })
} }
func Shutdown(plugin *node.Plugin) { func Shutdown() {
log.Info("Stopping Server ...") log.Info("Stopping Server ...")
server.Shutdown() server.Shutdown()
log.Info("Stopping Server ... done")
} }
func HandleConnection(conn *network.ManagedConnection) { func HandleConnection(conn *network.ManagedConnection) {
......
...@@ -5,7 +5,6 @@ import ( ...@@ -5,7 +5,6 @@ import (
"time" "time"
"github.com/iotaledger/hive.go/daemon" "github.com/iotaledger/hive.go/daemon"
"github.com/iotaledger/hive.go/events"
"github.com/iotaledger/hive.go/node" "github.com/iotaledger/hive.go/node"
"golang.org/x/net/context" "golang.org/x/net/context"
"golang.org/x/net/websocket" "golang.org/x/net/websocket"
...@@ -22,17 +21,14 @@ func Configure(plugin *node.Plugin) { ...@@ -22,17 +21,14 @@ func Configure(plugin *node.Plugin) {
router.Handle("/datastream", websocket.Handler(dataStream)) router.Handle("/datastream", websocket.Handler(dataStream))
router.HandleFunc("/", index) router.HandleFunc("/", index)
daemon.Events.Shutdown.Attach(events.NewClosure(func() {
ctx, cancel := context.WithTimeout(context.Background(), 0*time.Second)
defer cancel()
httpServer.Shutdown(ctx)
}))
} }
func Run(plugin *node.Plugin) { func Run(plugin *node.Plugin) {
daemon.BackgroundWorker("Analysis HTTP Server", func(shutdownSignal <-chan struct{}) { daemon.BackgroundWorker("Analysis HTTP Server", func(shutdownSignal <-chan struct{}) {
httpServer.ListenAndServe() go httpServer.ListenAndServe()
<-shutdownSignal
ctx, cancel := context.WithTimeout(context.Background(), 0*time.Second)
defer cancel()
httpServer.Shutdown(ctx)
}) })
} }
...@@ -23,16 +23,6 @@ func configure(plugin *node.Plugin) { ...@@ -23,16 +23,6 @@ func configure(plugin *node.Plugin) {
Events.Error.Attach(events.NewClosure(func(err errors.IdentifiableError) { Events.Error.Attach(events.NewClosure(func(err errors.IdentifiableError) {
log.Error(err.Error()) log.Error(err.Error())
})) }))
daemon.Events.Shutdown.Attach(events.NewClosure(func() {
log.Info("Stopping Bundle Processor ...")
workerPool.Stop()
log.Info("Stopping Value Bundle Processor ...")
valueBundleProcessorWorkerPool.Stop()
}))
} }
func run(plugin *node.Plugin) { func run(plugin *node.Plugin) {
...@@ -40,7 +30,10 @@ func run(plugin *node.Plugin) { ...@@ -40,7 +30,10 @@ func run(plugin *node.Plugin) {
daemon.BackgroundWorker("Bundle Processor", func(shutdownSignal <-chan struct{}) { daemon.BackgroundWorker("Bundle Processor", func(shutdownSignal <-chan struct{}) {
log.Info("Starting Bundle Processor ... done") log.Info("Starting Bundle Processor ... done")
workerPool.Run() workerPool.Start()
<-shutdownSignal
log.Info("Stopping Bundle Processor ...")
workerPool.Stop()
log.Info("Stopping Bundle Processor ... done") log.Info("Stopping Bundle Processor ... done")
}) })
...@@ -48,7 +41,10 @@ func run(plugin *node.Plugin) { ...@@ -48,7 +41,10 @@ func run(plugin *node.Plugin) {
daemon.BackgroundWorker("Value Bundle Processor", func(shutdownSignal <-chan struct{}) { daemon.BackgroundWorker("Value Bundle Processor", func(shutdownSignal <-chan struct{}) {
log.Info("Starting Value Bundle Processor ... done") log.Info("Starting Value Bundle Processor ... done")
valueBundleProcessorWorkerPool.Run() valueBundleProcessorWorkerPool.Start()
<-shutdownSignal
log.Info("Stopping Value Bundle Processor ...")
valueBundleProcessorWorkerPool.Stop()
log.Info("Stopping Value Bundle Processor ... done") log.Info("Stopping Value Bundle Processor ... done")
}) })
} }
...@@ -33,13 +33,6 @@ func configure(plugin *node.Plugin) { ...@@ -33,13 +33,6 @@ func configure(plugin *node.Plugin) {
TPSQ = TPSQ[1:] TPSQ = TPSQ[1:]
} }
})) }))
daemon.Events.Shutdown.Attach(events.NewClosure(func() {
ctx, cancel := context.WithTimeout(context.Background(), 0*time.Second)
defer cancel()
_ = server.Shutdown(ctx)
}))
} }
func run(plugin *node.Plugin) { func run(plugin *node.Plugin) {
...@@ -49,5 +42,10 @@ func run(plugin *node.Plugin) { ...@@ -49,5 +42,10 @@ func run(plugin *node.Plugin) {
log.Error(err.Error()) log.Error(err.Error())
} }
}() }()
<-shutdownSignal
ctx, cancel := context.WithTimeout(context.Background(), 0*time.Second)
defer cancel()
_ = server.Shutdown(ctx)
}) })
} }
...@@ -36,14 +36,14 @@ func configure(plugin *node.Plugin) { ...@@ -36,14 +36,14 @@ func configure(plugin *node.Plugin) {
}) })
logger.Events.AnyMsg.Attach(anyLogMsgClosure) logger.Events.AnyMsg.Attach(anyLogMsgClosure)
daemon.Events.Shutdown.Attach(events.NewClosure(func() { daemon.BackgroundWorker("UI-Detach", func(shutdownSignal <-chan struct{}) {
<-shutdownSignal
logger.InjectWriters(os.Stdout) logger.InjectWriters(os.Stdout)
logger.Events.AnyMsg.Detach(anyLogMsgClosure) logger.Events.AnyMsg.Detach(anyLogMsgClosure)
if app != nil { if app != nil {
app.Stop() app.Stop()
} }
})) }, 1)
} }
func run(plugin *node.Plugin) { func run(plugin *node.Plugin) {
......
...@@ -44,11 +44,6 @@ func configureSolidifier(plugin *node.Plugin) { ...@@ -44,11 +44,6 @@ func configureSolidifier(plugin *node.Plugin) {
workerPool.Submit(metaTx) workerPool.Submit(metaTx)
})) }))
daemon.Events.Shutdown.Attach(events.NewClosure(func() {
log.Info("Stopping Solidifier ...")
workerPool.Stop()
}))
} }
func runSolidifier(plugin *node.Plugin) { func runSolidifier(plugin *node.Plugin) {
...@@ -56,7 +51,10 @@ func runSolidifier(plugin *node.Plugin) { ...@@ -56,7 +51,10 @@ func runSolidifier(plugin *node.Plugin) {
daemon.BackgroundWorker("Tangle Solidifier", func(shutdownSignal <-chan struct{}) { daemon.BackgroundWorker("Tangle Solidifier", func(shutdownSignal <-chan struct{}) {
log.Info("Starting Solidifier ... done") log.Info("Starting Solidifier ... done")
workerPool.Run() workerPool.Start()
<-shutdownSignal
log.Info("Stopping Solidifier ...")
workerPool.Stop()
log.Info("Stopping Solidifier ... done") log.Info("Stopping Solidifier ... done")
}) })
} }
......
...@@ -5,7 +5,6 @@ import ( ...@@ -5,7 +5,6 @@ import (
"time" "time"
"github.com/iotaledger/hive.go/daemon" "github.com/iotaledger/hive.go/daemon"
"github.com/iotaledger/hive.go/events"
"github.com/iotaledger/hive.go/logger" "github.com/iotaledger/hive.go/logger"
"github.com/iotaledger/hive.go/node" "github.com/iotaledger/hive.go/node"
"github.com/labstack/echo" "github.com/labstack/echo"
...@@ -20,17 +19,6 @@ func configure(plugin *node.Plugin) { ...@@ -20,17 +19,6 @@ func configure(plugin *node.Plugin) {
Server.HideBanner = true Server.HideBanner = true
Server.HidePort = true Server.HidePort = true
Server.GET("/", IndexRequest) Server.GET("/", IndexRequest)
daemon.Events.Shutdown.Attach(events.NewClosure(func() {
log.Info("Stopping Web Server ...")
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second)
defer cancel()
if err := Server.Shutdown(ctx); err != nil {
log.Errorf("Couldn't stop server cleanly: %s", err.Error())
}
}))
} }
func run(plugin *node.Plugin) { func run(plugin *node.Plugin) {
...@@ -39,8 +27,20 @@ func run(plugin *node.Plugin) { ...@@ -39,8 +27,20 @@ func run(plugin *node.Plugin) {
daemon.BackgroundWorker("WebAPI Server", func(shutdownSignal <-chan struct{}) { daemon.BackgroundWorker("WebAPI Server", func(shutdownSignal <-chan struct{}) {
log.Info("Starting Web Server ... done") log.Info("Starting Web Server ... done")
go func() {
if err := Server.Start(":8080"); err != nil { if err := Server.Start(":8080"); err != nil {
log.Info("Stopping Web Server ... done") log.Info("Stopping Web Server ... done")
} }
}()
<-shutdownSignal
log.Info("Stopping Web Server ...")
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second)
defer cancel()
if err := Server.Shutdown(ctx); err != nil {
log.Errorf("Couldn't stop server cleanly: %s", err.Error())
}
}) })
} }
...@@ -22,17 +22,6 @@ var emptyTag = strings.Repeat("9", 27) ...@@ -22,17 +22,6 @@ var emptyTag = strings.Repeat("9", 27)
// Configure the zeromq plugin // Configure the zeromq plugin
func configure(plugin *node.Plugin) { func configure(plugin *node.Plugin) {
daemon.Events.Shutdown.Attach(events.NewClosure(func() {
log.Info("Stopping ZeroMQ Publisher ...")
if err := publisher.Shutdown(); err != nil {
log.Errorf("Stopping ZeroMQ Publisher: %s", err.Error())
} else {
log.Info("Stopping ZeroMQ Publisher ... done")
}
}))
tangle.Events.TransactionStored.Attach(events.NewClosure(func(tx *value_transaction.ValueTransaction) { tangle.Events.TransactionStored.Attach(events.NewClosure(func(tx *value_transaction.ValueTransaction) {
// create goroutine for every event // create goroutine for every event
go func() { go func() {
...@@ -54,6 +43,15 @@ func run(plugin *node.Plugin) { ...@@ -54,6 +43,15 @@ func run(plugin *node.Plugin) {
} else { } else {
log.Infof("Starting ZeroMQ Publisher (port %d) ... done", zeromqPort) log.Infof("Starting ZeroMQ Publisher (port %d) ... done", zeromqPort)
} }
<-shutdownSignal
log.Info("Stopping ZeroMQ Publisher ...")
if err := publisher.Shutdown(); err != nil {
log.Errorf("Stopping ZeroMQ Publisher: %s", err.Error())
} else {
log.Info("Stopping ZeroMQ Publisher ... done")
}
}) })
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment