1
0
Fork 0
arangodb/arangod/Rest/AnyServer.h

182 lines
5.8 KiB
C++

////////////////////////////////////////////////////////////////////////////////
/// DISCLAIMER
///
/// Copyright 2014-2016 ArangoDB GmbH, Cologne, Germany
/// Copyright 2004-2014 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 ArangoDB GmbH, Cologne, Germany
///
/// @author Dr. Frank Celler
////////////////////////////////////////////////////////////////////////////////
#ifndef ARANGOD_REST_ANY_SERVER_H
#define ARANGOD_REST_ANY_SERVER_H 1
#include "Basics/Common.h"
namespace triagens {
namespace rest {
class ApplicationServer;
////////////////////////////////////////////////////////////////////////////////
/// @brief rest server base
////////////////////////////////////////////////////////////////////////////////
class AnyServer {
AnyServer(AnyServer const&) = delete;
AnyServer& operator=(AnyServer const&) = delete;
public:
AnyServer();
virtual ~AnyServer();
public:
//////////////////////////////////////////////////////////////////////////////
/// @brief enumeration for server modes
//////////////////////////////////////////////////////////////////////////////
enum class ServerMode { MODE_STANDALONE, MODE_SERVICE };
public:
//////////////////////////////////////////////////////////////////////////////
/// @brief starts the server
//////////////////////////////////////////////////////////////////////////////
int start();
//////////////////////////////////////////////////////////////////////////////
/// @brief begins shutdown sequence
//////////////////////////////////////////////////////////////////////////////
void beginShutdown();
//////////////////////////////////////////////////////////////////////////////
/// @brief set the server mode
//////////////////////////////////////////////////////////////////////////////
void setMode(ServerMode mode) { _mode = mode; }
//////////////////////////////////////////////////////////////////////////////
/// @brief get the server mode as a string
//////////////////////////////////////////////////////////////////////////////
char const* modeString() const {
if (_mode == ServerMode::MODE_STANDALONE) {
return "standalone";
}
TRI_ASSERT(_mode == ServerMode::MODE_SERVICE);
return "service";
}
protected:
//////////////////////////////////////////////////////////////////////////////
/// @brief builds the application server
//////////////////////////////////////////////////////////////////////////////
virtual void buildApplicationServer() = 0;
//////////////////////////////////////////////////////////////////////////////
/// @brief start the server using the description
//////////////////////////////////////////////////////////////////////////////
virtual int startupServer() = 0;
//////////////////////////////////////////////////////////////////////////////
/// @brief to be called when something happened
//////////////////////////////////////////////////////////////////////////////
virtual void startupProgress(){};
//////////////////////////////////////////////////////////////////////////////
/// @brief to be called when we're ready for action.
//////////////////////////////////////////////////////////////////////////////
virtual void startupFinished(){};
//////////////////////////////////////////////////////////////////////////////
/// @brief to be called when we're starting to shutdown.
//////////////////////////////////////////////////////////////////////////////
virtual void shutDownBegins(){};
protected:
//////////////////////////////////////////////////////////////////////////////
/// @brief the server mode
//////////////////////////////////////////////////////////////////////////////
ServerMode _mode;
//////////////////////////////////////////////////////////////////////////////
/// @brief running in daemon mode
//////////////////////////////////////////////////////////////////////////////
bool _daemonMode;
//////////////////////////////////////////////////////////////////////////////
/// @brief running in supervisor mode
//////////////////////////////////////////////////////////////////////////////
bool _supervisorMode;
////////////////////////////////////////////////////////////////////////////////
/// @brief was docuBlock pidFile
////////////////////////////////////////////////////////////////////////////////
std::string _pidFile;
//////////////////////////////////////////////////////////////////////////////
/// @brief working directory
//////////////////////////////////////////////////////////////////////////////
std::string _workingDirectory;
//////////////////////////////////////////////////////////////////////////////
/// @brief application server
//////////////////////////////////////////////////////////////////////////////
ApplicationServer* _applicationServer;
private:
//////////////////////////////////////////////////////////////////////////////
/// @brief starts a supervisor
//////////////////////////////////////////////////////////////////////////////
int startupSupervisor();
//////////////////////////////////////////////////////////////////////////////
/// @brief starts a daemon
//////////////////////////////////////////////////////////////////////////////
int startupDaemon();
};
}
}
#endif