GenericObject.hpp 3.92 KB
Newer Older
1
/*
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
 * 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/>.
 */

19
20
21
22
23
24
25
#pragma once

#include "ObjectOps.hpp"
#include "objectstore/cta.pb.h"

namespace cta {  namespace objectstore {

26
class GenericObject: public ObjectOps<serializers::GenericObject, serializers::GenericObject_t> {
27
28
public:
  GenericObject(const std::string & name, Backend & os):
29
    ObjectOps<serializers::GenericObject, serializers::GenericObject_t>(os, name) {};
30
    
31
32
  CTA_GENERATE_EXCEPTION_CLASS(ForbiddenOperation);
  
33
34
35
36
37
38
39
  /** This object has a special, relaxed version of header parsing as all types
   * of objects are accepted here. */
  void getHeaderFromObjectData(const std::string& objData) override;

  /** Overload of ObjectOps's implementation: this special object does not really 
   parse its payload */
  void getPayloadFromHeader() override {}
40
  
41
42
  /** Overload of ObjectOps's implementation: we will leave the payload transparently
   * untouched and only deal with header parameters */
43
44
  void commit();
  
45
  /** Get the object's type (type is forced implicitly in other classes) */
46
47
  serializers::ObjectType type();
  
48
49
  /** Overload of ObjectOps's implementation: this operation is forbidden. Generic
   * Object is only used to manipulate existing objects */
50
51
  void insert();
  
52
53
  /** Overload of ObjectOps's implementation: this operation is forbidden. Generic
   * Object is only used to manipulate existing objects */
54
55
  void initialize();
  
56
57
  /** Overload of ObjectOps's implementation: this operation is forbidden. Generic
   * Object cannot be garbage collected as-is */
58
59
  void garbageCollect(const std::string& presumedOwner, AgentReference & agentReference, log::LogContext & lc,
    cta::catalogue::Catalogue & catalogue) override;
60
  
61
62
63
64
  /** This dispatcher function will call the object's garbage collection function.
   * It also handles the passed lock and returns is unlocked.
   * The object is expected to be passed exclusive locked and already fetched.
   * No extra care will be required from the object
65
66
67
   *
   * @param lock reference to the generic object's lock
   * @param presumedOwner address of the agent which pointed to the object
68
   * @param agent reference object allowing creation of new objects when needed (at least for requeuing of requests)
69
   * @params lc log context passed to garbage collection routines to log GC steps.
Eric Cano's avatar
Eric Cano committed
70
   * @params catalogue reference to the catalogue, used by some garbage collection routines (specially for RetrieveRequests
71
   * which are tape status dependent.
72
   */
73
74
  void garbageCollectDispatcher(ScopedExclusiveLock & lock, const std::string &presumedOwner, AgentReference & agentReference, 
    log::LogContext & lc, cta::catalogue::Catalogue & catalogue);
75
  
Eric Cano's avatar
Eric Cano committed
76
77
78
79
80
  /** This dispatcher function will call the object's dump.
   * It also handles the passed lock.
   *
   * @param lock reference to the generic object's lock
   */
81
  std::string dump();
Eric Cano's avatar
Eric Cano committed
82
  
83
84
85
86
87
88
89
90
91
92
93
94
95
96
  CTA_GENERATE_EXCEPTION_CLASS(UnsupportedType);
  
  /**
   * This method will extract contents of the generic object's header and
   * transfer them to the header of the destination
   * The source (this) will be emptied.
   * @param destination pointed to the new object's destination
   */
  void transplantHeader(ObjectOpsBase & destination);
  
  /**
   * This method exposes the reference to the object store.
   */
  Backend & objectStore();
97
98
99
100
};

}}