Skip to content
Snippets Groups Projects
Commit f435e9b3 authored by Steven Murray's avatar Steven Murray
Browse files

Introduced the singleton pattern to enforce that there can only be one copy of...

Introduced the singleton pattern to enforce that there can only be one copy of the aggregatord daemon in a single process
parent e78fcf23
Branches
Tags
No related merge requests found
......@@ -39,6 +39,13 @@
#include <memory>
//------------------------------------------------------------------------------
// s_instance
//------------------------------------------------------------------------------
castor::tape::aggregator::AggregatorDaemon
castor::tape::aggregator::AggregatorDaemon::s_instance;
//------------------------------------------------------------------------------
// constructor
//------------------------------------------------------------------------------
......
......@@ -49,11 +49,11 @@ class AggregatorDaemon : public castor::server::BaseDaemon {
public:
/**
* Constructor.
*
* @param daemonName The name of the daemon.
* Returns a reference to the single instance of the daemon.
*/
AggregatorDaemon() throw(castor::exception::Exception);
static AggregatorDaemon &instance() throw() {
return s_instance;
}
/**
* Destructor.
......@@ -68,6 +68,18 @@ public:
private:
/**
* Private static member used to implement the singleton pattern without
* using the heap.
*/
static AggregatorDaemon s_instance;
/**
* Private constructor to enforce only one instance of the daemon can be
* instantiate via the instance() method of the singleton patten.
*/
AggregatorDaemon() throw(castor::exception::Exception);
/**
* Exception throwing main() function which basically implements the
* non-exception throwing main() function except for the initialisation of
......
......@@ -32,7 +32,7 @@
//------------------------------------------------------------------------------
int main(int argc, char **argv) {
castor::tape::aggregator::AggregatorDaemon daemon;
using namespace castor::tape::aggregator;
return daemon.main(argc, argv);
return AggregatorDaemon::instance().main(argc, argv);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment