Commit 6a18f72b authored by legoc's avatar legoc
Browse files

Request response messages

parent 116b3cfc
......@@ -322,29 +322,14 @@ std::string createDetachUnmanagedRequest(int id) {
return request.toString();
}
std::string createRequestResponse(int64_t value) {
std::string createRequestResponse(int32_t value, const std::string& message) {
json::StringObject request;
request.pushKey(message::TYPE);
request.pushInt(message::RESPONSE);
request.pushKey(message::RequestResponse::VALUE);
request.pushInt64(value);
request.pushKey(message::RequestResponse::MESSAGE);
request.pushString("");
return request.toString();
}
std::string createRequestResponse(int64_t value, const std::string& message) {
json::StringObject request;
request.pushKey(message::TYPE);
request.pushInt(message::RESPONSE);
request.pushKey(message::RequestResponse::VALUE);
request.pushInt64(value);
request.pushInt(value);
request.pushKey(message::RequestResponse::MESSAGE);
request.pushString(message);
......@@ -352,7 +337,6 @@ std::string createRequestResponse(int64_t value, const std::string& message) {
return request.toString();
}
std::string createStoreKeyValueRequest(int id, const std::string& key, const std::string& value) {
json::StringObject request;
......
......@@ -348,8 +348,7 @@ std::string createAttachUnmanagedRequest(const std::string& name, long pid);
std::string createDetachUnmanagedRequest(int id);
std::string createOutputPortWithIdRequest(int id);
std::string createOutputPortRequest(const std::string& name);
std::string createRequestResponse(int64_t value);
std::string createRequestResponse(int64_t value, const std::string& message);
std::string createRequestResponse(int32_t value, const std::string& message);
std::string createStoreKeyValueRequest(int id, const std::string& key, const std::string& value);
std::string createGetKeyValueRequest(int id, const std::string& key);
std::string createRemoveKeyRequest(int id, const std::string& key);
......
......@@ -136,21 +136,6 @@ public class Application {
}
}
/**
* Method provided by convenience to simplify the use of JSON messages.
* @param value
* @param message
* @return
*/
public JSONObject createJSONResponse(int value, String message) {
JSONObject response = new JSONObject();
response.put(Messages.RequestResponse.VALUE, value);
response.put(Messages.RequestResponse.MESSAGE, "OK");
return response;
}
//TODO Remove when use of key values is done.
public void removePort(String name) {
......@@ -468,21 +453,6 @@ public class Application {
throw new UnexpectedException("Cannot parse message");
}
}
/**
* Method provided by convenience to simplify the use of JSON messages.
* @param value
* @param message
* @return
*/
public JSONObject createJSONResponse(int value, String message) {
JSONObject response = new JSONObject();
response.put(Messages.RequestResponse.VALUE, value);
response.put(Messages.RequestResponse.MESSAGE, "OK");
return response;
}
}
......
......@@ -205,49 +205,32 @@ public class PublisherImpl {
publisher.sendMore(Messages.Event.SYNC);
publisher.send(Messages.Event.SYNC);
JSONObject response = new JSONObject();
response.put(Messages.RequestResponse.VALUE, 0);
response.put(Messages.RequestResponse.MESSAGE, "OK");
Zmq.Msg message = new Zmq.Msg();
message.add(Messages.serialize(response));
message.add(Messages.serialize(Messages.createRequestResponse(0, "OK")));
return message;
}
private Zmq.Msg processSubscribePublisherRequest() {
// Return the reply.
JSONObject response = new JSONObject();
response.put(Messages.RequestResponse.VALUE, 0);
response.put(Messages.RequestResponse.MESSAGE, "OK");
Zmq.Msg message = new Zmq.Msg();
message.add(Messages.serialize(response));
message.add(Messages.serialize(Messages.createRequestResponse(0, "OK")));
return message;
}
private Zmq.Msg processCancelPublisherRequest() {
JSONObject response = new JSONObject();
response.put(Messages.RequestResponse.VALUE, 0);
response.put(Messages.RequestResponse.MESSAGE, "OK");
Zmq.Msg message = new Zmq.Msg();
message.add(Messages.serialize(response));
message.add(Messages.serialize(Messages.createRequestResponse(0, "OK")));
return message;
}
private Zmq.Msg processUnknownRequest() {
JSONObject response = new JSONObject();
response.put(Messages.RequestResponse.VALUE, -1);
response.put(Messages.RequestResponse.MESSAGE, "Unknown request");
Zmq.Msg message = new Zmq.Msg();
message.add(Messages.serialize(response));
message.add(Messages.serialize(Messages.createRequestResponse(-1, "Unknown request")));
return message;
}
......
......@@ -203,13 +203,8 @@ public class RequesterImpl {
private Zmq.Msg processReplyRequest() {
// Return the reply.
JSONObject response = new JSONObject();
response.put(Messages.RequestResponse.VALUE, 0);
response.put(Messages.RequestResponse.MESSAGE, "OK");
Zmq.Msg message = new Zmq.Msg();
message.add(Messages.serialize(response));
message.add(Messages.serialize(Messages.createRequestResponse(0, "OK")));
return message;
}
......
......@@ -144,13 +144,8 @@ public class ResponderImpl {
private Zmq.Msg processReplyRequest() {
// Return the reply.
JSONObject response = new JSONObject();
response.put(Messages.RequestResponse.VALUE, 0);
response.put(Messages.RequestResponse.MESSAGE, "OK");
Zmq.Msg message = new Zmq.Msg();
message.add(Messages.serialize(response));
message.add(Messages.serialize(Messages.createRequestResponse(0, "OK")));
return message;
}
......
......@@ -585,6 +585,17 @@ public class Messages {
return request;
}
public static JSONObject createRequestResponse(int value, String message) {
JSONObject request = new JSONObject();
request.put(Messages.TYPE, Messages.RESPONSE);
request.put(Messages.RequestResponse.VALUE, value);
request.put(Messages.RequestResponse.MESSAGE, message);
return request;
}
public static JSONObject createStoreKeyValueRequest(int applicationId, String key, String value) {
JSONObject request = new JSONObject();
......
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