MINIFI-34 Establishing CMake build system to provide build functionality equivalent...
[nifi-minifi-cpp.git] / libminifi / include / GetFile.h
1 /**
2 * @file GetFile.h
3 * GetFile class declaration
4 *
5 * Licensed to the Apache Software Foundation (ASF) under one or more
6 * contributor license agreements. See the NOTICE file distributed with
7 * this work for additional information regarding copyright ownership.
8 * The ASF licenses this file to You under the Apache License, Version 2.0
9 * (the "License"); you may not use this file except in compliance with
10 * the License. You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 */
20 #ifndef __GET_FILE_H__
21 #define __GET_FILE_H__
22
23 #include "FlowFileRecord.h"
24 #include "Processor.h"
25 #include "ProcessSession.h"
26
27 //! GetFile Class
28 class GetFile : public Processor
29 {
30 public:
31 //! Constructor
32 /*!
33 * Create a new processor
34 */
35 GetFile(std::string name, uuid_t uuid = NULL)
36 : Processor(name, uuid)
37 {
38 _logger = Logger::getLogger();
39 _directory = ".";
40 _recursive = true;
41 _keepSourceFile = false;
42 _minAge = 0;
43 _maxAge = 0;
44 _minSize = 0;
45 _maxSize = 0;
46 _ignoreHiddenFile = true;
47 _pollInterval = 0;
48 _batchSize = 10;
49 _lastDirectoryListingTime = getTimeMillis();
50 _fileFilter = "[^\\.].*";
51 }
52 //! Destructor
53 virtual ~GetFile()
54 {
55 }
56 //! Processor Name
57 static const std::string ProcessorName;
58 //! Supported Properties
59 static Property Directory;
60 static Property Recurse;
61 static Property KeepSourceFile;
62 static Property MinAge;
63 static Property MaxAge;
64 static Property MinSize;
65 static Property MaxSize;
66 static Property IgnoreHiddenFile;
67 static Property PollInterval;
68 static Property BatchSize;
69 static Property FileFilter;
70 //! Supported Relationships
71 static Relationship Success;
72
73 public:
74 //! OnTrigger method, implemented by NiFi GetFile
75 virtual void onTrigger(ProcessContext *context, ProcessSession *session);
76 //! Initialize, over write by NiFi GetFile
77 virtual void initialize(void);
78 //! perform directory listing
79 void performListing(std::string dir);
80
81 protected:
82
83 private:
84 //! Logger
85 Logger *_logger;
86 //! Queue for store directory list
87 std::queue<std::string> _dirList;
88 //! Get Listing size
89 uint64_t getListingSize() {
90 std::lock_guard<std::mutex> lock(_mtx);
91 return _dirList.size();
92 }
93 //! Whether the directory listing is empty
94 bool isListingEmpty();
95 //! Put full path file name into directory listing
96 void putListing(std::string fileName);
97 //! Poll directory listing for files
98 void pollListing(std::queue<std::string> &list, int maxSize);
99 //! Check whether file can be added to the directory listing
100 bool acceptFile(std::string fileName);
101 //! Mutex for protection of the directory listing
102 std::mutex _mtx;
103 std::string _directory;
104 bool _recursive;
105 bool _keepSourceFile;
106 int64_t _minAge;
107 int64_t _maxAge;
108 int64_t _minSize;
109 int64_t _maxSize;
110 bool _ignoreHiddenFile;
111 int64_t _pollInterval;
112 int64_t _batchSize;
113 uint64_t _lastDirectoryListingTime;
114 std::string _fileFilter;
115 };
116
117 #endif