From 053dba088d8d536b0a54484b9ec6d5df59861126 Mon Sep 17 00:00:00 2001 From: Frank Celler Date: Tue, 3 Jan 2012 19:00:49 +0100 Subject: [PATCH] cleanup --- Dispatcher/ApplicationServerDispatcher.cpp | 44 ++++ Dispatcher/ApplicationServerDispatcher.h | 87 ++++++++ .../ApplicationServerDispatcherImpl.cpp | 208 ++++++++++++++++++ Dispatcher/ApplicationServerDispatcherImpl.h | 139 ++++++++++++ Dispatcher/Dispatcher.h | 117 ++++++++++ Dispatcher/DispatcherImpl.cpp | 6 +- Dispatcher/DispatcherImpl.h | 3 +- Dispatcher/DispatcherQueue.cpp | 2 +- Dispatcher/DispatcherQueue.h | 2 +- Dispatcher/DispatcherThread.cpp | 6 +- Dispatcher/DispatcherThread.h | 3 +- Dispatcher/Job.cpp | 41 ++++ Dispatcher/Job.h | 151 +++++++++++++ 13 files changed, 799 insertions(+), 10 deletions(-) create mode 100644 Dispatcher/ApplicationServerDispatcher.cpp create mode 100644 Dispatcher/ApplicationServerDispatcher.h create mode 100644 Dispatcher/ApplicationServerDispatcherImpl.cpp create mode 100644 Dispatcher/ApplicationServerDispatcherImpl.h create mode 100644 Dispatcher/Dispatcher.h create mode 100644 Dispatcher/Job.cpp create mode 100644 Dispatcher/Job.h diff --git a/Dispatcher/ApplicationServerDispatcher.cpp b/Dispatcher/ApplicationServerDispatcher.cpp new file mode 100644 index 0000000000..9ec21e4e5e --- /dev/null +++ b/Dispatcher/ApplicationServerDispatcher.cpp @@ -0,0 +1,44 @@ +//////////////////////////////////////////////////////////////////////////////// +/// @brief application server with dispatcher +/// +/// @file +/// +/// DISCLAIMER +/// +/// Copyright 2010-2011 triagens GmbH, Cologne, Germany +/// +/// Licensed under the Apache License, Version 2.0 (the "License"); +/// you may not use this file except in compliance with the License. +/// You may obtain a copy of the License at +/// +/// http://www.apache.org/licenses/LICENSE-2.0 +/// +/// Unless required by applicable law or agreed to in writing, software +/// distributed under the License is distributed on an "AS IS" BASIS, +/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +/// See the License for the specific language governing permissions and +/// limitations under the License. +/// +/// Copyright holder is triAGENS GmbH, Cologne, Germany +/// +/// @author Dr. Frank Celler +/// @author Copyright 2009-2011, triAGENS GmbH, Cologne, Germany +//////////////////////////////////////////////////////////////////////////////// + +#include "ApplicationServerDispatcher.h" + +#include "Dispatcher/ApplicationServerDispatcherImpl.h" + +namespace triagens { + namespace rest { + + // ----------------------------------------------------------------------------- + // constructors and destructors + // ----------------------------------------------------------------------------- + + ApplicationServerDispatcher* ApplicationServerDispatcher::create (string const& description, string const& version) { + return new ApplicationServerDispatcherImpl(description, version); + } + } +} + diff --git a/Dispatcher/ApplicationServerDispatcher.h b/Dispatcher/ApplicationServerDispatcher.h new file mode 100644 index 0000000000..dab86d0082 --- /dev/null +++ b/Dispatcher/ApplicationServerDispatcher.h @@ -0,0 +1,87 @@ +//////////////////////////////////////////////////////////////////////////////// +/// @brief application server with dispatcher +/// +/// @file +/// +/// DISCLAIMER +/// +/// Copyright 2010-2011 triagens GmbH, Cologne, Germany +/// +/// Licensed under the Apache License, Version 2.0 (the "License"); +/// you may not use this file except in compliance with the License. +/// You may obtain a copy of the License at +/// +/// http://www.apache.org/licenses/LICENSE-2.0 +/// +/// Unless required by applicable law or agreed to in writing, software +/// distributed under the License is distributed on an "AS IS" BASIS, +/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +/// See the License for the specific language governing permissions and +/// limitations under the License. +/// +/// Copyright holder is triAGENS GmbH, Cologne, Germany +/// +/// @author Dr. Frank Celler +/// @author Copyright 2009-2011, triAGENS GmbH, Cologne, Germany +//////////////////////////////////////////////////////////////////////////////// + +#ifndef TRIAGENS_FYN_REST_APPLICATION_SERVER_DISPATCHER_H +#define TRIAGENS_FYN_REST_APPLICATION_SERVER_DISPATCHER_H 1 + +#include "ApplicationServer/ApplicationServer.h" + +namespace triagens { + namespace rest { + class Dispatcher; + + //////////////////////////////////////////////////////////////////////////////// + /// @brief application server with dispatcher + //////////////////////////////////////////////////////////////////////////////// + + class ApplicationServerDispatcher : virtual public ApplicationServer { + public: + + //////////////////////////////////////////////////////////////////////////////// + /// @brief constructs a new skeleton + //////////////////////////////////////////////////////////////////////////////// + + static ApplicationServerDispatcher* create (string const& description, string const& version); + + public: + + //////////////////////////////////////////////////////////////////////////////// + /// @brief returns the dispatcher + //////////////////////////////////////////////////////////////////////////////// + + virtual Dispatcher* dispatcher () const = 0; + + //////////////////////////////////////////////////////////////////////////////// + /// @brief builds the dispatcher + //////////////////////////////////////////////////////////////////////////////// + + virtual void buildDispatcher () = 0; + + //////////////////////////////////////////////////////////////////////////////// + /// @brief builds the dispatcher reporter + //////////////////////////////////////////////////////////////////////////////// + + virtual void buildDispatcherReporter () = 0; + + //////////////////////////////////////////////////////////////////////////////// + /// @brief builds the dispatcher queue + //////////////////////////////////////////////////////////////////////////////// + + virtual void buildStandardQueue (size_t nrThreads) = 0; + + //////////////////////////////////////////////////////////////////////////////// + /// @brief builds the named dispatcher queue + //////////////////////////////////////////////////////////////////////////////// + + virtual void buildNamedQueue (string const& name, size_t nrThreads) = 0; + }; + } +} + +#endif + + diff --git a/Dispatcher/ApplicationServerDispatcherImpl.cpp b/Dispatcher/ApplicationServerDispatcherImpl.cpp new file mode 100644 index 0000000000..551cd0b217 --- /dev/null +++ b/Dispatcher/ApplicationServerDispatcherImpl.cpp @@ -0,0 +1,208 @@ +//////////////////////////////////////////////////////////////////////////////// +/// @brief application server dispatcher implementation +/// +/// @file +/// +/// DISCLAIMER +/// +/// Copyright 2010-2011 triagens GmbH, Cologne, Germany +/// +/// Licensed under the Apache License, Version 2.0 (the "License"); +/// you may not use this file except in compliance with the License. +/// You may obtain a copy of the License at +/// +/// http://www.apache.org/licenses/LICENSE-2.0 +/// +/// Unless required by applicable law or agreed to in writing, software +/// distributed under the License is distributed on an "AS IS" BASIS, +/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +/// See the License for the specific language governing permissions and +/// limitations under the License. +/// +/// Copyright holder is triAGENS GmbH, Cologne, Germany +/// +/// @author Dr. Frank Celler +/// @author Copyright 2009-2011, triAGENS GmbH, Cologne, Germany +//////////////////////////////////////////////////////////////////////////////// + +#include "ApplicationServerDispatcherImpl.h" + +#include + +#include "Dispatcher/DispatcherImpl.h" +#include "Dispatcher/DispatcherQueue.h" +#include "Scheduler/PeriodicTask.h" +#include "Scheduler/Scheduler.h" + +using namespace std; +using namespace triagens::basics; +using namespace triagens::rest; + +// ----------------------------------------------------------------------------- +// helper classes and methods +// ----------------------------------------------------------------------------- + +namespace { + + //////////////////////////////////////////////////////////////////////////////// + /// @brief produces a dispatcher status report + //////////////////////////////////////////////////////////////////////////////// + + class DispatcherReporterTask : public PeriodicTask { + public: + DispatcherReporterTask (Dispatcher* dispatcher, double reportIntervall) + : Task("Dispatcher-Reporter"), PeriodicTask(reportIntervall * 0., reportIntervall), dispatcher(dispatcher) { + } + + public: + bool handlePeriod () { + dispatcher->reportStatus(); + return true; + } + + public: + Dispatcher* dispatcher; + }; +} + +namespace triagens { + namespace rest { + + // ----------------------------------------------------------------------------- + // constructors and destructors + // ----------------------------------------------------------------------------- + + ApplicationServerDispatcherImpl::ApplicationServerDispatcherImpl (string const& description, string const& version) + : ApplicationServerSchedulerImpl(description, version), + _dispatcher(0), + _dispatcherReporterTask(0) { + } + + + + ApplicationServerDispatcherImpl::~ApplicationServerDispatcherImpl () { + if (_dispatcher != 0) { + delete _dispatcher; + } + } + + // ----------------------------------------------------------------------------- + // public methods + // ----------------------------------------------------------------------------- + + void ApplicationServerDispatcherImpl::buildDispatcher () { + if (_dispatcher != 0) { + LOGGER_FATAL << "a dispatcher has already been created"; + exit(EXIT_FAILURE); + } + + _dispatcher = new DispatcherImpl(); + } + + + + void ApplicationServerDispatcherImpl::buildDispatcherReporter () { + if (_dispatcher == 0) { + LOGGER_FATAL << "no dispatcher is known, cannot create dispatcher reporter"; + exit(EXIT_FAILURE); + } + + if (0.0 < _reportIntervall) { + _dispatcherReporterTask = new DispatcherReporterTask(_dispatcher, _reportIntervall); + + registerTask(_dispatcherReporterTask); + } + } + + + + void ApplicationServerDispatcherImpl::buildStandardQueue (size_t nrThreads) { + if (_dispatcher == 0) { + LOGGER_FATAL << "no dispatcher is known, cannot create dispatcher queue"; + exit(EXIT_FAILURE); + } + + LOGGER_TRACE << "setting up a standard queue with " << nrThreads << " threads "; + + _dispatcher->addQueue("STANDARD", nrThreads); + } + + + + void ApplicationServerDispatcherImpl::buildNamedQueue (string const& name, size_t nrThreads) { + if (_dispatcher == 0) { + LOGGER_FATAL << "no dispatcher is known, cannot create dispatcher queue"; + exit(EXIT_FAILURE); + } + + LOGGER_TRACE << "setting up a named queue '" << name << "' with " << nrThreads << " threads "; + + _dispatcher->addQueue(name, nrThreads); + } + + + + void ApplicationServerDispatcherImpl::start () { + ApplicationServerSchedulerImpl::start(); + + if (_dispatcher != 0) { + bool ok = _dispatcher->start(); + + if (! ok) { + LOGGER_FATAL << "cannot start dispatcher"; + exit(EXIT_FAILURE); + } + } + } + + + + void ApplicationServerDispatcherImpl::wait () { + ApplicationServerSchedulerImpl::wait(); + + if (_dispatcher != 0) { + while (_dispatcher->isRunning()) { + LOGGER_TRACE << "waiting for dispatcher to stop"; + + usleep(10000); + } + + LOGGER_TRACE << "dispatcher has stopped"; + } + } + + + + void ApplicationServerDispatcherImpl::beginShutdown () { + ApplicationServerSchedulerImpl::beginShutdown(); + + if (_dispatcher != 0) { + _dispatcher->beginShutdown(); + } + } + + + + void ApplicationServerDispatcherImpl::shutdown () { + ApplicationServerSchedulerImpl::shutdown(); + + if (_dispatcher != 0) { + int count = 0; + + while (++count < 6 && _dispatcher->isRunning()) { + LOGGER_TRACE << "waiting for dispatcher to stop"; + sleep(1); + } + } + } + } +} + + + + + + + + + diff --git a/Dispatcher/ApplicationServerDispatcherImpl.h b/Dispatcher/ApplicationServerDispatcherImpl.h new file mode 100644 index 0000000000..3626f30b7e --- /dev/null +++ b/Dispatcher/ApplicationServerDispatcherImpl.h @@ -0,0 +1,139 @@ +//////////////////////////////////////////////////////////////////////////////// +/// @brief application server dispatcher implementation +/// +/// @file +/// +/// DISCLAIMER +/// +/// Copyright 2010-2011 triagens GmbH, Cologne, Germany +/// +/// Licensed under the Apache License, Version 2.0 (the "License"); +/// you may not use this file except in compliance with the License. +/// You may obtain a copy of the License at +/// +/// http://www.apache.org/licenses/LICENSE-2.0 +/// +/// Unless required by applicable law or agreed to in writing, software +/// distributed under the License is distributed on an "AS IS" BASIS, +/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +/// See the License for the specific language governing permissions and +/// limitations under the License. +/// +/// Copyright holder is triAGENS GmbH, Cologne, Germany +/// +/// @author Dr. Frank Celler +/// @author Copyright 2009-2011, triAGENS GmbH, Cologne, Germany +//////////////////////////////////////////////////////////////////////////////// + +#ifndef TRIAGENS_FYN_APPLICATION_SERVER_APPLICATION_SERVER_DISPATCHER_IMPL_H +#define TRIAGENS_FYN_APPLICATION_SERVER_APPLICATION_SERVER_DISPATCHER_IMPL_H 1 + +#include "ApplicationServer/ApplicationServerSchedulerImpl.h" + +#include "Dispatcher/ApplicationServerDispatcher.h" +#include "Dispatcher/Dispatcher.h" + +namespace triagens { + namespace rest { + + //////////////////////////////////////////////////////////////////////////////// + /// @brief application server dispatcher implementation + //////////////////////////////////////////////////////////////////////////////// + + class ApplicationServerDispatcherImpl : virtual public ApplicationServerSchedulerImpl, + virtual public ApplicationServerDispatcher { + ApplicationServerDispatcherImpl (ApplicationServerDispatcherImpl const&); + ApplicationServerDispatcherImpl& operator= (ApplicationServerDispatcherImpl const&); + + public: + + //////////////////////////////////////////////////////////////////////////////// + /// @brief constructor + //////////////////////////////////////////////////////////////////////////////// + + ApplicationServerDispatcherImpl (string const& description, string const& version); + + //////////////////////////////////////////////////////////////////////////////// + /// @brief destructor + //////////////////////////////////////////////////////////////////////////////// + + ~ApplicationServerDispatcherImpl (); + + public: + + //////////////////////////////////////////////////////////////////////////////// + /// {@inheritDoc} + //////////////////////////////////////////////////////////////////////////////// + + Dispatcher* dispatcher () const { + return _dispatcher; + } + + //////////////////////////////////////////////////////////////////////////////// + /// {@inheritDoc} + //////////////////////////////////////////////////////////////////////////////// + + void buildDispatcher (); + + //////////////////////////////////////////////////////////////////////////////// + /// {@inheritDoc} + //////////////////////////////////////////////////////////////////////////////// + + void buildDispatcherReporter (); + + //////////////////////////////////////////////////////////////////////////////// + /// {@inheritDoc} + //////////////////////////////////////////////////////////////////////////////// + + void buildStandardQueue (size_t nrThreads); + + //////////////////////////////////////////////////////////////////////////////// + /// {@inheritDoc} + //////////////////////////////////////////////////////////////////////////////// + + void buildNamedQueue (string const& name, size_t nrThreads); + + public: + + //////////////////////////////////////////////////////////////////////////////// + /// {@inheritDoc} + //////////////////////////////////////////////////////////////////////////////// + + void start (); + + //////////////////////////////////////////////////////////////////////////////// + /// {@inheritDoc} + //////////////////////////////////////////////////////////////////////////////// + + void wait (); + + //////////////////////////////////////////////////////////////////////////////// + /// {@inheritDoc} + //////////////////////////////////////////////////////////////////////////////// + + void beginShutdown (); + + //////////////////////////////////////////////////////////////////////////////// + /// {@inheritDoc} + //////////////////////////////////////////////////////////////////////////////// + + void shutdown (); + + protected: + + //////////////////////////////////////////////////////////////////////////////// + /// @brief scheduler + //////////////////////////////////////////////////////////////////////////////// + + Dispatcher* _dispatcher; + + //////////////////////////////////////////////////////////////////////////////// + /// @brief reporting task + //////////////////////////////////////////////////////////////////////////////// + + Task* _dispatcherReporterTask; + }; + } +} + +#endif diff --git a/Dispatcher/Dispatcher.h b/Dispatcher/Dispatcher.h new file mode 100644 index 0000000000..a7ecc07d93 --- /dev/null +++ b/Dispatcher/Dispatcher.h @@ -0,0 +1,117 @@ +//////////////////////////////////////////////////////////////////////////////// +/// @brief interface of a job dispatcher +/// +/// @file +/// +/// DISCLAIMER +/// +/// Copyright 2010-2011 triagens GmbH, Cologne, Germany +/// +/// Licensed under the Apache License, Version 2.0 (the "License"); +/// you may not use this file except in compliance with the License. +/// You may obtain a copy of the License at +/// +/// http://www.apache.org/licenses/LICENSE-2.0 +/// +/// Unless required by applicable law or agreed to in writing, software +/// distributed under the License is distributed on an "AS IS" BASIS, +/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +/// See the License for the specific language governing permissions and +/// limitations under the License. +/// +/// Copyright holder is triAGENS GmbH, Cologne, Germany +/// +/// @author Dr. Frank Celler +/// @author Martin Schoenert +/// @author Copyright 2009-2011, triAGENS GmbH, Cologne, Germany +//////////////////////////////////////////////////////////////////////////////// + +#ifndef TRIAGENS_FYN_REST_DISPATCHER_H +#define TRIAGENS_FYN_REST_DISPATCHER_H 1 + +#include + +//////////////////////////////////////////////////////////////////////////////// +/// @defgroup Dispatcher Job Dispatcher +//////////////////////////////////////////////////////////////////////////////// + +namespace triagens { + namespace rest { + class Job; + class DispatcherQueue; + class DispatcherThread; + + //////////////////////////////////////////////////////////////////////////////// + /// @ingroup Dispatcher + /// @brief interface of a job dispatcher + //////////////////////////////////////////////////////////////////////////////// + + class Dispatcher { + private: + Dispatcher (Dispatcher const&); + Dispatcher& operator= (Dispatcher const&); + + public: + + ///////////////////////////////////////////////////////////////////////// + /// @brief constructor + ///////////////////////////////////////////////////////////////////////// + + Dispatcher () { + } + + ///////////////////////////////////////////////////////////////////////// + /// @brief destructor + ///////////////////////////////////////////////////////////////////////// + + virtual ~Dispatcher () { + } + + public: + + ///////////////////////////////////////////////////////////////////////// + /// @brief is the dispatcher still running + ///////////////////////////////////////////////////////////////////////// + + virtual bool isRunning () = 0; + + ///////////////////////////////////////////////////////////////////////// + /// @brief adds a new queue + ///////////////////////////////////////////////////////////////////////// + + virtual void addQueue (string const& name, size_t nrThreads) = 0; + + ///////////////////////////////////////////////////////////////////////// + /// @brief adds a new job + /// + /// The method is called from the scheduler to add a new job request. + /// It returns immediately (i.e. without waiting for the job to finish). + /// When the job is finished the scheduler will be awoken and + /// the scheduler will write the response over the network to + /// the caller. + ///////////////////////////////////////////////////////////////////////// + + virtual bool addJob (Job*) = 0; + + ///////////////////////////////////////////////////////////////////////// + /// @brief start the dispatcher + ///////////////////////////////////////////////////////////////////////// + + virtual bool start () = 0; + + ///////////////////////////////////////////////////////////////////////// + /// @brief begins shutdown process + ///////////////////////////////////////////////////////////////////////// + + virtual void beginShutdown () = 0; + + ///////////////////////////////////////////////////////////////////////// + /// @brief reports status of dispatcher queues + ///////////////////////////////////////////////////////////////////////// + + virtual void reportStatus () = 0; + }; + } +} + +#endif diff --git a/Dispatcher/DispatcherImpl.cpp b/Dispatcher/DispatcherImpl.cpp index ae3ecd3375..fd2e6178f6 100644 --- a/Dispatcher/DispatcherImpl.cpp +++ b/Dispatcher/DispatcherImpl.cpp @@ -29,13 +29,13 @@ #include "DispatcherImpl.h" #include -#include +#include #include #include -#include #include "Dispatcher/DispatcherQueue.h" #include "Dispatcher/DispatcherThread.h" +#include "Dispatcher/Job.h" using namespace triagens::basics; @@ -160,7 +160,7 @@ namespace triagens { void DispatcherImpl::reportStatus () { - if (TRI_IsDebugLogging()) { + if (TRI_IsDebugLogging(__FILE__)) { MUTEX_LOCKER(accessDispatcher); for (map::iterator i = queues.begin(); i != queues.end(); ++i) { diff --git a/Dispatcher/DispatcherImpl.h b/Dispatcher/DispatcherImpl.h index 8edd5859ba..2f359c4731 100644 --- a/Dispatcher/DispatcherImpl.h +++ b/Dispatcher/DispatcherImpl.h @@ -31,9 +31,10 @@ #include -#include #include +#include "Dispatcher/Dispatcher.h" + namespace triagens { namespace rest { diff --git a/Dispatcher/DispatcherQueue.cpp b/Dispatcher/DispatcherQueue.cpp index eb07cc9801..04379f12fe 100644 --- a/Dispatcher/DispatcherQueue.cpp +++ b/Dispatcher/DispatcherQueue.cpp @@ -29,7 +29,7 @@ #include "DispatcherQueue.h" #include -#include +#include #include "Dispatcher/DispatcherThread.h" diff --git a/Dispatcher/DispatcherQueue.h b/Dispatcher/DispatcherQueue.h index 16dda01ad2..7bc6259180 100644 --- a/Dispatcher/DispatcherQueue.h +++ b/Dispatcher/DispatcherQueue.h @@ -32,8 +32,8 @@ #include #include -#include +#include "Dispatcher/Dispatcher.h" #include "Dispatcher/DispatcherImpl.h" namespace triagens { diff --git a/Dispatcher/DispatcherThread.cpp b/Dispatcher/DispatcherThread.cpp index 6c7c08ee01..dfcade5309 100644 --- a/Dispatcher/DispatcherThread.cpp +++ b/Dispatcher/DispatcherThread.cpp @@ -29,12 +29,12 @@ #include "DispatcherThread.h" #include -#include +#include #include -#include -#include +#include "Dispatcher/Dispatcher.h" #include "Dispatcher/DispatcherQueue.h" +#include "Dispatcher/Job.h" using namespace triagens::basics; diff --git a/Dispatcher/DispatcherThread.h b/Dispatcher/DispatcherThread.h index e7e9045d8a..a8b3337b8a 100644 --- a/Dispatcher/DispatcherThread.h +++ b/Dispatcher/DispatcherThread.h @@ -32,7 +32,8 @@ #include #include -#include + +#include "Dispatcher/Job.h" namespace triagens { namespace rest { diff --git a/Dispatcher/Job.cpp b/Dispatcher/Job.cpp new file mode 100644 index 0000000000..547ffdfbe3 --- /dev/null +++ b/Dispatcher/Job.cpp @@ -0,0 +1,41 @@ +//////////////////////////////////////////////////////////////////////////////// +/// @brief abstract base class for jobs +/// +/// @file +/// +/// DISCLAIMER +/// +/// Copyright 2010-2011 triagens GmbH, Cologne, Germany +/// +/// Licensed under the Apache License, Version 2.0 (the "License"); +/// you may not use this file except in compliance with the License. +/// You may obtain a copy of the License at +/// +/// http://www.apache.org/licenses/LICENSE-2.0 +/// +/// Unless required by applicable law or agreed to in writing, software +/// distributed under the License is distributed on an "AS IS" BASIS, +/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +/// See the License for the specific language governing permissions and +/// limitations under the License. +/// +/// Copyright holder is triAGENS GmbH, Cologne, Germany +/// +/// @author Dr. Frank Celler +/// @author Martin Schoenert +/// @author Copyright 2009-2011, triAGENS GmbH, Cologne, Germany +//////////////////////////////////////////////////////////////////////////////// + +#include "Job.h" + +namespace triagens { + namespace rest { + + // ----------------------------------------------------------------------------- + // public methods + // ----------------------------------------------------------------------------- + + void Job::setDispatcherThread (DispatcherThread*) { + } + } +} diff --git a/Dispatcher/Job.h b/Dispatcher/Job.h new file mode 100644 index 0000000000..f254e672ea --- /dev/null +++ b/Dispatcher/Job.h @@ -0,0 +1,151 @@ +//////////////////////////////////////////////////////////////////////////////// +/// @brief abstract base class for jobs +/// +/// @file +/// +/// DISCLAIMER +/// +/// Copyright 2010-2011 triagens GmbH, Cologne, Germany +/// +/// Licensed under the Apache License, Version 2.0 (the "License"); +/// you may not use this file except in compliance with the License. +/// You may obtain a copy of the License at +/// +/// http://www.apache.org/licenses/LICENSE-2.0 +/// +/// Unless required by applicable law or agreed to in writing, software +/// distributed under the License is distributed on an "AS IS" BASIS, +/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +/// See the License for the specific language governing permissions and +/// limitations under the License. +/// +/// Copyright holder is triAGENS GmbH, Cologne, Germany +/// +/// @author Dr. Frank Celler +/// @author Martin Schoenert +/// @author Copyright 2009-2011, triAGENS GmbH, Cologne, Germany +//////////////////////////////////////////////////////////////////////////////// + +#ifndef TRIAGENS_FYN_REST_JOB_H +#define TRIAGENS_FYN_REST_JOB_H 1 + +#include + +namespace triagens { + namespace basics { + class TriagensError; + } + + namespace rest { + class DispatcherThread; + + //////////////////////////////////////////////////////////////////////////////// + /// @ingroup Dispatcher + /// @brief abstract base class for jobs + //////////////////////////////////////////////////////////////////////////////// + + class Job { + private: + Job (Job const&); + Job& operator= (Job const&); + + public: + + //////////////////////////////////////////////////////////////////////////////// + /// @brief job types + //////////////////////////////////////////////////////////////////////////////// + + enum JobType { + READ_JOB, + WRITE_JOB, + SPECIAL_JOB + }; + + //////////////////////////////////////////////////////////////////////////////// + /// @brief status of execution + //////////////////////////////////////////////////////////////////////////////// + + enum status_e { + JOB_DONE, + JOB_REQUEUE, + JOB_FAILED + }; + + public: + + //////////////////////////////////////////////////////////////////////////////// + /// @brief constructs a job + //////////////////////////////////////////////////////////////////////////////// + + explicit + Job (string const& name) + : name(name) { + } + + //////////////////////////////////////////////////////////////////////////////// + /// @brief deletes the job + //////////////////////////////////////////////////////////////////////////////// + + virtual ~Job () { + } + + public: + + //////////////////////////////////////////////////////////////////////////////// + /// @brief gets the type of the job + /// + /// Note that initialise can change the job type. + //////////////////////////////////////////////////////////////////////////////// + + virtual JobType type () = 0; + + //////////////////////////////////////////////////////////////////////////////// + /// @brief returns the queue name to use + //////////////////////////////////////////////////////////////////////////////// + + virtual string const& queue () { + static string standard = "STANDARD"; + return standard; + } + + //////////////////////////////////////////////////////////////////////////////// + /// @brief sets the thread which currently dealing with the job + //////////////////////////////////////////////////////////////////////////////// + + virtual void setDispatcherThread (DispatcherThread*); + + //////////////////////////////////////////////////////////////////////////////// + /// @brief starts working + //////////////////////////////////////////////////////////////////////////////// + + virtual status_e work () = 0; + + //////////////////////////////////////////////////////////////////////////////// + /// @brief cleans up after work and delete + //////////////////////////////////////////////////////////////////////////////// + + virtual void cleanup () = 0; + + //////////////////////////////////////////////////////////////////////////////// + /// @brief handle error and delete + //////////////////////////////////////////////////////////////////////////////// + + virtual void handleError (basics::TriagensError const&) = 0; + + public: + + //////////////////////////////////////////////////////////////////////////////// + /// @brief getter for the name + //////////////////////////////////////////////////////////////////////////////// + + const string& getName () const { + return name; + } + + private: + const string& name; + }; + } +} + +#endif