MusicDB Websocket Server¶
This is the main module to run the MusicDB Server.
To start and run the server, the following sequence of function calls is necessary:
Initialize(mdbconfig, musicdatabase) StartWebSocketServer() Run()
This module maintain global instances of the following classes.
Those objects can be used inside the thread the server runs.
Usually the main thread.
Using these objects saves a lot of memory.
If the server is not started, the objects are all None
.
- musicdb.mdbapi.server.Initialize(configobj, databaseobj)[source]¶
This function initializes the whole server. It initializes lots of global objects that get shared between multiple connections.
The following things happen when this method gets called:
Assign the configobj and databaseobj to global variables
cfg
anddatabase
to share them between multiple connectionsSeed Python’s random number generator
Instantiate a global
musicdb.mdbapi.mise.MusicDBMicroSearchEngine()
objectStarting the upload, integration and import management via
musicdb.taskmanagement.managementthread.StartTaskManagementThread()
Start the Audio Streaming Thread via
musicdb.mdbapi.audiostream.StartAudioStreamingThread()
(see Audio Streaming Server for details)Start the Video Streaming Thread via
musicdb.mdbapi.videostream.StartVideoStreamingThread()
(see Audio Streaming Server for details)Update MiSE cache via
musicdb.mdbapi.mise.MusicDBMicroSearchEngine.UpdateCache()
- Parameters
configobj –
MusicDBConfig
that gets shared between connectionsdatabaseobj –
MusicDatabase
that gets shared between connections
- Returns
None
- Raises
TypeError – When configobj is not of type
MusicDBConfig
TypeError – When databaseobj is not of type
MusicDatabase
- musicdb.mdbapi.server.Run()[source]¶
This is the servers main loop.
Inside the loop all MusicDB Websocket Server events get handled by calling
musicdb.lib.ws.server.MusicDBWebSocketServer.HandleEvents()
. When a shutdown gets triggered theShutdown()
function gets called and the server stops.The
Shutdown()
gets also called the user presses Ctrl-C This leads to a regular shutdown.In as an exception occurs the
Shutdown()
gets called, too. In this case the exit-code will be1
.
- musicdb.mdbapi.server.SIGTERM_Handler()[source]¶
This function is the handler for the system signal TERM. It signals the server to shut down.
- musicdb.mdbapi.server.Shutdown()[source]¶
This function stops the server and all its dependent threads.
The following things happen when this function gets called:
Stopping task management via
musicdb.taskmanagement.managementthread.StopTaskManagementThread()
Stop the Audio Streaming Thread via
musicdb.mdbapi.audiostream.StopAudioStreamingThread()
Stop the Video Streaming Thread via
musicdb.mdbapi.videostream.StopVideoStreamingThread()
Stop the websocket server
At the end, the program gets terminated. So, this function gets never left.
The exit code will be
0
if this was a regular shutdown. If the shutdown got forced, for example due to a critical error, the exit code is1
.This function should also be called when
Initialize()
fails or when it raises an exception.
- musicdb.mdbapi.server.SignalHandler(signum, stack)[source]¶
This is the general signal handle for the MusicDB Server. This function reacts on system signals and calls the handler of a specific signal.
- Parameters
signum – signal number
stack – current stack frame
Returns: Nothing
- musicdb.mdbapi.server.StartWebSocketServer()[source]¶
This function creates and starts the actual MusicDB Websocket Server.
- Returns
True
on success, otherwiseFalse
- musicdb.mdbapi.server.UpdateCaches()[source]¶
This function handles the signal to refresh the server cache. Its task is to trigger updating the servers cache and to inform the clients to update.
On server side:
The MiSE Cache gets updated by calling
musicdb.mdbapi.mise.MusicDBMicroSearchEngine.UpdateCache()
To inform the clients a broadcast packet get sent with the following content:
{method:"broadcast", fncname:"sys:refresh", fncsig:"UpdateCaches", arguments:null, pass:null}
Example
if(fnc == "sys:refresh" && sig == "UpdateCaches") { MusicDB_Request("GetTags", "UpdateTagsCache"); // Update tag cache MusicDB_Request("GetFilteredArtistsWithAlbums", "ShowArtists"); // Update artist view }