<commit_before>/*
 * Copyright (c) 2008-2020, Hazelcast, Inc. All Rights Reserved.
 *
 * 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.
 */

/*
 * Copyright (c) 2008-2020, Hazelcast, Inc. All Rights Reserved.
 *
 * 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 <vector>
#include <functional>
#include <boost/format.hpp>

#include "hazelcast/util/Util.h"
#include "hazelcast/util/IOUtil.h"
#include "hazelcast/client/hazelcast_client.h"
#include "hazelcast/client/transaction_context.h"
#include "hazelcast/client/cluster.h"
#include "hazelcast/client/spi/lifecycle_service.h"
#include "hazelcast/client/lifecycle_listener.h"
#include <hazelcast/client/exception/protocol_exceptions.h>
#include "hazelcast/client/impl/hazelcast_client_instance_impl.h"
#include "hazelcast/client/impl/ClientLockReferenceIdGenerator.h"
#include "hazelcast/client/spi/impl/ClientInvocationServiceImpl.h"
#include "hazelcast/client/spi/impl/ClientPartitionServiceImpl.h"
#include "hazelcast/client/spi/impl/ClientExecutionServiceImpl.h"
#include "hazelcast/client/spi/impl/sequence/CallIdFactory.h"
#include "hazelcast/client/spi/impl/AwsAddressProvider.h"
#include "hazelcast/client/spi/impl/DefaultAddressProvider.h"
#include "hazelcast/client/aws/impl/AwsAddressTranslator.h"
#include "hazelcast/client/spi/impl/DefaultAddressTranslator.h"
#include "hazelcast/client/spi/impl/listener/listener_service_impl.h"
#include "hazelcast/client/load_balancer.h"
#include "hazelcast/client/connection/ClientConnectionManagerImpl.h"
#include "hazelcast/client/proxy/flake_id_generator_impl.h"
#include "hazelcast/logger.h"
#include "hazelcast/client/member_selectors.h"

#ifndef HAZELCAST_VERSION
#define HAZELCAST_VERSION "NOT_FOUND"
#endif

namespace hazelcast {
    namespace client {
        hazelcast_client::hazelcast_client() : client_impl_(new impl::hazelcast_client_instance_impl(client_config())) {
            client_impl_->start();
        }

        hazelcast_client::hazelcast_client(client_config config) : client_impl_(
                new impl::hazelcast_client_instance_impl(std::move(config))) {
            client_impl_->start();
        }

        const std::string &hazelcast_client::get_name() const {
            return client_impl_->get_name();
        }

        client_config &hazelcast_client::get_client_config() {
            return client_impl_->get_client_config();
        }

        transaction_context hazelcast_client::new_transaction_context() {
            return client_impl_->new_transaction_context();
        }

        transaction_context hazelcast_client::new_transaction_context(const transaction_options &options) {
            return client_impl_->new_transaction_context(options);
        }

        cluster &hazelcast_client::get_cluster() {
            return client_impl_->get_cluster();
        }

        boost::uuids::uuid hazelcast_client::add_lifecycle_listener(lifecycle_listener &&lifecycle_listener) {
            return client_impl_->add_lifecycle_listener(std::move(lifecycle_listener));
        }

        bool hazelcast_client::remove_lifecycle_listener(const boost::uuids::uuid &registration_id) {
            return client_impl_->remove_lifecycle_listener(registration_id);
        }

        void hazelcast_client::shutdown() {
            client_impl_->shutdown();
        }

        spi::lifecycle_service &hazelcast_client::get_lifecycle_service() {
            return client_impl_->get_lifecycle_service();
        }

        local_endpoint hazelcast_client::get_local_endpoint() const {
            return client_impl_->get_local_endpoint();
        }

        hazelcast_client::~hazelcast_client() {
            client_impl_->shutdown();
        }

        cp::cp_subsystem &hazelcast_client::get_cp_subsystem() {
            return client_impl_->get_cp_subsystem();
        }

        const boost::string_view version() {
            return HAZELCAST_VERSION;
        }

        namespace impl {
            std::atomic<int32_t> hazelcast_client_instance_impl::CLIENT_ID(0);

            hazelcast_client_instance_impl::hazelcast_client_instance_impl(client_config config)
                    : client_config_(std::move(config)), client_properties_(client_config_.get_properties()),
                      client_context_(*this),
                      serialization_service_(client_config_.get_serialization_config()), cluster_service_(client_context_),
                      transaction_manager_(client_context_), cluster_(cluster_service_),
                      lifecycle_service_(client_context_, client_config_.get_lifecycle_listeners()),
                      proxy_manager_(client_context_),
                      id_(++CLIENT_ID), random_generator_(std::chrono::system_clock::now().time_since_epoch().count()),
                      uuid_generator_{random_generator_},
                      cp_subsystem_(client_context_), proxy_session_manager_(client_context_) {
                const std::shared_ptr<std::string> &name = client_config_.get_instance_name();
                if (name.get() != NULL) {
                    instance_name_ = *name;
                } else {
                    std::ostringstream out;
                    out << "hz.client_" << id_;
                    instance_name_ = out.str();
                }

                auto logger_config = client_config_.get_logger_config();<commit_msg>Changed the uuid seed value to a va value that may be more random than the current timestamp(`std::random_device{}()`). (#697)<commit_after>/*
 * Copyright (c) 2008-2020, Hazelcast, Inc. All Rights Reserved.
 *
 * 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.
 */

/*
 * Copyright (c) 2008-2020, Hazelcast, Inc. All Rights Reserved.
 *
 * 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 <vector>
#include <functional>
#include <boost/format.hpp>

#include "hazelcast/util/Util.h"
#include "hazelcast/util/IOUtil.h"
#include "hazelcast/client/hazelcast_client.h"
#include "hazelcast/client/transaction_context.h"
#include "hazelcast/client/cluster.h"
#include "hazelcast/client/spi/lifecycle_service.h"
#include "hazelcast/client/lifecycle_listener.h"
#include <hazelcast/client/exception/protocol_exceptions.h>
#include "hazelcast/client/impl/hazelcast_client_instance_impl.h"
#include "hazelcast/client/impl/ClientLockReferenceIdGenerator.h"
#include "hazelcast/client/spi/impl/ClientInvocationServiceImpl.h"
#include "hazelcast/client/spi/impl/ClientPartitionServiceImpl.h"
#include "hazelcast/client/spi/impl/ClientExecutionServiceImpl.h"
#include "hazelcast/client/spi/impl/sequence/CallIdFactory.h"
#include "hazelcast/client/spi/impl/AwsAddressProvider.h"
#include "hazelcast/client/spi/impl/DefaultAddressProvider.h"
#include "hazelcast/client/aws/impl/AwsAddressTranslator.h"
#include "hazelcast/client/spi/impl/DefaultAddressTranslator.h"
#include "hazelcast/client/spi/impl/listener/listener_service_impl.h"
#include "hazelcast/client/load_balancer.h"
#include "hazelcast/client/connection/ClientConnectionManagerImpl.h"
#include "hazelcast/client/proxy/flake_id_generator_impl.h"
#include "hazelcast/logger.h"
#include "hazelcast/client/member_selectors.h"

#ifndef HAZELCAST_VERSION
#define HAZELCAST_VERSION "NOT_FOUND"
#endif

namespace hazelcast {
    namespace client {
        hazelcast_client::hazelcast_client() : client_impl_(new impl::hazelcast_client_instance_impl(client_config())) {
            client_impl_->start();
        }

        hazelcast_client::hazelcast_client(client_config config) : client_impl_(
                new impl::hazelcast_client_instance_impl(std::move(config))) {
            client_impl_->start();
        }

        const std::string &hazelcast_client::get_name() const {
            return client_impl_->get_name();
        }

        client_config &hazelcast_client::get_client_config() {
            return client_impl_->get_client_config();
        }

        transaction_context hazelcast_client::new_transaction_context() {
            return client_impl_->new_transaction_context();
        }

        transaction_context hazelcast_client::new_transaction_context(const transaction_options &options) {
            return client_impl_->new_transaction_context(options);
        }

        cluster &hazelcast_client::get_cluster() {
            return client_impl_->get_cluster();
        }

        boost::uuids::uuid hazelcast_client::add_lifecycle_listener(lifecycle_listener &&lifecycle_listener) {
            return client_impl_->add_lifecycle_listener(std::move(lifecycle_listener));
        }

        bool hazelcast_client::remove_lifecycle_listener(const boost::uuids::uuid &registration_id) {
            return client_impl_->remove_lifecycle_listener(registration_id);
        }

        void hazelcast_client::shutdown() {
            client_impl_->shutdown();
        }

        spi::lifecycle_service &hazelcast_client::get_lifecycle_service() {
            return client_impl_->get_lifecycle_service();
        }

        local_endpoint hazelcast_client::get_local_endpoint() const {
            return client_impl_->get_local_endpoint();
        }

        hazelcast_client::~hazelcast_client() {
            client_impl_->shutdown();
        }

        cp::cp_subsystem &hazelcast_client::get_cp_subsystem() {
            return client_impl_->get_cp_subsystem();
        }

        const boost::string_view version() {
            return HAZELCAST_VERSION;
        }

        namespace impl {
            std::atomic<int32_t> hazelcast_client_instance_impl::CLIENT_ID(0);

            hazelcast_client_instance_impl::hazelcast_client_instance_impl(client_config config)
                    : client_config_(std::move(config)), client_properties_(client_config_.get_properties()),
                      client_context_(*this),
                      serialization_service_(client_config_.get_serialization_config()), cluster_service_(client_context_),
                      transaction_manager_(client_context_), cluster_(cluster_service_),
                      lifecycle_service_(client_context_, client_config_.get_lifecycle_listeners()),
                      proxy_manager_(client_context_),
                      id_(++CLIENT_ID), random_generator_(std::random_device{}()),
                      uuid_generator_{random_generator_},
                      cp_subsystem_(client_context_), proxy_session_manager_(client_context_) {
                const std::shared_ptr<std::string> &name = client_config_.get_instance_name();
                if (name.get() != NULL) {
                    instance_name_ = *name;
                } else {
                    std::ostringstream out;
                    out << "hz.client_" << id_;
                    instance_name_ = out.str();
                }

                auto logger_config = client_config_.get_logger_config();
{'fraction_non_alphanumeric': 0.09858277526864974, 'fraction_numerical': 0.004438560971811245, 'mean_word_length': 3.380286493860846, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 43, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, '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': '7651224', 'n_tokens_mistral': 3736, 'n_tokens_neox': 3632, 'n_words': 709}