Skip to content
Snippets Groups Projects
Commit c4a2e5c9 authored by Steven Murray's avatar Steven Murray
Browse files

AcsProxyZmq now connects on demand

parent 754faeb5
Branches
Tags
No related merge requests found
......@@ -169,9 +169,8 @@ Frame createAcsForceDismountTapeFrame(const std::string &vid, const AcsLibrarySl
// constructor
//------------------------------------------------------------------------------
AcsProxyZmq::AcsProxyZmq(void *const zmqContext, const unsigned short serverPort) throw():
m_serverPort(serverPort),
m_serverSocket(zmqContext, ZMQ_REQ) {
connectZmqSocketToLocalhost(m_serverSocket, serverPort);
m_zmqContext(zmqContext),
m_serverPort(serverPort) {
}
//------------------------------------------------------------------------------
......@@ -182,10 +181,10 @@ void AcsProxyZmq::mountTapeReadOnly(const std::string &vid, const LibrarySlot &l
try {
const Frame rqst = createAcsMountTapeReadOnlyFrame(vid, dynamic_cast<const AcsLibrarySlot&>(librarySlot));
sendFrame(m_serverSocket, rqst);
sendFrame(serverSocketInstance(), rqst);
MediaChangerReturnValue reply;
recvTapeReplyOrEx(m_serverSocket, reply);
recvTapeReplyOrEx(serverSocketInstance(), reply);
if(0 != reply.value()) {
// Should never get here
cta::exception::Exception ex;
......@@ -210,10 +209,10 @@ void AcsProxyZmq::mountTapeReadWrite(const std::string &vid, const LibrarySlot &
try {
const Frame rqst = createAcsMountTapeReadWriteFrame(vid, dynamic_cast<const AcsLibrarySlot&>(librarySlot));
sendFrame(m_serverSocket, rqst);
sendFrame(serverSocketInstance(), rqst);
MediaChangerReturnValue reply;
recvTapeReplyOrEx(m_serverSocket, reply);
recvTapeReplyOrEx(serverSocketInstance(), reply);
if(0 != reply.value()) {
// Should never get here
cta::exception::Exception ex;
......@@ -238,10 +237,10 @@ void AcsProxyZmq::dismountTape(const std::string &vid, const LibrarySlot &librar
try {
const Frame rqst = createAcsDismountTapeFrame(vid, dynamic_cast<const AcsLibrarySlot&>(librarySlot));
sendFrame(m_serverSocket, rqst);
sendFrame(serverSocketInstance(), rqst);
MediaChangerReturnValue reply;
recvTapeReplyOrEx(m_serverSocket, reply);
recvTapeReplyOrEx(serverSocketInstance(), reply);
if(0 != reply.value()) {
// Should never get here
cta::exception::Exception ex;
......@@ -266,10 +265,10 @@ void AcsProxyZmq::forceDismountTape(const std::string &vid, const LibrarySlot &l
try {
const Frame rqst = createAcsForceDismountTapeFrame(vid, dynamic_cast<const AcsLibrarySlot&>(librarySlot));
sendFrame(m_serverSocket, rqst);
sendFrame(serverSocketInstance(), rqst);
MediaChangerReturnValue reply;
recvTapeReplyOrEx(m_serverSocket, reply);
recvTapeReplyOrEx(serverSocketInstance(), reply);
if(0 != reply.value()) {
// Should never get here
cta::exception::Exception ex;
......@@ -286,5 +285,16 @@ void AcsProxyZmq::forceDismountTape(const std::string &vid, const LibrarySlot &l
}
}
//------------------------------------------------------------------------------
// serverSocketInstance
//------------------------------------------------------------------------------
ZmqSocketMT &AcsProxyZmq::serverSocketInstance() {
if(nullptr == m_serverSocket) {
m_serverSocket.reset(new ZmqSocketMT(m_zmqContext, ZMQ_REQ));
connectZmqSocketToLocalhost(*m_serverSocket, m_serverPort);
}
return *m_serverSocket;
}
} // namespace mediachanger
} // namespace cta
......@@ -22,6 +22,7 @@
#include "mediachanger/MediaChangerProxy.hpp"
#include "mediachanger/ZmqSocketMT.hpp"
#include <memory>
#include <mutex>
namespace cta {
......@@ -80,6 +81,11 @@ public:
void forceDismountTape(const std::string &vid, const LibrarySlot &librarySlot) override;
private:
/**
* The ZMQ context.
*/
void *m_zmqContext;
/**
* Mutex used to implement a critical section around the enclosed
......@@ -94,9 +100,21 @@ private:
const unsigned short m_serverPort;
/**
* Socket connecting this proxy the daemon it represents.
* Socket connecting this proxy to the daemon it represents.
*/
std::unique_ptr<ZmqSocketMT> m_serverSocket;
/**
* Returns the socket instance connecting this proxy to the daemon it
* represents. This method instantiates a socket and connects it if
* a socket does not already exist.
*
* Please note that a lock MUST be taken on m_mutex before calling this
* method.
*
* @return The socket connecting this proxy the daemon it represents.
*/
ZmqSocketMT m_serverSocket;
ZmqSocketMT &serverSocketInstance();
}; // class AcsProxyZmq
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment