Skip to content
Snippets Groups Projects
Commit 6660cd5e authored by Michael Davis's avatar Michael Davis
Browse files

[XrdSsi] Refactors XrdSsi classes

Renames private member variables. Changes to some constructor arguments.
parent 86b382d6
Branches
Tags
No related merge requests found
...@@ -14,17 +14,17 @@ void RequestProc<xrdssi::test::Request, xrdssi::test::Result, xrdssi::test::Meta ...@@ -14,17 +14,17 @@ void RequestProc<xrdssi::test::Request, xrdssi::test::Result, xrdssi::test::Meta
// Output message in Json format (for debugging) // Output message in Json format (for debugging)
std::cerr << "Received message:" << std::endl; std::cerr << "Received message:" << std::endl;
std::cerr << MessageToJsonString(request); std::cerr << MessageToJsonString(m_request);
// Set reply // Set reply
response.set_result_code(0); m_response.set_result_code(0);
response.mutable_response()->set_message_text("This is the reply to " + *request.mutable_message_text()); m_response.mutable_response()->set_message_text("This is the reply to " + *m_request.mutable_message_text());
// Output message in Json format (for debugging) // Output message in Json format (for debugging)
std::cerr << "Preparing response:" << std::endl; std::cerr << "Preparing response:" << std::endl;
std::cerr << MessageToJsonString(response); std::cerr << MessageToJsonString(m_response);
} }
...@@ -38,12 +38,12 @@ void RequestProc<xrdssi::test::Request, xrdssi::test::Result, xrdssi::test::Meta ...@@ -38,12 +38,12 @@ void RequestProc<xrdssi::test::Request, xrdssi::test::Result, xrdssi::test::Meta
{ {
// Set metadata // Set metadata
metadata.set_message_text("Have some metadata"); m_metadata.set_message_text("Have some metadata");
// Output message in Json format (for debugging) // Output message in Json format (for debugging)
std::cerr << "Preparing metadata..." << std::endl; std::cerr << "Preparing metadata..." << std::endl;
std::cerr << MessageToJsonString(metadata); std::cerr << MessageToJsonString(m_metadata);
} }
......
...@@ -35,10 +35,10 @@ private: ...@@ -35,10 +35,10 @@ private:
void ExecuteAlerts() { std::cerr << "Called default ExecuteAlerts()" << std::endl; } void ExecuteAlerts() { std::cerr << "Called default ExecuteAlerts()" << std::endl; }
void ExecuteMetadata() { std::cerr << "Called default ExecuteMetadata()" << std::endl; } void ExecuteMetadata() { std::cerr << "Called default ExecuteMetadata()" << std::endl; }
RequestType request; RequestType m_request;
ResponseType response; ResponseType m_response;
MetadataType metadata; MetadataType m_metadata;
AlertType alert; AlertType m_alert;
}; };
...@@ -61,7 +61,7 @@ void RequestProc<RequestType, ResponseType, MetadataType, AlertType>::Execute() ...@@ -61,7 +61,7 @@ void RequestProc<RequestType, ResponseType, MetadataType, AlertType>::Execute()
// Deserialize the Request // Deserialize the Request
if(!request.ParseFromString(request_str)) if(!m_request.ParseFromString(request_str))
{ {
throw XrdSsiException("request.ParseFromString() failed"); throw XrdSsiException("request.ParseFromString() failed");
} }
...@@ -86,7 +86,7 @@ void RequestProc<RequestType, ResponseType, MetadataType, AlertType>::Execute() ...@@ -86,7 +86,7 @@ void RequestProc<RequestType, ResponseType, MetadataType, AlertType>::Execute()
std::string response_str; std::string response_str;
if(!metadata.SerializeToString(&response_str)) if(!m_metadata.SerializeToString(&response_str))
{ {
throw XrdSsiException("metadata.SerializeToString() failed"); throw XrdSsiException("metadata.SerializeToString() failed");
} }
...@@ -103,7 +103,7 @@ void RequestProc<RequestType, ResponseType, MetadataType, AlertType>::Execute() ...@@ -103,7 +103,7 @@ void RequestProc<RequestType, ResponseType, MetadataType, AlertType>::Execute()
// Serialize the Response // Serialize the Response
if(!response.SerializeToString(&response_str)) if(!m_response.SerializeToString(&response_str))
{ {
throw XrdSsiException("response.SerializeToString() failed"); throw XrdSsiException("response.SerializeToString() failed");
} }
......
...@@ -30,9 +30,7 @@ bool TestSsiServiceProvider::Init(XrdSsiLogger *logP, XrdSsiCluster *clsP, const ...@@ -30,9 +30,7 @@ bool TestSsiServiceProvider::Init(XrdSsiLogger *logP, XrdSsiCluster *clsP, const
// do some initialisation // do some initialisation
initOK = true; return true;
return initOK;
} }
......
...@@ -34,12 +34,8 @@ public: ...@@ -34,12 +34,8 @@ public:
// Constructor and destructor // Constructor and destructor
TestSsiServiceProvider() : initOK(false) {} TestSsiServiceProvider() {}
virtual ~TestSsiServiceProvider() {} virtual ~TestSsiServiceProvider() {}
private:
bool initOK;
}; };
#endif #endif
...@@ -12,13 +12,13 @@ ...@@ -12,13 +12,13 @@
class XrdSsiException : public std::exception class XrdSsiException : public std::exception
{ {
public: public:
XrdSsiException(const std::string &err_msg) : error_msg(err_msg) {} XrdSsiException(const std::string &err_msg) : m_err_msg(err_msg) {}
XrdSsiException(const XrdSsiErrInfo &eInfo) : error_msg(eInfo.Get()) {} XrdSsiException(const XrdSsiErrInfo &eInfo) : m_err_msg(eInfo.Get()) {}
const char* what() const noexcept { return error_msg.c_str(); } const char* what() const noexcept { return m_err_msg.c_str(); }
private: private:
std::string error_msg; std::string m_err_msg;
}; };
#endif #endif
...@@ -23,14 +23,28 @@ template <typename RequestType, typename ResponseType, typename MetadataType, ty ...@@ -23,14 +23,28 @@ template <typename RequestType, typename ResponseType, typename MetadataType, ty
class XrdSsiPbRequest : public XrdSsiRequest class XrdSsiPbRequest : public XrdSsiRequest
{ {
public: public:
XrdSsiPbRequest(const std::string &buffer_str, uint16_t timeout=0) : request_buffer(buffer_str.c_str()), request_len(buffer_str.size()) XrdSsiPbRequest(const std::string &buffer_str, unsigned int response_bufsize, uint16_t timeout) :
m_request_bufptr(buffer_str.c_str()),
m_request_len(buffer_str.size()),
m_response_bufsize(response_bufsize)
{ {
std::cerr << "Creating TestSsiRequest object, setting timeout=" << timeout << std::endl; std::cerr << "Creating XrdSsiPbRequest object:" << std::endl;
std::cerr << " Response buffer size = " << m_response_bufsize << std::endl;
std::cerr << " Response timeout = " << timeout << std::endl;
// Allocate response buffer
m_response_bufptr = new char[m_response_bufsize];
// Set response timeout
SetTimeOut(timeout); SetTimeOut(timeout);
} }
virtual ~XrdSsiPbRequest() virtual ~XrdSsiPbRequest()
{ {
std::cerr << "Deleting TestSsiRequest object" << std::endl; std::cerr << "Deleting XrdSsiPbRequest object" << std::endl;
delete[] m_response_bufptr;
} }
// It is up to the implementation to create request data, save it in some manner, and provide it to // It is up to the implementation to create request data, save it in some manner, and provide it to
...@@ -41,7 +55,7 @@ public: ...@@ -41,7 +55,7 @@ public:
// Query for Andy: shouldn't the return type for GetRequest be const? // Query for Andy: shouldn't the return type for GetRequest be const?
virtual char *GetRequest(int &reqlen) override { reqlen = request_len; return const_cast<char*>(request_buffer); } virtual char *GetRequest(int &reqlen) override { reqlen = m_request_len; return const_cast<char*>(m_request_bufptr); }
// Requests are sent to the server asynchronously via the service object. The ProcessResponse() callback // Requests are sent to the server asynchronously via the service object. The ProcessResponse() callback
// is used to inform the request object if the request completed or failed. // is used to inform the request object if the request completed or failed.
...@@ -60,12 +74,20 @@ public: ...@@ -60,12 +74,20 @@ public:
virtual void Alert(XrdSsiRespInfoMsg &aMsg) override; virtual void Alert(XrdSsiRespInfoMsg &aMsg) override;
private: private:
const char *request_buffer; // Pointer to the Request buffer
int request_len;
const char *m_request_bufptr;
int m_request_len;
// Pointer to the Response buffer
char *m_response_bufptr;
int m_response_bufsize;
int m_response_len;
// Callbacks for each of the XRootD response types // Callbacks for each of the XRootD reply types
XrdSsiPbRequestCallback<RequestType> RequestCallback; XrdSsiPbRequestCallback<ResponseType> ResponseCallback;
XrdSsiPbRequestCallback<MetadataType> MetadataCallback; XrdSsiPbRequestCallback<MetadataType> MetadataCallback;
XrdSsiPbRequestCallback<AlertType> AlertCallback; XrdSsiPbRequestCallback<AlertType> AlertCallback;
......
...@@ -10,8 +10,9 @@ ...@@ -10,8 +10,9 @@
// Constants // Constants
const unsigned int default_server_timeout = 15; // Maximum XRootD reply timeout in seconds const unsigned int DefaultResponseBufferSize = 2097152; // Default size for the response buffer in bytes = 2 Mb
const unsigned int default_shutdown_timeout = 30; // Maximum time to wait for the Service to shut down const unsigned int DefaultServerTimeout = 15; // Maximum XRootD reply timeout in secs
const unsigned int DefaultShutdownTimeout = 30; // Maximum time to wait for the Service to shut down in secs
...@@ -32,13 +33,17 @@ public: ...@@ -32,13 +33,17 @@ public:
XrdSsiPbServiceClientSide() = delete; XrdSsiPbServiceClientSide() = delete;
XrdSsiPbServiceClientSide(const std::string &hostname, unsigned int port, const std::string &resource, XrdSsiPbServiceClientSide(const std::string &hostname, unsigned int port, const std::string &resource,
unsigned int server_timeout = default_server_timeout, unsigned int response_bufsize = DefaultResponseBufferSize,
unsigned int shutdown_timeout = default_shutdown_timeout) : unsigned int server_tmo = DefaultServerTimeout,
resource(resource), server_tmo(server_timeout), shutdown_tmo(shutdown_timeout) unsigned int shutdown_tmo = DefaultShutdownTimeout) :
m_resource(resource),
m_response_bufsize(response_bufsize),
m_server_tmo(server_tmo),
m_shutdown_tmo(shutdown_tmo)
{ {
XrdSsiErrInfo eInfo; XrdSsiErrInfo eInfo;
if(!(serverP = XrdSsiProviderClient->GetService(eInfo, hostname + ":" + std::to_string(port)))) if(!(m_server_ptr = XrdSsiProviderClient->GetService(eInfo, hostname + ":" + std::to_string(port))))
{ {
throw XrdSsiException(eInfo); throw XrdSsiException(eInfo);
} }
...@@ -53,12 +58,13 @@ public: ...@@ -53,12 +58,13 @@ public:
void send(const RequestType &request); void send(const RequestType &request);
private: private:
XrdSsiResource resource; // Requests are bound to this resource XrdSsiResource m_resource; // Requests are bound to this resource
XrdSsiService *serverP; // Pointer to XRootD Server object XrdSsiService *m_server_ptr; // Pointer to XRootD Server object
unsigned int server_tmo; // Timeout for a response from the server unsigned int m_response_bufsize; // Buffer size for responses from the XRootD SSI server
unsigned int shutdown_tmo; // Timeout to shut down the server in the destructor unsigned int m_server_tmo; // Timeout for a response from the server
unsigned int m_shutdown_tmo; // Timeout to shut down the server in the destructor
}; };
...@@ -73,13 +79,13 @@ XrdSsiPbServiceClientSide<RequestType, ResponseType, MetadataType, AlertType>::~ ...@@ -73,13 +79,13 @@ XrdSsiPbServiceClientSide<RequestType, ResponseType, MetadataType, AlertType>::~
// The XrdSsiService object cannot be explicitly deleted. The Stop() method deletes the object if // The XrdSsiService object cannot be explicitly deleted. The Stop() method deletes the object if
// it is safe to do so. // it is safe to do so.
while(!serverP->Stop() && shutdown_tmo--) while(!m_server_ptr->Stop() && m_shutdown_tmo--)
{ {
sleep(1); sleep(1);
std::cerr << "."; std::cerr << ".";
} }
if(shutdown_tmo > 0) if(m_shutdown_tmo > 0)
{ {
std::cerr << "done." << std::endl; std::cerr << "done." << std::endl;
} }
...@@ -119,12 +125,13 @@ void XrdSsiPbServiceClientSide<RequestType, ResponseType, MetadataType, AlertTyp ...@@ -119,12 +125,13 @@ void XrdSsiPbServiceClientSide<RequestType, ResponseType, MetadataType, AlertTyp
// Requests are always executed in the context of a service. They need to correspond to what the service allows. // Requests are always executed in the context of a service. They need to correspond to what the service allows.
XrdSsiRequest *requestP = new XrdSsiPbRequest<RequestType, ResponseType, MetadataType, AlertType> (request_str, server_tmo); XrdSsiRequest *request_ptr =
new XrdSsiPbRequest<RequestType, ResponseType, MetadataType, AlertType>(request_str, m_response_bufsize, m_server_tmo);
// Transfer ownership of the request to the service object // Transfer ownership of the request to the service object
// TestSsiRequest handles deletion of the request buffer, so we can allow the pointer to go out-of-scope // TestSsiRequest handles deletion of the request buffer, so we can allow the pointer to go out-of-scope
serverP->ProcessRequest(*requestP, resource); m_server_ptr->ProcessRequest(*request_ptr, m_resource);
// Note: it is safe to delete the XrdSsiResource object after ProcessRequest() returns. I don't delete it because // Note: it is safe to delete the XrdSsiResource object after ProcessRequest() returns. I don't delete it because
// I am assuming I can reuse it, but I need to check if that is a safe assumption. Perhaps I need to create a new // I am assuming I can reuse it, but I need to check if that is a safe assumption. Perhaps I need to create a new
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment