Commit bc005601 authored by Steven Murray's avatar Steven Murray
Browse files

Deleted SmartZmqContext from tapeserver/castor

parent 87b61e96
......@@ -38,7 +38,6 @@ set(CtaMessageSrcs
Constants.cpp
Frame.cpp
messages.cpp
SmartZmqContext.cpp
../../../tapeserver/daemon/TapedProxy.cpp
TapeserverProxyZmq.cpp
ZmqMsg.cpp
......
/******************************************************************************
*
* This file is part of the Castor project.
* See http://castor.web.cern.ch/castor
*
* Copyright (C) 2003 CERN
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*
*
*
* @author Castor Dev team, castor-dev@cern.ch
*****************************************************************************/
#include "tapeserver/castor/messages/SmartZmqContext.hpp"
#include "common/utils/utils.hpp"
#include "common/log/Logger.hpp"
#include <errno.h>
#include <unistd.h>
#include <zmq.h>
#include <list>
//-----------------------------------------------------------------------------
// constructor
//-----------------------------------------------------------------------------
castor::messages::SmartZmqContext::SmartZmqContext() throw() :
m_zmqContext(NULL) {
}
//-----------------------------------------------------------------------------
// constructor
//-----------------------------------------------------------------------------
castor::messages::SmartZmqContext::SmartZmqContext(void *const zmqContext)
throw() : m_zmqContext(zmqContext) {
}
//-----------------------------------------------------------------------------
// reset
//-----------------------------------------------------------------------------
void castor::messages::SmartZmqContext::reset(void *const zmqContext)
throw() {
// If the new ZMQ context is not the one already owned
if(zmqContext != m_zmqContext) {
// If this smart pointer still owns a ZMQ context, then terminate it
if(m_zmqContext != NULL) {
zmq_term(m_zmqContext);
}
// Take ownership of the new ZMQ context
m_zmqContext = zmqContext;
}
}
//-----------------------------------------------------------------------------
// SmartZmqContext assignment operator
//-----------------------------------------------------------------------------
castor::messages::SmartZmqContext
&castor::messages::SmartZmqContext::operator=(SmartZmqContext& obj) {
reset(obj.release());
return *this;
}
//-----------------------------------------------------------------------------
// destructor
//-----------------------------------------------------------------------------
castor::messages::SmartZmqContext::~SmartZmqContext() throw() {
// ZMQ sends an abort on exit when cleaned up this way under some
// circumstances, so we purposely do not clean up the context (zmq_term) and
// leave a resource leak, which in our use case is one-off situation
// per process, and it gets cleaned up on process termination, which happens
// very soon after this destructor being called.
//reset();
}
//-----------------------------------------------------------------------------
// get
//-----------------------------------------------------------------------------
void *castor::messages::SmartZmqContext::get() const throw() {
return m_zmqContext;
}
//-----------------------------------------------------------------------------
// release
//-----------------------------------------------------------------------------
void *castor::messages::SmartZmqContext::release() {
// If this smart pointer does not own a ZMQ context
if(NULL == m_zmqContext) {
cta::exception::NotAnOwner ex;
ex.getMessage() << "Smart pointer does not own a ZMQ context";
throw ex;
}
void *const tmp = m_zmqContext;
// A NULL value indicates this smart pointer does not own a ZMQ context
m_zmqContext = NULL;
return tmp;
}
//-----------------------------------------------------------------------------
// release
//-----------------------------------------------------------------------------
void* castor::messages::SmartZmqContext::instantiateZmqContext(const int sizeOfIOThreadPoolForZMQ, cta::log::Logger& log) {
void *const zmqContext = zmq_init(sizeOfIOThreadPoolForZMQ);
if(NULL == zmqContext) {
const std::string message = cta::utils::errnoToString(errno);
cta::exception::Exception ex;
ex.getMessage() << "Child of ProcessForker failed to instantiate ZMQ"
" context: " << message;
throw ex;
}
std::ostringstream contextAddr;
contextAddr << std::hex << zmqContext;
std::list<cta::log::Param> params = {cta::log::Param("contextAddr", contextAddr.str())};
log(cta::log::INFO, "Child of ProcessForker instantiated a ZMQ context", params);
return zmqContext;
}
/******************************************************************************
*
* This file is part of the Castor project.
* See http://castor.web.cern.ch/castor
*
* Copyright (C) 2003 CERN
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*
*
* @author Castor Dev team, castor-dev@cern.ch
*****************************************************************************/
#pragma once
#include "common/exception/NotAnOwner.hpp"
#include "common/log/Logger.hpp"
#include <stdio.h>
namespace castor {
namespace messages {
/**
* A smart pointer that owns a ZMQ context. If the smart pointer goes out of
* scope and it owns a ZMQ context, then it will terminate that context by
* calling zmq_term().
*/
class SmartZmqContext {
public:
/**
* Constructor.
*/
SmartZmqContext() throw();
/**
* Constructor.
*
* @param zmqContext The ZMQ context to be owned by the smart pointer.
*/
SmartZmqContext(void *const zmqContext) throw();
/**
* Take ownership of the specified ZMQ context, terminating the previously
* owned ZMQ context if there is one and it is not the same as the one
* specified.
*
* @param zmqContext The ZMQ context to be owned, defaults to NULL if not
* specified, where NULL means this smart pointer will not own a ZMQ context
* after the reset() method returns.
*/
void reset(void *const zmqContext = NULL) throw();
/**
* SmartZmqContext assignment operator.
*
* This function does the following:
* <ul>
* <li> Calls release on the previous owner (obj);
* <li> Terminates the ZMQ context of this object if it already owns one.
* <li> Makes this object the owner of the ZMQ context released from the
* previous owner (obj).
* </ul>
*/
SmartZmqContext &operator=(SmartZmqContext& obj);
/**
* Destructor.
*
* If the smart pointer owns a ZMQ context, then the destructor will
* terminate it by calling zmq_term().
*/
~SmartZmqContext() throw();
/**
* Returns the owned ZMQ context or NULL if this smart pointer does not own
* one.
*
* @return The owned ZMQ context or NULL.
*/
void *get() const throw();
/**
* Releases the owned ZMQ context.
*
* @return The released ZMQ context.
*/
void *release() ;
/**
* Helper function instancing a ZMQ context.
* @param sizeOfIOThreadPoolForZMQ The size of the IO thread pool to be used
* by ZMQ.
* @param log a reference to the logger, provided by the caller.
* @return The ZMQ context.
*/
static void *instantiateZmqContext(const int sizeOfIOThreadPoolForZMQ,
cta::log::Logger & log);
private:
/**
* The owned ZMQ context. A value of NULL means this smart pointer does not
* own a ZMQ context.
*/
void *m_zmqContext;
/**
* Private copy-constructor to prevent users from trying to create a new
* copy of an object of this class.
*
* Not implemented so that it cannot be called.
*/
SmartZmqContext(const SmartZmqContext &obj) throw();
}; // class SmartZmqContext
} // namespace message
} // namespace castor
......@@ -25,13 +25,13 @@
#include "mediachanger/AcsProxyZmq.hpp"
#include "mediachanger/MmcProxyLog.hpp"
#include "mediachanger/RmcProxyTcpIp.hpp"
#include "mediachanger/SmartZmqContext.hpp"
#include "objectstore/Backend.hpp"
#include "objectstore/BackendFactory.hpp"
#include "objectstore/BackendVFS.hpp"
#include "objectstore/BackendPopulator.hpp"
#include "rdbms/Login.hpp"
#include "scheduler/OStoreDB/OStoreDBWithAgent.hpp"
#include "tapeserver/castor/messages/SmartZmqContext.hpp"
#include "tapeserver/castor/acs/Constants.hpp"
#include "tapeserver/castor/tape/tapeserver/daemon/CleanerSession.hpp"
#include "tapeserver/castor/tape/tapeserver/daemon/DataTransferSession.hpp"
......@@ -918,9 +918,8 @@ int DriveHandler::runChild() {
// Mounting management.
const int sizeOfIOThreadPoolForZMQ = 1;
castor::messages::SmartZmqContext zmqContext(
castor::messages::SmartZmqContext::instantiateZmqContext(sizeOfIOThreadPoolForZMQ,
m_processManager.logContext().logger()));
mediachanger::SmartZmqContext zmqContext(
mediachanger::SmartZmqContext::instantiateZmqContext(sizeOfIOThreadPoolForZMQ));
mediachanger::AcsProxyZmq acs(castor::acs::ACS_PORT, zmqContext.get());
cta::mediachanger::MmcProxyLog mmc(m_processManager.logContext().logger());
......@@ -962,9 +961,8 @@ int DriveHandler::runChild() {
// Mounting management.
const int sizeOfIOThreadPoolForZMQ = 1;
castor::messages::SmartZmqContext zmqContext(
castor::messages::SmartZmqContext::instantiateZmqContext(sizeOfIOThreadPoolForZMQ,
m_processManager.logContext().logger()));
mediachanger::SmartZmqContext zmqContext(
mediachanger::SmartZmqContext::instantiateZmqContext(sizeOfIOThreadPoolForZMQ));
mediachanger::AcsProxyZmq acs(castor::acs::ACS_PORT, zmqContext.get());
cta::mediachanger::MmcProxyLog mmc(m_processManager.logContext().logger());
......
Supports Markdown
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