Skip to content

Commit

Permalink
[C++]: more of the archive API.
Browse files Browse the repository at this point in the history
  • Loading branch information
tmontgomery committed Feb 28, 2019
1 parent a0c4e61 commit bf4afa9
Show file tree
Hide file tree
Showing 5 changed files with 120 additions and 4 deletions.
4 changes: 3 additions & 1 deletion aeron-archive/src/main/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,14 @@ add_custom_command(OUTPUT ${GENERATED_CODECS}
add_custom_target(codecs DEPENDS ${GENERATED_CODECS})

SET(SOURCE
client/ArchiveProxy.cpp)
client/ArchiveProxy.cpp
client/AeronArchive.cpp)

SET(HEADERS
client/ArchiveException.h
client/ArchiveConfiguration.h
client/ArchiveProxy.h
client/ControlResponsePoller.h
client/AeronArchive.h)

set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -DDISABLE_BOUNDS_CHECKS")
Expand Down
25 changes: 25 additions & 0 deletions aeron-archive/src/main/cpp/client/AeronArchive.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Copyright 2014-2019 Real Logic Ltd.
*
* Licensed 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 "AeronArchive.h"

using namespace aeron::archive::client;

template<typename IdleStrategy>
std::shared_ptr<AeronArchive<IdleStrategy>> AeronArchive<IdleStrategy>::AsyncConnect::poll()
{
return std::make_shared<AeronArchive<IdleStrategy>>();
}
38 changes: 35 additions & 3 deletions aeron-archive/src/main/cpp/client/AeronArchive.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@

#include "Aeron.h"
#include "ArchiveConfiguration.h"
#include "ControlResponsePoller.h"
#include "concurrent/BackOffIdleStrategy.h"
#include "concurrent/YieldingIdleStrategy.h"

namespace aeron {
namespace archive {
Expand All @@ -33,20 +35,50 @@ class AeronArchive
AeronArchive(Context_t& context);
~AeronArchive();

class AsyncConnect
{
public:
AsyncConnect(Context_t& context);
~AsyncConnect();

std::shared_ptr<AeronArchive> poll();
private:
Context_t m_ctx;
};

static std::unique_ptr<AsyncConnect> asyncConnect(Context_t& context);

inline static std::unique_ptr<AsyncConnect> asyncConnect()
{
Context_t ctx;
return AeronArchive::asyncConnect(ctx);
}

template<typename ConnectIdleStrategy = aeron::concurrent::YieldingIdleStrategy>
inline static std::shared_ptr<AeronArchive> connect(Context_t& context)
{
return std::make_shared<AeronArchive>(context);
std::unique_ptr<AsyncConnect> asyncConnect = AeronArchive::asyncConnect(context);
ConnectIdleStrategy idle;

std::shared_ptr<AeronArchive> archive = asyncConnect->poll();
while (nullptr == *archive)
{
idle.idle();
archive = asyncConnect->poll();
}

return archive;
}

inline static std::shared_ptr<AeronArchive> connect()
{
Context_t ctx;
return connect(ctx);
return AeronArchive::connect(ctx);
}

private:
std::shared_ptr<Aeron> m_aeron;
Context_t m_context;
Context_t m_ctx;
IdleStrategy m_idle;
};

Expand Down
10 changes: 10 additions & 0 deletions aeron-archive/src/main/cpp/client/ArchiveProxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,16 @@ class ArchiveProxy
{
}

inline std::shared_ptr<Publication> publication()
{
return m_publication;
}

inline void publication(std::shared_ptr<Publication> publication)
{
m_publication = std::move(publication);
}

bool connect(
const std::string& responseChannel,
std::int32_t responseStreamId,
Expand Down
47 changes: 47 additions & 0 deletions aeron-archive/src/main/cpp/client/ControlResponsePoller.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Copyright 2014-2019 Real Logic Ltd.
*
* Licensed 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.
*/
#ifndef AERON_ARCHIVE_CONTROLRESPONSEPOLLER_H
#define AERON_ARCHIVE_CONTROLRESPONSEPOLLER_H

#include "Aeron.h"

namespace aeron {
namespace archive {
namespace client {

class ControlResponsePoller
{
public:
ControlResponsePoller(std::shared_ptr<Subscription> subscription, int fragmentLimit = 10);
~ControlResponsePoller();

inline std::shared_ptr<Subscription> subscription()
{
return m_subscription;
}

inline void subscription(std::shared_ptr<Subscription> subscription)
{
m_subscription = std::move(subscription);
}
private:
std::shared_ptr<Subscription> m_subscription;
const int m_fragmentLimit;

};

}}}
#endif //AERON_ARCHIVE_CONTROLRESPONSEPOLLER_H

0 comments on commit bf4afa9

Please sign in to comment.