Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/ci-build-binary-artifacts.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ jobs:
mkdir -p $BUILD_DIR
cmake -B $BUILD_DIR \
-G "${{ matrix.generator }}" ${{ matrix.arch }} \
-DUSE_ASIO=ON \
-DBUILD_TESTS=OFF \
-DVCPKG_TRIPLET=${{ matrix.triplet }} \
-DCMAKE_INSTALL_PREFIX=${{ env.INSTALL_DIR }} \
Expand All @@ -174,6 +175,7 @@ jobs:
mkdir -p $BUILD_DIR
cmake -B $BUILD_DIR \
-G "${{ matrix.generator }}" ${{ matrix.arch }} \
-DUSE_ASIO=ON \
-DBUILD_TESTS=OFF \
-DVCPKG_TRIPLET=${{ matrix.triplet }} \
-DCMAKE_INSTALL_PREFIX=$INSTALL_DIR_DEBUG \
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/ci-pr-validation.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ jobs:
cmake \
-B ./build-1 \
-G "${{ matrix.generator }}" ${{ matrix.arch }} \
-DUSE_ASIO=ON \
-DBUILD_TESTS=OFF \
-DVCPKG_TRIPLET="${{ matrix.triplet }}" \
-DCMAKE_INSTALL_PREFIX="${{ env.INSTALL_DIR }}" \
Expand Down Expand Up @@ -232,6 +233,7 @@ jobs:
cmake \
-B ./build-2 \
-G "${{ matrix.generator }}" ${{ matrix.arch }} \
-DUSE_ASIO=ON \
-DBUILD_TESTS=OFF \
-DVCPKG_TRIPLET="${{ matrix.triplet }}" \
-DCMAKE_INSTALL_PREFIX="${{ env.INSTALL_DIR }}" \
Expand Down
11 changes: 11 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@

cmake_minimum_required(VERSION 3.13)

option(USE_ASIO "Use Asio instead of Boost.Asio" OFF)

option(INTEGRATE_VCPKG "Integrate with Vcpkg" OFF)
if (INTEGRATE_VCPKG)
set(USE_ASIO ON)
set(CMAKE_TOOLCHAIN_FILE "${CMAKE_SOURCE_DIR}/vcpkg/scripts/buildsystems/vcpkg.cmake")
endif ()

Expand Down Expand Up @@ -129,6 +132,10 @@ if (INTEGRATE_VCPKG)
$<IF:$<TARGET_EXISTS:zstd::libzstd_shared>,zstd::libzstd_shared,zstd::libzstd_static>
Snappy::snappy
)
if (USE_ASIO)
find_package(asio CONFIG REQUIRED)
set(COMMON_LIBS ${COMMON_LIBS} asio::asio)
endif ()
add_definitions(-DHAS_ZSTD -DHAS_SNAPPY)
if (MSVC)
find_package(dlfcn-win32 CONFIG REQUIRED)
Expand All @@ -140,6 +147,10 @@ else ()
include(./LegacyFindPackages.cmake)
endif ()

if (USE_ASIO)
add_definitions(-DUSE_ASIO)
endif ()

set(LIB_NAME $ENV{PULSAR_LIBRARY_NAME})
if (NOT LIB_NAME)
set(LIB_NAME pulsar)
Expand Down
4 changes: 0 additions & 4 deletions LegacyFindPackages.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,6 @@ if (Boost_MAJOR_VERSION EQUAL 1 AND Boost_MINOR_VERSION LESS 69)
MESSAGE(STATUS "Linking with Boost:System")
endif()

if (MSVC)
set(BOOST_COMPONENTS ${BOOST_COMPONENTS} date_time)
endif()

if (CMAKE_COMPILER_IS_GNUCC AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.9)
# GCC 4.8.2 implementation of std::regex is buggy
set(BOOST_COMPONENTS ${BOOST_COMPONENTS} regex)
Expand Down
6 changes: 3 additions & 3 deletions lib/AckGroupingTrackerEnabled.cc
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ void AckGroupingTrackerEnabled::close() {
this->flush();
std::lock_guard<std::mutex> lock(this->mutexTimer_);
if (this->timer_) {
boost::system::error_code ec;
ASIO_ERROR ec;
this->timer_->cancel(ec);
}
}
Expand Down Expand Up @@ -168,9 +168,9 @@ void AckGroupingTrackerEnabled::scheduleTimer() {

std::lock_guard<std::mutex> lock(this->mutexTimer_);
this->timer_ = this->executor_->createDeadlineTimer();
this->timer_->expires_from_now(boost::posix_time::milliseconds(std::max(1L, this->ackGroupingTimeMs_)));
this->timer_->expires_from_now(std::chrono::milliseconds(std::max(1L, this->ackGroupingTimeMs_)));
auto self = shared_from_this();
this->timer_->async_wait([this, self](const boost::system::error_code& ec) -> void {
this->timer_->async_wait([this, self](const ASIO_ERROR& ec) -> void {
if (!ec) {
this->flush();
this->scheduleTimer();
Expand Down
3 changes: 1 addition & 2 deletions lib/AckGroupingTrackerEnabled.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,17 @@
#include <pulsar/MessageId.h>

#include <atomic>
#include <boost/asio/deadline_timer.hpp>
#include <cstdint>
#include <mutex>
#include <set>

#include "AckGroupingTracker.h"
#include "AsioTimer.h"

namespace pulsar {

class ClientImpl;
using ClientImplPtr = std::shared_ptr<ClientImpl>;
using DeadlineTimerPtr = std::shared_ptr<boost::asio::deadline_timer>;
class ExecutorService;
using ExecutorServicePtr = std::shared_ptr<ExecutorService>;
class HandlerBase;
Expand Down
32 changes: 32 additions & 0 deletions lib/AsioDefines.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* 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.
*/
// This header defines common macros to use Asio or Boost.Asio.
#pragma once

#ifdef USE_ASIO
#define ASIO ::asio
#define ASIO_ERROR asio::error_code
#define ASIO_SUCCESS (ASIO_ERROR{})
#define ASIO_SYSTEM_ERROR asio::system_error
#else
#define ASIO boost::asio
#define ASIO_ERROR boost::system::error_code
#define ASIO_SUCCESS boost::system::errc::make_error_code(boost::system::errc::success)
#define ASIO_SYSTEM_ERROR boost::system::system_error
#endif
19 changes: 9 additions & 10 deletions lib/TimeUtils.cc → lib/AsioTimer.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,16 @@
* specific language governing permissions and limitations
* under the License.
*/
#pragma once

#include "TimeUtils.h"
#ifdef USE_ASIO
#include <asio/steady_timer.hpp>
#else
#include <boost/asio/steady_timer.hpp>
#endif

namespace pulsar {
#include <memory>

ptime TimeUtils::now() { return microsec_clock::universal_time(); }
#include "AsioDefines.h"

int64_t TimeUtils::currentTimeMillis() {
static ptime time_t_epoch(boost::gregorian::date(1970, 1, 1));

time_duration diff = now() - time_t_epoch;
return diff.total_milliseconds();
}
} // namespace pulsar
using DeadlineTimerPtr = std::shared_ptr<ASIO::steady_timer>;
7 changes: 5 additions & 2 deletions lib/Backoff.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
#include <time.h> /* time */

#include <algorithm>
#include <chrono>

#include "TimeUtils.h"

namespace pulsar {

Expand All @@ -33,8 +36,8 @@ TimeDuration Backoff::next() {

// Check for mandatory stop
if (!mandatoryStopMade_) {
const boost::posix_time::ptime& now = boost::posix_time::microsec_clock::universal_time();
TimeDuration timeElapsedSinceFirstBackoff = boost::posix_time::milliseconds(0);
auto now = TimeUtils::now();
TimeDuration timeElapsedSinceFirstBackoff = std::chrono::nanoseconds(0);
if (initial_ == current) {
firstBackoffTime_ = now;
} else {
Expand Down
8 changes: 4 additions & 4 deletions lib/Backoff.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@
#define _PULSAR_BACKOFF_HEADER_
#include <pulsar/defines.h>

#include <boost/date_time/posix_time/posix_time.hpp>
#include <chrono>
#include <random>

namespace pulsar {
#include "TimeUtils.h"

using TimeDuration = boost::posix_time::time_duration;
namespace pulsar {

class PULSAR_PUBLIC Backoff {
public:
Expand All @@ -38,7 +38,7 @@ class PULSAR_PUBLIC Backoff {
const TimeDuration max_;
TimeDuration next_;
TimeDuration mandatoryStop_;
boost::posix_time::ptime firstBackoffTime_;
decltype(std::chrono::high_resolution_clock::now()) firstBackoffTime_;
std::mt19937 rng_;
bool mandatoryStopMade_ = false;

Expand Down
Loading