<commit_before>//  Copyright 2011 <NAME>
//
//  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 ZIPPYLOG_DEVICE_PERSISTED_STATE_REACTOR_HPP_
#define ZIPPYLOG_DEVICE_PERSISTED_STATE_REACTOR_HPP_

#include <zippylog/zippylog.hpp>
#include <zippylog/device/device.hpp>
#include <zippylog/persisted_state_manager.hpp>
#include <zippylog/store.hpp>

#include <zmq.hpp>

#include <string>

namespace zippylog {
namespace device {

/// Container for parameters used to initialize PersistedStateReactor
class ZIPPYLOG_EXPORT PersistedStateReactorStartParams {
public:
    /// Create a new container
    PersistedStateReactorStartParams() :
        ctx(NULL),
        active(NULL)
    { }

    /// 0MQ context
    ::zmq::context_t *ctx;

    /// Endpoint for socket that should receive store changes
    ::std::string store_change_endpoint;

    /// Endpoint for socket that leads back to clients
    ::std::string client_endpoint;

    /// Endpoint for socket that receives new persisted state requests
    ::std::string subscription_endpoint;

    /// Endpoint for socket that receives updates from clients
    ::std::string subscription_updates_endpoint;

    /// Endpoint for a logger to send logging information
    ::std::string logger_endpoint;

    /// Semaphore stating whether device should remain active
    ::zippylog::platform::ConditionalWait *active;

    /// Parameters used to construct a persisted state observer
    PersistedStateManagerStartParams manager_params;
};

/// Device that reacts to events related to persisted state
///
/// The device is responsible for managing subscriptions and plugins and
/// handling all events that these are interested in.
///
/// Interaction with the device is performed through a number of 0MQ sockets:
///
///   - store_changes - SUB that receives store change notifications
///   - client        - PUSH that sends subscription responses to clients
///   - subscriptions - PULL that receives new subscription requests
///   - subscription_updates - SUB that receives updates concerning existing subscriptions
///   - logger        - PUSH that sends logging info from the device
///
/// The general pattern is to instantiate this class on a thread and call
/// Run(), which will block until the device is shut down.
class ZIPPYLOG_EXPORT PersistedStateReactor : public ::zippylog::device::Device {
public:
    /// Construct a persisted state reactor from parameters
    ///
    /// @params Options to define instance
    PersistedStateReactor(PersistedStateReactorStartParams const &params);

    ~PersistedStateReactor();

    /// Performs work on the device if there is work to be done
    ///
    /// Waits up to the specified time for work to become available, if none is available
    ::zippylog::device::PumpResult Pump(int32 timeout_microseconds);
protected:

    ///@{
    /// Persisted state manager handlers<commit_msg>fix typo in docs<commit_after>//  Copyright 2011 <NAME>
//
//  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 ZIPPYLOG_DEVICE_PERSISTED_STATE_REACTOR_HPP_
#define ZIPPYLOG_DEVICE_PERSISTED_STATE_REACTOR_HPP_

#include <zippylog/zippylog.hpp>
#include <zippylog/device/device.hpp>
#include <zippylog/persisted_state_manager.hpp>
#include <zippylog/store.hpp>

#include <zmq.hpp>

#include <string>

namespace zippylog {
namespace device {

/// Container for parameters used to initialize PersistedStateReactor
class ZIPPYLOG_EXPORT PersistedStateReactorStartParams {
public:
    /// Create a new container
    PersistedStateReactorStartParams() :
        ctx(NULL),
        active(NULL)
    { }

    /// 0MQ context
    ::zmq::context_t *ctx;

    /// Endpoint for socket that should receive store changes
    ::std::string store_change_endpoint;

    /// Endpoint for socket that leads back to clients
    ::std::string client_endpoint;

    /// Endpoint for socket that receives new persisted state requests
    ::std::string subscription_endpoint;

    /// Endpoint for socket that receives updates from clients
    ::std::string subscription_updates_endpoint;

    /// Endpoint for a logger to send logging information
    ::std::string logger_endpoint;

    /// Semaphore stating whether device should remain active
    ::zippylog::platform::ConditionalWait *active;

    /// Parameters used to construct a persisted state observer
    PersistedStateManagerStartParams manager_params;
};

/// Device that reacts to events related to persisted state
///
/// The device is responsible for managing subscriptions and plugins and
/// handling all events that these are interested in.
///
/// Interaction with the device is performed through a number of 0MQ sockets:
///
///   - store_changes - SUB that receives store change notifications
///   - client        - PUSH that sends subscription responses to clients
///   - subscriptions - PULL that receives new subscription requests
///   - subscription_updates - SUB that receives updates concerning existing subscriptions
///   - logger        - PUSH that sends logging info from the device
///
/// The general pattern is to instantiate this class on a thread and call
/// Run(), which will block until the device is shut down.
class ZIPPYLOG_EXPORT PersistedStateReactor : public ::zippylog::device::Device {
public:
    /// Construct a persisted state reactor from parameters
    ///
    /// @param params Options to define instance
    PersistedStateReactor(PersistedStateReactorStartParams const &params);

    ~PersistedStateReactor();

    /// Performs work on the device if there is work to be done
    ///
    /// Waits up to the specified time for work to become available, if none is available
    ::zippylog::device::PumpResult Pump(int32 timeout_microseconds);
protected:

    ///@{
    /// Persisted state manager handlers
{'fraction_non_alphanumeric': 0.08432495960041134, 'fraction_numerical': 0.0035257822829440283, 'mean_word_length': 3.4294079375406636, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7479685', 'n_tokens_mistral': 1799, 'n_tokens_neox': 1745, 'n_words': 707}