RecallReportPacker.hpp 4.48 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
/******************************************************************************
 *                      RecallReportPacker.hpp
 *
 * 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
 *****************************************************************************/

25
#pragma once
26
27
28

#include "castor/tape/tapeserver/daemon/ReportPackerInterface.hpp"
#include "castor/log/LogContext.hpp"
29
#include "castor/tape/tapeserver/client/ClientInterface.hpp"
30
31
32
33
34
35
36
37
#include "castor/tape/tapeserver/threading/Threading.hpp"
#include "castor/tape/tapeserver/threading/BlockingQueue.hpp"

namespace castor {
namespace tape {
namespace tapeserver {
namespace daemon {
  
38
class RecallReportPacker : protected ReportPackerInterface<detail::Recall> {
39
public:
40
41
  RecallReportPacker(client::ClientInterface & tg,unsigned int reportFilePeriod,
          log::LogContext lc);
42
43
44
45
46
47
48
49
  
  ~RecallReportPacker();
  
  /**
   * Create into the MigrationReportPacker a report for the successful migration
   * of migratedFile
   * @param migratedFile the file successfully migrated
   */
50
  virtual void reportCompletedJob(const FileStruct& recalledFile,
David COME's avatar
David COME committed
51
  unsigned long checksum);
52
53
  
  /**
54
   * Create into the MigrationReportPacker a report for the failed migration
55
   * of migratedFile
56
   * @param migratedFile the file which failed 
57
   */
58
  virtual void reportFailedJob(const FileStruct & recalledFile,const std::string& msg,int error_code);
59
60
61
62
       
  /**
   * Create into the MigrationReportPacker a report for the nominal end of session
   */
63
  virtual void reportEndOfSession();
64
65
66
67
68
69
  
  /**
   * Create into the MigrationReportPacker a report for an erroneous end of session
   * @param msg The error message 
   * @param error_code The error code given by the drive
   */
70
  virtual void reportEndOfSessionWithErrors(const std::string msg,int error_code);
71
  
72
73
  void startThreads() { m_workerThread.start(); }
  void waitThread() { m_workerThread.wait(); }
74
75
76
  
private:
  class Report {
77
    const bool m_endNear;
78
  public:
79
    Report(bool b):m_endNear(b){}
80
81
    virtual ~Report(){}
    virtual void execute(RecallReportPacker& packer)=0;
82
    bool goingToEnd() const {return m_endNear;};
83
84
85
  };
  class ReportSuccessful :  public Report {
    const FileStruct m_migratedFile;
David COME's avatar
David COME committed
86
    unsigned long m_checksum;
87
  public:
David COME's avatar
David COME committed
88
89
    ReportSuccessful(const FileStruct& file,unsigned long checksum): 
    Report(false),m_migratedFile(file),m_checksum(checksum){}
90
91
92
93
94
95
96
97
    virtual void execute(RecallReportPacker& _this);
  };
  class ReportError : public Report {
    const FileStruct m_migratedFile;
    const std::string m_error_msg;
    const int m_error_code;
  public:
    ReportError(const FileStruct& file,std::string msg,int error_code):
98
    Report(false),m_migratedFile(file),m_error_msg(msg),m_error_code(error_code){}
99

100
101
102
103
    virtual void execute(RecallReportPacker& _this);
  };
  class ReportEndofSession : public Report {
  public:
104
    ReportEndofSession():Report(true){}
105
106
107
108
109
110
111
    virtual void execute(RecallReportPacker& _this);
  };
  class ReportEndofSessionWithErrors : public Report {
    std::string m_message;
    int m_error_code;
  public:
    ReportEndofSessionWithErrors(std::string msg,int error_code):
112
    Report(true),m_message(msg),m_error_code(error_code){}
113
  
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
    virtual void execute(RecallReportPacker& _this);
  };
  
  class WorkerThread: public castor::tape::threading::Thread {
    RecallReportPacker & m_parent;
  public:
    WorkerThread(RecallReportPacker& parent);
    virtual void run();
  } m_workerThread;
  
  void flush();
  
  castor::tape::threading::Mutex m_producterProtection;
  
  /** 
   * m_fifo is holding all the report waiting to be processed
   */
  castor::tape::threading::BlockingQueue<Report*> m_fifo;
  
  unsigned int m_reportFilePeriod;
  bool m_errorHappened;
};

}}}}