Commit 3f5acac2 authored by Steven Murray's avatar Steven Murray
Browse files

Simply added the castor source tree to the CTA project in CTA/tapeserver/castor.

The CTA/tapeserver/castor directory started as a partial is copy of a git
checkout of:

    https://:@git.cern.ch/kerberos/CASTOR

at the following commit:

    commit f4cb056d
    Author: Sebastien Ponce <sebastien.ponce@cern.ch>
    Date:   Wed Jul 15 09:15:29 2015 +0200

        Close properly hbase connections in case of broken pipe, avoiding socket leak
parent cd86bccb
The CTA/tapeserver/castor directory started as a partial is copy of a git
checkout of:
https://:@git.cern.ch/kerberos/CASTOR
at the following commit:
commit f4cb056d4dc487112892a236dc5bdb04251344b8
Author: Sebastien Ponce <sebastien.ponce@cern.ch>
Date: Wed Jul 15 09:15:29 2015 +0200
Close properly hbase connections in case of broken pipe, avoiding socket leak
/**** This file has been autogenerated by gencastor from Umbrello UML model ***/
/******************************************************************************
*
* 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 Files
#include "castor/BaseAddress.hpp"
#include "castor/Constants.hpp"
#include "castor/IObject.hpp"
#include "castor/ObjectSet.hpp"
#include "osdep.h"
#include <iostream>
#include <string>
//------------------------------------------------------------------------------
// Constructor
//------------------------------------------------------------------------------
castor::BaseAddress::BaseAddress() throw() :
m_objType(0),
m_cnvSvcName(""),
m_cnvSvcType(0),
m_target(0),
m_id(0) {
}
//------------------------------------------------------------------------------
// Destructor
//------------------------------------------------------------------------------
castor::BaseAddress::~BaseAddress() throw() {
}
//------------------------------------------------------------------------------
// print
//------------------------------------------------------------------------------
void castor::BaseAddress::print(std::ostream& stream,
std::string indent,
castor::ObjectSet& alreadyPrinted) const {
stream << indent << "[# BaseAddress #]" << std::endl;
if (alreadyPrinted.find(this) != alreadyPrinted.end()) {
// Circular dependency, this object was already printed
stream << indent << "Back pointer, see above" << std::endl;
return;
}
// Output of all members
stream << indent << "objType : " << m_objType << std::endl;
stream << indent << "cnvSvcName : " << m_cnvSvcName << std::endl;
stream << indent << "cnvSvcType : " << m_cnvSvcType << std::endl;
stream << indent << "target : " << m_target << std::endl;
stream << indent << "id : " << m_id << std::endl;
alreadyPrinted.insert(this);
}
//------------------------------------------------------------------------------
// print
//------------------------------------------------------------------------------
void castor::BaseAddress::print() const {
ObjectSet alreadyPrinted;
print(std::cout, "", alreadyPrinted);
}
//------------------------------------------------------------------------------
// TYPE
//------------------------------------------------------------------------------
int castor::BaseAddress::TYPE() {
return OBJ_BaseAddress;
}
//------------------------------------------------------------------------------
// type
//------------------------------------------------------------------------------
int castor::BaseAddress::type() const {
return TYPE();
}
//------------------------------------------------------------------------------
// clone
//------------------------------------------------------------------------------
castor::IObject* castor::BaseAddress::clone() {
return new BaseAddress(*this);
}
/**** This file has been autogenerated by gencastor from Umbrello UML model ***/
/******************************************************************************
*
* 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 Files
#include "castor/IAddress.hpp"
#include "osdep.h"
#include <iostream>
#include <string>
namespace castor {
// Forward declarations
class ObjectSet;
class IObject;
/**
* class BaseAddress
* The most basic address : only a type.
*/
class BaseAddress : public virtual IAddress {
public:
/**
* Empty Constructor
*/
BaseAddress() throw();
/**
* Empty Destructor
*/
virtual ~BaseAddress() throw();
/**
* Outputs this object in a human readable format
* @param stream The stream where to print this object
* @param indent The indentation to use
* @param alreadyPrinted The set of objects already printed.
* This is to avoid looping when printing circular dependencies
*/
virtual void print(std::ostream& stream,
std::string indent,
castor::ObjectSet& alreadyPrinted) const;
/**
* Outputs this object in a human readable format
*/
virtual void print() const;
/**
* Gets the type of this kind of objects
*/
static int TYPE();
/********************************************/
/* Implementation of IObject abstract class */
/********************************************/
/**
* Gets the type of the object
*/
virtual int type() const;
/**
* virtual method to clone any object
*/
virtual IObject* clone();
/*********************************/
/* End of IObject abstract class */
/*********************************/
/**
* Get the value of m_objType
* the object type of this address
* @return the value of m_objType
*/
unsigned int objType() const {
return m_objType;
}
/**
* Set the value of m_objType
* the object type of this address
* @param new_var the new value of m_objType
*/
void setObjType(unsigned int new_var) {
m_objType = new_var;
}
/**
* Get the value of m_cnvSvcName
* the name of the conversion service able to deal with this address
* @return the value of m_cnvSvcName
*/
std::string cnvSvcName() const {
return m_cnvSvcName;
}
/**
* Set the value of m_cnvSvcName
* the name of the conversion service able to deal with this address
* @param new_var the new value of m_cnvSvcName
*/
void setCnvSvcName(std::string new_var) {
m_cnvSvcName = new_var;
}
/**
* Get the value of m_cnvSvcType
* the type of the conversion service able to deal with this address
* @return the value of m_cnvSvcType
*/
unsigned int cnvSvcType() const {
return m_cnvSvcType;
}
/**
* Set the value of m_cnvSvcType
* the type of the conversion service able to deal with this address
* @param new_var the new value of m_cnvSvcType
*/
void setCnvSvcType(unsigned int new_var) {
m_cnvSvcType = new_var;
}
/**
* Get the value of m_target
* The id of the object this address points to, if any
* @return the value of m_target
*/
u_signed64 target() const {
return m_target;
}
/**
* Set the value of m_target
* The id of the object this address points to, if any
* @param new_var the new value of m_target
*/
void setTarget(u_signed64 new_var) {
m_target = new_var;
}
/**
* Get the value of m_id
* The id of this object
* @return the value of m_id
*/
u_signed64 id() const {
return m_id;
}
/**
* Set the value of m_id
* The id of this object
* @param new_var the new value of m_id
*/
void setId(u_signed64 new_var) {
m_id = new_var;
}
private:
/// the object type of this address
unsigned int m_objType;
/// the name of the conversion service able to deal with this address
std::string m_cnvSvcName;
/// the type of the conversion service able to deal with this address
unsigned int m_cnvSvcType;
/// The id of the object this address points to, if any
u_signed64 m_target;
/// The id of this object
u_signed64 m_id;
}; /* end of class BaseAddress */
} /* end of namespace castor */
/******************************************************************************
*
* 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 Files
#include <vector>
#include <map>
#include "castor/exception/Exception.hpp"
// Local Includes
#include "ICnvFactory.hpp"
#include "BaseCnvSvc.hpp"
#include "Converters.hpp"
#include "IConverter.hpp"
#include "IAddress.hpp"
#include "IObject.hpp"
// -----------------------------------------------------------------------
// Constructor
// -----------------------------------------------------------------------
castor::BaseCnvSvc::BaseCnvSvc(const std::string name) :
BaseSvc(name) {}
// -----------------------------------------------------------------------
// Destructor
// -----------------------------------------------------------------------
castor::BaseCnvSvc::~BaseCnvSvc() throw() {
BaseCnvSvc::reset();
}
// -----------------------------------------------------------------------
// reset
// -----------------------------------------------------------------------
void castor::BaseCnvSvc::reset() throw() {
// release all converters
std::map<unsigned int, IConverter*>::iterator it;
for (it = m_converters.begin(); it != m_converters.end(); it++) {
if (it->second != 0) {
delete it->second;
}
}
m_converters.clear();
// call parent's reset
BaseSvc::reset();
}
//-----------------------------------------------------------------------------
// addAlias
//-----------------------------------------------------------------------------
void castor::BaseCnvSvc::addAlias(const unsigned int alias,
const unsigned int real) {
m_aliases[alias] = real;
}
//-----------------------------------------------------------------------------
// removeAlias
//-----------------------------------------------------------------------------
void castor::BaseCnvSvc::removeAlias(const unsigned int id) {
m_aliases.erase(id);
}
//-----------------------------------------------------------------------------
// converter
//-----------------------------------------------------------------------------
castor::IConverter* castor::BaseCnvSvc::converter
(const unsigned int origObjType)
{
// First uses aliases
unsigned int objType = origObjType;
if (m_aliases.find(objType) != m_aliases.end()) {
objType = m_aliases[objType];
}
// check if we have one
IConverter* conv = m_converters[objType];
if (0 != conv) return conv;
// Try to find one
const castor::ICnvFactory* fac =
castor::Converters::instance()->cnvFactory(repType(), objType);
if (0 == fac) {
castor::exception::Exception e;
e.getMessage() << "No factory found for object type "
<< objType << " and representation type "
<< repType();
throw e;
}
m_converters[objType] = fac->instantiate(this);
if (0!= m_converters[objType]) return m_converters[objType];
// Throw an exception since we did not find any suitable converter
castor::exception::Exception e;
e.getMessage() << "No converter for object type "
<< objType << " and representation type "
<< repType();
throw e;
}
// -----------------------------------------------------------------------
// createRep
// -----------------------------------------------------------------------
void castor::BaseCnvSvc::createRep(castor::IAddress* address,
castor::IObject* object,
bool endTransaction,
unsigned int type)
{
// If no object, nothing to create
if (0 != object) {
// Look for an adapted converter
// The converter is always valid if no exception is thrown
IConverter* conv = converter(object->type());
// convert
conv->createRep(address, object, endTransaction, type);
}
}
// -----------------------------------------------------------------------
// bulkCreateRep
// -----------------------------------------------------------------------
void castor::BaseCnvSvc::bulkCreateRep(castor::IAddress* address,
std::vector<castor::IObject*> &objects,
bool endTransaction,
unsigned int type)
{
// If no object, nothing to create
if (objects.size() > 0) {
// Look for an adapted converter
// The converter is always valid if no exception is thrown
// Note that we assume that all objects have the same type
IConverter* conv = converter(objects[0]->type());
// convert
conv->bulkCreateRep(address, objects, endTransaction, type);
}
}
// -----------------------------------------------------------------------
// updateRep
// -----------------------------------------------------------------------
void castor::BaseCnvSvc::updateRep(castor::IAddress* address,
castor::IObject* object,
bool endTransaction)
{
// If no object, nothing to update
if (0 != object) {
// Look for an adapted converter
// The converter is always valid if no exception is thrown
IConverter* conv = converter(object->type());
// convert
conv->updateRep(address, object, endTransaction);
}
}
// -----------------------------------------------------------------------
// deleteRep
// -----------------------------------------------------------------------
void castor::BaseCnvSvc::deleteRep(castor::IAddress* address,
castor::IObject* object,
bool endTransaction)
{
// Look for an adapted converter
// The converter is always valid if no exception is thrown
IConverter* conv = converter(object->type());
// convert
conv->deleteRep(address, object, endTransaction);
}
// -----------------------------------------------------------------------
// createObj
// -----------------------------------------------------------------------
castor::IObject* castor::BaseCnvSvc::createObj
(castor::IAddress* address)
{
// Look for an adapted converter
// The converter is always valid if no exception is thrown
castor::IConverter* conv = converter(address->objType());
return conv->createObj(address);
}
// -----------------------------------------------------------------------
// bulkCreateObj
// -----------------------------------------------------------------------
std::vector<castor::IObject*> castor::BaseCnvSvc::bulkCreateObj
(castor::IAddress* address)
{
// Look for an adapted converter
// The converter is always valid if no exception is thrown
castor::IConverter* conv = converter(address->objType());
return conv->bulkCreateObj(address);
}
// -----------------------------------------------------------------------
// updateObj
// -----------------------------------------------------------------------
void castor::BaseCnvSvc::updateObj(castor::IObject* object)
{
// Look for an adapted converter
// The converter is always valid if no exception is thrown
castor::IConverter* conv = converter(object->type());
return conv->updateObj(object);
}
//------------------------------------------------------------------------------
// fillRep
//------------------------------------------------------------------------------
void castor::BaseCnvSvc::fillRep(castor::IAddress* address,
castor::IObject* object,
unsigned int type,
bool endTransaction)
{
// Look for an adapted converter
// The converter is always valid if no exception is thrown
castor::IConverter* conv = converter(object->type());
return conv->fillRep(address, object, type, endTransaction);
}
//------------------------------------------------------------------------------
// fillObj
//------------------------------------------------------------------------------
void castor::BaseCnvSvc::fillObj(castor::IAddress* address,
castor::IObject* object,
unsigned int type,
bool endTransaction)
{
// Look for an adapted converter
// The converter is always valid if no exception is thrown
castor::IConverter* conv = converter(object->type());
return conv->fillObj(address, object, type, endTransaction);
}
// -----------------------------------------------------------------------
// deleteRepByAddress
// -----------------------------------------------------------------------
void castor::BaseCnvSvc::deleteRepByAddress (castor::IAddress* address,
bool endTransaction)
{
castor::IObject* obj = createObj(address);
address->setObjType(obj->type());
deleteRep(address, obj, endTransaction);
}
//------------------------------------------------------------------------------
// commit
//------------------------------------------------------------------------------
void castor::BaseCnvSvc::commit()
{
// Default implementation, does nothing.
}
//------------------------------------------------------------------------------
// rollback
//------------------------------------------------------------------------------
void castor::BaseCnvSvc::rollback()
{
// Default implementation, does nothing.
}
//------------------------------------------------------------------------------
// createStatement
//------------------------------------------------------------------------------
castor::db::IDbStatement* castor::BaseCnvSvc::createStatement(const std::string&)
{
// Default implementation, does nothing.
return 0;
}
/******************************************************************************
*
* 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.