Commit 1f6d11d2 authored by legoc's avatar legoc
Browse files

(split) Stopping time is only used when a stop handler is defined (by This...

(split) Stopping time is only used when a stop handler is defined (by This handleStop() or executable, if passed in handleStop() it overrides the server value
parent c5eed0ac
......@@ -14,6 +14,7 @@
* Added Instance::waitFor(KeyValue) to wait for a key value event.
* Added Com classes for port and storage requests.
* Argument info passed in JSON format.
* Added optional stopping time in This::handleStop() function.
0.3.3
-----
......
......@@ -150,9 +150,12 @@ public:
static bool isAvailable(int timeout = 10000);
static bool isStopping();
/**
* Sets the stop handler with stopping time that overrides the one that may be defined in the configuration of the server.
*/
template<typename Type>
static void handleStop(Type function) {
m_instance.handleStopImpl(function);
static void handleStop(Type function, int stoppingTime = -1) {
m_instance.handleStopImpl(function, stoppingTime);
}
static void cancelWaitings();
......@@ -185,7 +188,7 @@ private:
State waitForStop();
void stoppingFunction(StopFunctionType stop);
void handleStopImpl(StopFunctionType function);
void handleStopImpl(StopFunctionType function, int stoppingTime);
std::string m_name;
int m_id;
......
......@@ -463,7 +463,12 @@ void This::stoppingFunction(StopFunctionType stop) {
}
}
void This::handleStopImpl(StopFunctionType function) {
void This::handleStopImpl(StopFunctionType function, int stoppingTime) {
// Notify the server.
m_requestSocket->request(m_impl->createSetStopHandlerRequest(m_id, stoppingTime));
// Create the handler.
m_stopHandler = unique_ptr<HandlerImpl>(new HandlerImpl(bind(&This::stoppingFunction, this, function)));
}
......
......@@ -131,6 +131,21 @@ std::string ServicesImpl::createStartRequest(const std::string& name, const std:
return request.toString();
}
std::string ServicesImpl::createSetStopHandlerRequest(int id, int stoppingTime) const {
json::StringObject request;
request.pushKey(message::TYPE);
request.pushInt(message::SET_STOP_HANDLER);
request.pushKey(message::SetStopHandlerRequest::ID);
request.pushInt(id);
request.pushKey(message::SetStopHandlerRequest::STOPPING_TIME);
request.pushInt(stoppingTime);
return request.toString();
}
std::string ServicesImpl::createStopRequest(int id) const {
json::StringObject request;
......
......@@ -38,6 +38,7 @@ public:
std::string createSyncStreamRequest(const std::string& name) const;
std::string createVersionRequest() const;
std::string createStartRequest(const std::string& name, const std::vector<std::string> & args, const std::string& thisName, int thisId, const std::string& thisEndpoint) const;
std::string createSetStopHandlerRequest(int id, int stoppingTime) const;
std::string createStopRequest(int id) const;
std::string createKillRequest(int id) const;
std::string createConnectRequest(const std::string& name) const;
......
......@@ -62,6 +62,7 @@ namespace message {
const int PORT_UNAVAILABLE = 35;
const int RELEASE_PORT = 36;
const int PORTS = 37;
const int SET_STOP_HANDLER = 38;
namespace Event {
constexpr const char* SYNC = "SYNC";
......@@ -98,6 +99,11 @@ namespace message {
constexpr const char* MESSAGE = "message"; // optional string message = 2;
}
namespace SetStopHandlerRequest {
constexpr const char* ID = "id"; // int32
constexpr const char* STOPPING_TIME = "stopping_time"; // int32
}
namespace StopRequest {
constexpr const char* ID = "id"; // required int32 id = 1;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment