DiskReadTask.hpp 3.22 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
25
/******************************************************************************
 *
 * 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

David COME's avatar
David COME committed
26
#include "castor/tape/tapeserver/daemon/DataPipeline.hpp"
27
#include "castor/tape/tapeserver/daemon/DataConsumer.hpp"
28
#include "castor/tape/tapeserver/daemon/DiskStats.hpp"
29
#include "castor/tape/tapeserver/daemon/ErrorFlag.hpp"
30
#include "castor/tape/tapegateway/FileToMigrateStruct.hpp"
31
#include "castor/server/AtomicFlag.hpp"
32
#include "castor/log/LogContext.hpp"
33
#include "castor/tape/tapeserver/file/DiskFile.hpp"
34

David COME's avatar
David COME committed
35
36
37
38
39
namespace castor {
namespace tape {
namespace tapeserver {
namespace daemon {
  
40
class DiskReadTask {
41
public:
42
43
44
45
46
  /**
   * @param destination The task that will consume data block we fill up
   * @param file the file we are migrating. We acquire the ownership of the pointer
   * @param numberOfBlock number of memory block we need read the whole file
   */
47
  DiskReadTask(DataConsumer & destination, 
48
          tape::tapegateway::FileToMigrateStruct* file,size_t numberOfBlock,
49
          castor::server::AtomicFlag& errorFlag);
50
  
51
  void execute(log::LogContext& lc, diskFile::DiskFileFactory & fileFactory);
52
53
54
55
56
57
    /**
   * Return the stats of the tasks. Should be call after execute 
   * (otherwise, it is pointless)
   * @return 
   */
  const DiskStats getTaskStats() const;
58
private:
59
60
61
62
63
64
65
66
67
  
  /**
   * Stats to measue how long it takes to write on disk
   */
  DiskStats m_stats;
  
  /**
   * Throws an exception if m_errorFlag is set
   */
68
  void checkMigrationFailing() const {
69
70
    //if a task has signaled an error, we stop our job
    if(m_errorFlag){
71
      throw  castor::tape::tapeserver::daemon::ErrorFlag();
72
73
    }
  }
74
  
75
  /**
76
77
78
79
80
81
82
   * log into lc all m_stats parameters with the given message at the 
   * given level
   * @param level
   * @param message
   */
  void logWithStat(int level,const std::string& msg,log::LogContext& lc) ;
  
83
  void circulateAllBlocks(size_t fromBlockId, MemBlock * mb);
84
85
86
  /**
   * The task (a TapeWriteTask) that will handle the read blocks
   */
87
  DataConsumer & m_nextTask;
88
89
90
91
  
  /**
   * All we need to know about the file we are migrating
   */
92
  std::auto_ptr<tape::tapegateway::FileToMigrateStruct> m_migratedFile;
93
94
95
96
  
  /**
   * The number of memory block we will need to read the whole file
   */
97
  size_t m_numberOfBlock;
98
  
99
  castor::server::AtomicFlag& m_errorFlag;
100
};
David COME's avatar
David COME committed
101
102

}}}}
103