BackendPopulator.cpp 2.29 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
/*
 * The CERN Tape Archive (CTA) project
 * Copyright (C) 2015  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 3 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, see <http://www.gnu.org/licenses/>.
 */

#include "objectstore/BackendVFS.hpp"
#include "objectstore/RootEntry.hpp"
21
#include "objectstore/BackendPopulator.hpp"
22

23
24
namespace cta { namespace objectstore {

25
26
27
//------------------------------------------------------------------------------
// Constructor
//------------------------------------------------------------------------------
28
BackendPopulator::BackendPopulator(cta::objectstore::Backend & be): m_backend(be), m_agentReference("OStoreDBFactory") {
29
30
31
  cta::objectstore::RootEntry re(m_backend);
  cta::objectstore::ScopedExclusiveLock rel(re);
  re.fetch();
32
33
  Agent agent(m_agentReference.getAgentAddress(), m_backend);
  agent.initialize();
34
  cta::objectstore::EntryLogSerDeser cl("user0", "systemhost", time(NULL));
35
  re.addOrGetAgentRegisterPointerAndCommit(m_agentReference, cl);
36
  rel.release();
37
  agent.insertAndRegisterSelf();
38
  rel.lock(re);
39
  re.addOrGetDriveRegisterPointerAndCommit(m_agentReference, cl);
40
41
42
43
44
45
46
  rel.release();
}

//------------------------------------------------------------------------------
// Destructor
//------------------------------------------------------------------------------
BackendPopulator::~BackendPopulator() throw() {
47
48
49
50
  Agent agent(m_agentReference.getAgentAddress(), m_backend);
  cta::objectstore::ScopedExclusiveLock agl(agent);
  agent.fetch();
  agent.removeAndUnregisterSelf();
51
52
53
54
55
}

//------------------------------------------------------------------------------
// getAgent
//------------------------------------------------------------------------------
56
57
cta::objectstore::AgentReference & BackendPopulator::getAgentReference() {
  return m_agentReference;
58
59
60
}

}}