-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cf9189c
commit 5d50be1
Showing
12 changed files
with
149 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <string> | ||
#include <chrono> | ||
|
||
namespace org::apache::nifi::minifi::utils::timeutils { | ||
|
||
/** | ||
* Mockable clock classes | ||
*/ | ||
class Clock { | ||
public: | ||
virtual ~Clock() = default; | ||
virtual std::chrono::milliseconds timeSinceEpoch() const = 0; | ||
virtual bool wait_until(std::condition_variable& cv, std::unique_lock<std::mutex>& lck, std::chrono::milliseconds time, const std::function<bool()>& pred) { | ||
return cv.wait_for(lck, time - timeSinceEpoch(), pred); | ||
} | ||
}; | ||
|
||
class SteadyClock : public Clock { | ||
public: | ||
std::chrono::milliseconds timeSinceEpoch() const override { | ||
return std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::steady_clock::now().time_since_epoch()); | ||
} | ||
|
||
virtual std::chrono::time_point<std::chrono::steady_clock> now() const { | ||
return std::chrono::steady_clock::now(); | ||
} | ||
}; | ||
|
||
std::shared_ptr<SteadyClock> getClock(); | ||
|
||
// test-only utility to specify what clock to use | ||
void setClock(std::shared_ptr<SteadyClock> clock); | ||
|
||
#ifdef WIN32 | ||
void dateSetGlobalInstall(const std::string& install); | ||
#endif | ||
|
||
} // namespace org::apache::nifi::minifi::utils::timeutils | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
#include "http/HTTPClient.h" | ||
#include "core/Resource.h" | ||
|
||
namespace org::apache::nifi::minifi::http { | ||
|
||
REGISTER_RESOURCE(HTTPClient, InternalResource); | ||
|
||
} // namespace org::apache::nifi::minifi::http |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
|
||
#include "utils/TimeUtil.h" | ||
#ifdef WIN32 | ||
#include "date/tz.h" | ||
#endif | ||
|
||
namespace org::apache::nifi::minifi::utils::timeutils { | ||
|
||
static std::mutex global_clock_mtx; | ||
static std::shared_ptr<SteadyClock> global_clock{std::make_shared<SteadyClock>()}; | ||
|
||
std::shared_ptr<SteadyClock> getClock() { | ||
std::lock_guard lock(global_clock_mtx); | ||
return global_clock; | ||
} | ||
|
||
// test-only utility to specify what clock to use | ||
void setClock(std::shared_ptr<SteadyClock> clock) { | ||
std::lock_guard lock(global_clock_mtx); | ||
global_clock = std::move(clock); | ||
} | ||
|
||
#ifdef WIN32 | ||
void dateSetGlobalInstall(const std::string& install) { | ||
date::set_install(install); | ||
} | ||
#endif | ||
|
||
|
||
} // namespace org::apache::nifi::minifi::utils::timeutils | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters