-
Notifications
You must be signed in to change notification settings - Fork 389
/
SourceQueue.h
55 lines (47 loc) · 1.71 KB
/
SourceQueue.h
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/**
* Copyright (c) 2014-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/
#pragma once
#include <wdt/ByteSource.h>
#include <memory>
namespace facebook {
namespace wdt {
/**
* Interface for consuming data from multiple ByteSource's.
* Call getNextSource() repeatedly to get new sources to consume data
* from, until finished() returns true.
*
* This class is thread-safe, i.e. multiple threads can consume sources
* in parallel and terminate once finished() returns true. Each source
* is guaranteed to be consumed exactly once.
*/
class SourceQueue {
public:
virtual ~SourceQueue() {
}
/// @return true iff no more sources to read from
virtual bool finished() const = 0;
/**
* Get the next source to consume. Ownership transfers to the caller.
* The method will block until it's able to get the next available source
* or be sure consumption of all sources has finished.
*
* @param threadCtx context of the caller thread
* @param status this variable is set to true, if the transfer has already
*
* @return New ByteSource to consume or nullptr if there are
* no more sources to read from (equivalent to finished()).
*/
virtual std::unique_ptr<ByteSource> getNextSource(ThreadCtx *threadCtx,
ErrorCode &status) = 0;
/// @return total number of files processed/enqueued
virtual int64_t getCount() const = 0;
/// @return total size of files processed/enqueued
virtual int64_t getTotalSize() const = 0;
};
} // namespace wdt
} // namespace facebook