github.com/cloud-foundations/dominator@v0.0.0-20221004181915-6e4fee580046/lib/mdb/mdbd/api.go (about)

     1  /*
     2  	Package mdbd implements a simple MDB watcher.
     3  
     4  	Package mdbd may be used to read MDB data from a file or remote server and
     5  	watch for updates.
     6  */
     7  package mdbd
     8  
     9  import (
    10  	"flag"
    11  
    12  	"github.com/Cloud-Foundations/Dominator/lib/constants"
    13  	"github.com/Cloud-Foundations/Dominator/lib/log"
    14  	"github.com/Cloud-Foundations/Dominator/lib/mdb"
    15  )
    16  
    17  var (
    18  	mdbServerHostname = flag.String("mdbServerHostname", "",
    19  		"Hostname of remote MDB server to get MDB updates from")
    20  	mdbServerPortNum = flag.Uint("mdbServerPortNum",
    21  		constants.SimpleMdbServerPortNumber, "Port number of MDB server")
    22  )
    23  
    24  // StartMdbDaemon starts an in-process "daemon" goroutine which watches for MDB
    25  // updates. At startup it will read the file named by mdbFileName for MDB data.
    26  // The default format is JSON, but if the filename extension is ".gob" then GOB
    27  // format is read. If the file is present and contains MDB data, the MDB data
    28  // are sent over the returned channel, otherwise no MDB data are sent initially.
    29  //
    30  // By default the file is monitored for updates and if the file is replaced by a
    31  // different inode, MDB data are read from the new inode. If the MDB data are
    32  // different than previously read, they are sent over the channel. This mode of
    33  // operation is designed for consuming MDB data via the file-system from a local
    34  // mdbd daemon.
    35  //
    36  // Alternatively, if a remote MDB server is specified with the
    37  // -mdbServerHostname and -mdbServerPortNum command-line flags then the remote
    38  // MDB server is queried for MDB data. As MDB updates are received they are
    39  // saved in the file and sent over the channel. In this mode of operation the
    40  // file is read only once at startup. The file acts as a local cache of the MDB
    41  // data received from the server, in case the MDB server is not available at
    42  // a subsequent restart of the application.
    43  //
    44  // The logger will be used to log problems.
    45  func StartMdbDaemon(mdbFileName string, logger log.Logger) <-chan *mdb.Mdb {
    46  	return startMdbDaemon(mdbFileName, logger)
    47  }