Add documentation

This commit is contained in:
Thorsten Sommer committed 2015-06-17 17:44:52 +02:00
1 parent 69d0bdabf4
commit 6dab89a1d4
144 files changed
+1107 -549

No files matched your search

+1
View File
@@ -1,5 +1,6 @@
package Shutdown
// A function to check if the system goes down right now.
func IsDown() (result bool) {
result = stopAllRequests
return
+4
View File
@@ -6,13 +6,17 @@ import (
"os/signal"
)
// Init the package.
func init() {
shutdownHandlers = list.New()
}
// The manual init for the shutdown notify handler.
func InitShutdown() {
// Apply the shutdown handler:
signal.Notify(shutdownSignal, os.Interrupt, os.Kill)
// Start a new thread which waits for the shutdown event:
go executeShutdown()
}
+11 -1
View File
@@ -8,28 +8,38 @@ import (
"os"
)
// A type for shutdown handlers.
type ShutdownHandler interface {
Shutdown()
}
// Function to add new shutdown handlers.
func AddShutdownHandler(handler ShutdownHandler) {
shutdownHandlers.PushFront(handler)
}
// The thread which waits for the shutdown event.
func executeShutdown() {
// Wait for the shutdown event:
sig := <-shutdownSignal
stopAllRequests = true
Log.LogFull(senderName, LM.CategorySYSTEM, LM.LevelWARN, LM.SeverityCritical, LM.ImpactCritical, LM.MessageNameSHUTDOWN, `The system was called to shutting down.`, sig.String(), `Call now all shutdown handlers.`)
// Execute all shutdown handlers:
for handler := shutdownHandlers.Front(); handler != nil; handler = handler.Next() {
safeCall(handler)
}
// Shutdown the logging system:
Log.LogFull(senderName, LM.CategorySYSTEM, LM.LevelWARN, LM.SeverityCritical, LM.ImpactCritical, LM.MessageNameSHUTDOWN, `The system is shutting down now.`)
Log.Flush()
// Stop the whole server:
os.Exit(0)
}
// This function is a wrapper to call safely a shutdown handler.
func safeCall(handler *list.Element) {
defer func() {
if err := recover(); err != nil {
+4 -4
View File
@@ -7,8 +7,8 @@ import (
)
var (
shutdownSignal chan os.Signal = make(chan os.Signal)
shutdownHandlers *list.List = nil
senderName LM.Sender = `System::Shutdown`
stopAllRequests bool = false
shutdownSignal chan os.Signal = make(chan os.Signal) // A channel for the shutdown event
shutdownHandlers *list.List = nil // All shutdown handlers
senderName LM.Sender = `System::Shutdown` // This is the name for logging event from this package
stopAllRequests bool = false // Does the system goes down now?
)