Commit e05fc97c by Amir Aharon

work in progress.. compiling

parent 40581230
Showing with 2762 additions and 172 deletions
// For format details, see https://aka.ms/vscode-remote/devcontainer.json or this file's README at:
// https://github.com/microsoft/vscode-dev-containers/tree/v0.117.1/containers/docker-existing-docker-compose
// If you want to run as a non-root user in the container, see .devcontainer/docker-compose.yml.
{
"name": "Existing Docker Compose (Extend)",
// Update the 'dockerComposeFile' list if you have more compose files or use different names.
// The .devcontainer/docker-compose.yml file contains any overrides you need/want to make.
"dockerComposeFile": [
"../docker-compose.yml",
"docker-compose.yml"
],
// The 'service' property is the name of the service for the container that VS Code should
// use. Update this value and .devcontainer/docker-compose.yml to the real service name.
"service": "dev-microservice",
// The optional 'workspaceFolder' property is the path VS Code should open by default when
// connected. This is typically a file mount in .devcontainer/docker-compose.yml
"workspaceFolder": "/workspace",
// Set *default* container specific settings.json values on container create.
"settings": {
"terminal.integrated.shell.linux": null
},
// Add the IDs of extensions you want installed when the container is created.
"extensions": ["ms-vscode.cpptools","austin.code-gnu-global","twxs.cmake","ms-vscode.cmake-tools","formulahendry.code-runner"]
// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],
// Uncomment the next line if you want start specific services in your Docker Compose config.
// "runServices": [],
// Uncomment the next line if you want to keep your containers running after VS Code shuts down.
// "shutdownAction": "none",
// Uncomment the next line to run commands after the container is created - for example installing git.
// "postCreateCommand": "apt-get update && apt-get install -y git",
// Uncomment to connect as a non-root user. See https://aka.ms/vscode-remote/containers/non-root.
// "remoteUser": "vscode"
}
#-------------------------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license information.
#-------------------------------------------------------------------------------------------------------------
version: '2'
services:
# Update this to the name of the service you want to work with in your docker-compose.yml file
dev-microservice:
# If you want add a non-root user to your Dockerfile, you can use the "remoteUser"
# property in devcontainer.json to cause VS Code its sub-processes (terminals, tasks,
# debugging) to execute as the user. Uncomment the next line if you want the entire
# container to run as this user instead. Note that, on Linux, you may need to
# ensure the UID and GID of the container user you create matches your local user.
# See https://aka.ms/vscode-remote/containers/non-root for details.
#
# user: vscode
# Uncomment if you want to override the service's Dockerfile to one in the .devcontainer
# folder. Note that the path of the Dockerfile and context is relative to the *primary*
# docker-compose.yml file (the first in the devcontainer.json "dockerComposeFile"
# array). The sample below assumes your primary file is in the root of your project.
#
# build:
# context: .
# dockerfile: .devcontainer/Dockerfile
volumes:
# Update this to wherever you want VS Code to mount the folder of your project
- .:/workspace:cached
# Uncomment the next line to use Docker from inside the container. See https://aka.ms/vscode-remote/samples/docker-in-docker-compose for details.
# - /var/run/docker.sock:/var/run/docker.sock
# Uncomment the next four lines if you will use a ptrace-based debugger like C++, Go, and Rust.
# cap_add:
# - SYS_PTRACE
# security_opt:
# - seccomp:unconfined
# Overrides default command so things don't shut down after the process ends.
command: /bin/sh -c "while sleep 1000; do :; done"
...@@ -37,16 +37,15 @@ ...@@ -37,16 +37,15 @@
"/usr/lib/gcc/x86_64-linux-gnu/7.4.0/include-fixed", "/usr/lib/gcc/x86_64-linux-gnu/7.4.0/include-fixed",
"/usr/include/x86_64-linux-gnu", "/usr/include/x86_64-linux-gnu",
"/usr/include", "/usr/include",
"/home/vscode/vcpkg/installed/x64-linux/include",
"${workspaceRoot}/../3party", "${workspaceRoot}/../3party",
"${workspaceRoot}/src", "${workspaceRoot}/src",
"/usr/include/c++/7.4.0", "/usr/include/c++/7.4.0",
"/usr/include/x86_64-linux-gnu/c++/7.4.0", "/usr/include/x86_64-linux-gnu/c++/7.4.0"
"${workspaceRoot}/../3party/cereal/include",
"${workspaceRoot}/../3party/spdlog/include"
], ],
"compileCommands": "./compile_commands.json", "compileCommands": "./compile_commands.json",
"defines": [], "defines": [],
"intelliSenseMode": "clang-x64", "intelliSenseMode": "${default}",
"browse": { "browse": {
"path": [ "path": [
"/usr/include/c++/7.4.0", "/usr/include/c++/7.4.0",
...@@ -57,7 +56,7 @@ ...@@ -57,7 +56,7 @@
"/usr/lib/gcc/x86_64-linux-gnu/7.4.0/include-fixed", "/usr/lib/gcc/x86_64-linux-gnu/7.4.0/include-fixed",
"/usr/include/x86_64-linux-gnu", "/usr/include/x86_64-linux-gnu",
"/usr/include", "/usr/include",
"${workspaceRoot}/../3party", "/home/vscode/vcpkg/installed/x64-linux/include",
"${workspaceRoot}/src", "${workspaceRoot}/src",
"/usr/include/c++/7.4.0" "/usr/include/c++/7.4.0"
], ],
...@@ -65,7 +64,11 @@ ...@@ -65,7 +64,11 @@
"databaseFilename": "" "databaseFilename": ""
}, },
"cStandard": "c11", "cStandard": "c11",
"cppStandard": "c++17" "cppStandard": "c++17",
"configurationProvider": "ms-vscode.cmake-tools",
"compilerArgs": [
"-std=c++17"
]
}, },
{ {
"name": "Win32", "name": "Win32",
......
...@@ -53,5 +53,6 @@ ...@@ -53,5 +53,6 @@
"type_traits": "cpp", "type_traits": "cpp",
"typeindex": "cpp", "typeindex": "cpp",
"typeinfo": "cpp" "typeinfo": "cpp"
} },
"cmake.configureOnOpen": true
} }
\ No newline at end of file
...@@ -4,6 +4,18 @@ ...@@ -4,6 +4,18 @@
"version": "2.0.0", "version": "2.0.0",
"tasks": [ "tasks": [
{ {
"label": "compile RestMsg.fbs",
"type": "shell",
"command": "/home/vscode/vcpkg/installed/x64-linux/tools/flatbuffers/flatc -o /home/vscode/project/schema -c /home/vscode/project/schema/RestMsg.fbs",
"problemMatcher": []
},
{
"label": "compile RestResponse.fbs",
"type": "shell",
"command": "/home/vscode/vcpkg/installed/x64-linux/tools/flatbuffers/flatc -o /home/vscode/project/schema -c /home/vscode/project/schema/RestResponse.fbs",
"problemMatcher": []
},
{
"label": "run build env", "label": "run build env",
"type": "shell", "type": "shell",
"command": "docker-compose -f develop-compose.yml run --service-ports --name devenv dev-microservice bash", "command": "docker-compose -f develop-compose.yml run --service-ports --name devenv dev-microservice bash",
......
/*
* Copyright 2000-2014 NeuStar, Inc. All rights reserved.
* NeuStar, the Neustar logo and related names and logos are registered
* trademarks, service marks or tradenames of NeuStar, Inc. All other
* product names, company names, marks, logos and symbols may be trademarks
* of their respective owners.
*/
/*
* simple_scheduled_thread_pool_executor.h
*
* Created on: Jun 11, 2014
* Author: vpoliboy
*/
#ifndef SIMPLE_SCHEDULED_THREAD_POOL_EXECUTOR_H_
#define SIMPLE_SCHEDULED_THREAD_POOL_EXECUTOR_H_
#include <boost/function.hpp>
#include <boost/scoped_ptr.hpp>
#include <boost/chrono/duration.hpp>
#include <boost/foreach.hpp>
#include <boost/asio.hpp>
#include <boost/atomic.hpp>
#include <boost/thread.hpp>
namespace cppmetrics {
namespace concurrent {
/**
* A simple threadpool that executes a given command at a given interval of time.
*/
class SimpleScheduledThreadPoolExecutor {
public:
/**
* Creates a new instance with the given thread size.
* @param pool_size The number of threads in the threadpool.
*/
SimpleScheduledThreadPoolExecutor(size_t pool_size);
virtual ~SimpleScheduledThreadPoolExecutor();
/**
* Executes the give task at the configured interval rate until shutdown is called. The given command
* is executed at a fixed rate and therefore there might be more than one command running at a time
* depending on the duration of the command.
* @param command The command to execute at fixed interval.
* @param period The interval between the start of the tasks.
*/
virtual void scheduleAtFixedRate(boost::function<void()> command,
boost::chrono::milliseconds period);
/**
* Executes the give task at the configured interval delay until shutdown is called. The given command
* is executed at a fixed delay. There can be only one task instance running at a given time.
* @param command The command to execute at fixed delay.
* @param period The time period between the end of the tasks.
*/
virtual void scheduleAtFixedDelay(boost::function<void()> command,
boost::chrono::milliseconds period);
/**
* Shuts down the service, may or may not return immediately depending on the pending tasks.
*/
virtual void shutdown();
/**
* Shuts down the service, will return immediately.
*/
virtual void shutdownNow();
/**
* gets the threadpool state.
* @return True if this is shutdown or shutting down, false otherwise.
*/
virtual bool isShutdown() const;
private:
void cancelTimers();
void timerHandler(const boost::system::error_code& ec, size_t timer_index);
void scheduleTimer(boost::function<void()> task,
boost::chrono::milliseconds period, bool fixed_rate);
boost::atomic<bool> running_;
boost::asio::io_service io_service_;
boost::scoped_ptr<boost::asio::io_service::work> work_ptr_;
boost::thread_group thread_group_;
class TimerTask;
typedef std::vector<TimerTask> TimerTasks;
TimerTasks timer_tasks_;
mutable boost::mutex timer_task_mutex_;
};
} /* namespace concurrent */
} /* namespace cppmetrics */
#endif /* SIMPLE_SCHEDULED_THREAD_POOL_EXECUTOR_H_ */
/*
* Copyright 2000-2014 NeuStar, Inc. All rights reserved.
* NeuStar, the Neustar logo and related names and logos are registered
* trademarks, service marks or tradenames of NeuStar, Inc. All other
* product names, company names, marks, logos and symbols may be trademarks
* of their respective owners.
*/
/*
* simple_thread_pool_executor.h
*
* Created on: Jun 10, 2014
* Author: vpoliboy
*/
#ifndef SIMPLE_THREAD_POOL_EXECUTOR_H_
#define SIMPLE_THREAD_POOL_EXECUTOR_H_
#include <boost/function.hpp>
#include <boost/scoped_ptr.hpp>
#include <boost/chrono/duration.hpp>
#include <boost/atomic.hpp>
#include <boost/thread/thread.hpp>
#include <boost/asio.hpp>
#include <boost/bind.hpp>
namespace cppmetrics {
namespace concurrent {
/**
* A simple threadpool modeled after similar class in java.
*/
class SimpleThreadPoolExecutor {
public:
/**
* Creates a new thread pool with the given number of threads.
* @param thread_count The number of threads in the thread pool.
*/
SimpleThreadPoolExecutor(size_t thread_count);
virtual ~SimpleThreadPoolExecutor();
/**
* Executes the given task in one of the threads.
* @param task The task to be executed.
*/
virtual void execute(boost::function<void()> command);
/**
* Shuts down the service, may or may not return immediately.
*/
virtual void shutdown();
/**
* Shuts down the service, will return immediately.
*/
virtual void shutdownNow();
/**
* gets the threadpool state.
* @return True if this is shutdown or shutting down, false otherwise.
*/
virtual bool isShutdown() const;
private:
boost::atomic<bool> running_;
boost::asio::io_service io_service_;
boost::scoped_ptr<boost::asio::io_service::work> work_ptr_;
boost::thread_group thread_group_;
};
} /* namespace concurrent */
} /* namespace cppmetrics */
#endif /* SIMPLE_THREAD_POOL_EXECUTOR_H_ */
/*
* Copyright 2000-2014 NeuStar, Inc. All rights reserved.
* NeuStar, the Neustar logo and related names and logos are registered
* trademarks, service marks or tradenames of NeuStar, Inc. All other
* product names, company names, marks, logos and symbols may be trademarks
* of their respective owners.
*/
/*
* console_reporter.h
*
* Created on: Jul 1, 2014
* Author: vpoliboy
*/
#ifndef CONSOLE_REPORTER_H_
#define CONSOLE_REPORTER_H_
#include "cppmetrics/core/scheduled_reporter.h"
namespace cppmetrics {
namespace core {
/*
* A GLOG console reporter that periodically logs the metric values.
*/
class ConsoleReporter: public ScheduledReporter, boost::noncopyable {
public:
/**
* Creates a {@link ConsoleReporter} instance. Uses the given registry.
* @param registry The metric registry.
* @param ostr The output stream used for printing the values.
* @param rate_unit The conversion unit user for the rate metrics.
*/
ConsoleReporter(MetricRegistryPtr registry,
std::ostream& ostr,
boost::chrono::milliseconds rate_unit = boost::chrono::seconds(1));
virtual ~ConsoleReporter();
/**
* Reports all the metrics from the registry periodically to the graphite server.
* @param gauge_map all of the gauges in the registry
* @param counter_map all of the counters in the registry
* @param histogram_map all of the histograms in the registry
* @param meter_map all of the meters in the registry
* @param timer_map all of the timers in the registry
*/
virtual void report(core::CounterMap counter_map,
core::HistogramMap histogram_map,
core::MeteredMap meter_map,
core::TimerMap timer_map,
core::GaugeMap gauge_map);
private:
void printWithBanner(const std::string& s, char sep);
void printGauge(const core::GaugeMap::mapped_type& metric);
void printCounter(const core::CounterMap::mapped_type& metric);
void printHistogram(const core::HistogramMap::mapped_type& metric);
void printTimer(const core::TimerMap::mapped_type& metric);
void printMeter(const core::MeteredMap::mapped_type& meter);
static const size_t CONSOLE_WIDTH = 80;
std::ostream& ostr_;
};
} /* namespace core */
} /* namespace cppmetrics */
#endif /* CONSOLER_REPORTER_H_ */
/*
* Copyright 2000-2014 NeuStar, Inc. All rights reserved.
* NeuStar, the Neustar logo and related names and logos are registered
* trademarks, service marks or tradenames of NeuStar, Inc. All other
* product names, company names, marks, logos and symbols may be trademarks
* of their respective owners.
*/
/*
* counter.h
*
* Created on: Jun 5, 2014
* Author: vpoliboy
*/
#ifndef COUNTER_H_
#define COUNTER_H_
#include <boost/cstdint.hpp>
#include <boost/scoped_ptr.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/atomic.hpp>
#include "cppmetrics/core/metric.h"
namespace cppmetrics {
namespace core {
/**
* An incrementing and decrementing counter metric.
* thread-safety: thread safe
*/
class Counter: public Metric {
public:
/**
* Constructor
* @param n Initialize the counter with a value of \c n.
*/
Counter(boost::int64_t n = 0) :
count_(n) {
}
virtual ~Counter() {
}
/**
* @return the current value of the counter.
*/
boost::int64_t getCount() const {
return count_;
}
/**
* @param n reset the counter to the value \c n.
*/
void setCount(boost::int64_t n) {
count_ = n;
}
/**
* @param n increment the counter by \c n
*/
void increment(boost::int64_t n = 1) {
count_ += n;
}
/**
* @param n decrement the counter by \c n
*/
void decrement(boost::int64_t n = 1) {
count_ -= n;
}
/**
* Clears the counter, same as calling <code> setCount(0) </code>;
*/
void clear() {
setCount(0);
}
private:
boost::atomic<boost::int64_t> count_;
};
typedef boost::shared_ptr<Counter> CounterPtr;
} /* namespace core */
} /* namespace cppmetrics */
#endif /* COUNTER_H_ */
/*
* Copyright 2000-2014 NeuStar, Inc. All rights reserved.
* NeuStar, the Neustar logo and related names and logos are registered
* trademarks, service marks or tradenames of NeuStar, Inc. All other
* product names, company names, marks, logos and symbols may be trademarks
* of their respective owners.
*/
/*
* exp_decay_sample.h
*
* Created on: Jun 5, 2014
* Author: vpoliboy
*/
#ifndef EXP_DECAY_SAMPLE_H_
#define EXP_DECAY_SAMPLE_H_
#include <vector>
#include <boost/atomic.hpp>
#include <boost/thread/mutex.hpp>
#include <boost/thread/lock_guard.hpp>
#include <boost/random/mersenne_twister.hpp>
#include <boost/random/uniform_real_distribution.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>
#include <boost/scoped_ptr.hpp>
#include "cppmetrics/core/types.h"
#include "cppmetrics/core/sample.h"
namespace cppmetrics {
namespace core {
/**
* An exponentially-decaying random reservoir of {@code long}s. Uses Cormode et al's
* forward-decaying priority reservoir sampling method to produce a statistically representative
* sampling reservoir, exponentially biased towards newer entries.
*/
class ExpDecaySample: public Sample {
public:
/**
* Creates a new {@link ExpDecaySample} of the given size and alpha factor.
* @param size the number of samples to keep in the sampling reservoir
* @param alpha the exponential decay factor; the higher this is, the more biased the reservoir
* will be towards newer values
*/
ExpDecaySample(boost::uint32_t size = 1024, double alpha = DEFAULT_ALPHA);
virtual ~ExpDecaySample();
virtual void clear();
/**
* Returns the number of values recorded.
* @return the number of values recorded
*/
virtual boost::uint64_t size() const;
/**
* Adds a new recorded value to the reservoir.
* @param value a new recorded value
*/
virtual void update(boost::int64_t value);
/**
* Adds an old value with a fixed timestamp to the reservoir.
* @param value the value to be added
* @param timestamp the epoch timestamp of {@code value} in seconds
*/
virtual void update(boost::int64_t value,
const Clock::time_point& timestamp);
/**
* Returns a snapshot of the reservoir's values.
* @return a snapshot of the reservoir's values
*/
virtual SnapshotPtr getSnapshot() const;
private:
static const double DEFAULT_ALPHA;
static const Clock::duration RESCALE_THRESHOLD;
void rescaleIfNeeded(const Clock::time_point& when);
void rescale(const Clock::time_point& old_start_time);
const double alpha_;
const boost::uint64_t reservoir_size_;
boost::atomic<boost::uint64_t> count_;
mutable boost::mutex mutex_;
Clock::time_point start_time_;
Clock::time_point next_scale_time_;
typedef std::map<double, boost::int64_t> Double2Int64Map;
Double2Int64Map values_;
mutable boost::mt11213b rng_;
};
} /* namespace core */
} /* namespace cppmetrics */
#endif /* EXP_DECAY_SAMPLE_H_ */
/*
* Copyright 2000-2014 NeuStar, Inc. All rights reserved.
* NeuStar, the Neustar logo and related names and logos are registered
* trademarks, service marks or tradenames of NeuStar, Inc. All other
* product names, company names, marks, logos and symbols may be trademarks
* of their respective owners.
*/
/*
* gauge.h
*
* Created on: Jun 9, 2014
* Author: vpoliboy
*/
#ifndef GAUGE_H_
#define GAUGE_H_
#include <boost/shared_ptr.hpp>
#include <boost/cstdint.hpp>
#include "cppmetrics/core/metric.h"
namespace cppmetrics {
namespace core {
/**
* A gauge metric is an instantaneous reading of a particular value. Used typically
* to instrument a queue size, backlog etc.
*
*/
class Gauge: public Metric {
public:
virtual ~Gauge() {
}
/**
* @return the current value of the guage.
*/
virtual boost::int64_t getValue() = 0;
};
typedef boost::shared_ptr<Gauge> GaugePtr;
} /* namespace core */
} /* namespace cppmetrics */
#endif /* GAUGE_H_ */
/*
* Copyright 2000-2014 NeuStar, Inc. All rights reserved.
* NeuStar, the Neustar logo and related names and logos are registered
* trademarks, service marks or tradenames of NeuStar, Inc. All other
* product names, company names, marks, logos and symbols may be trademarks
* of their respective owners.
*/
/*
* histogram.h
*
* Created on: Jun 5, 2014
* Author: vpoliboy
*/
#ifndef HISTOGRAM_H_
#define HISTOGRAM_H_
#include <boost/cstdint.hpp>
#include <boost/scoped_ptr.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/atomic.hpp>
#include "cppmetrics/core/metric.h"
#include "cppmetrics/core/sampling.h"
#include "cppmetrics/core/sample.h"
namespace cppmetrics {
namespace core {
/**
* A metric which calculates the distribution of a value.
* Thread-safe.
*/
class Histogram: public Metric, Sampling {
public:
/**
* Creates a new histogram based on the sample type.
* @param sample_type the sample to use internally.
* @see SamplingInterface for different types of samples.
*/
Histogram(SampleType sample_type = kBiased);
virtual ~Histogram();
/**
* @return the current snapshot based on the sample.
*/
virtual SnapshotPtr getSnapshot() const;
/**
* Adds a recorded value.
* @param value The length of the value.
*/
void update(boost::int64_t value);
/**
* @return The number of values recorded until now.
*/
boost::uint64_t getCount() const;
/**
* Clears the underlying sample.
*/
void clear();
/**< The Maximum sample size at any given time. */
static const boost::uint64_t DEFAULT_SAMPLE_SIZE;
private:
static const double DEFAULT_ALPHA;
boost::scoped_ptr<Sample> sample_; /**< The underlying sample implementation. */
boost::atomic<boost::uint64_t> count_; /**< The number of samples. */
};
typedef boost::shared_ptr<Histogram> HistogramPtr;
} /* namespace core */
} /* namespace cppmetrics */
#endif /* HISTOGRAM_H_ */
/*
* Copyright 2000-2014 NeuStar, Inc. All rights reserved.
* NeuStar, the Neustar logo and related names and logos are registered
* trademarks, service marks or tradenames of NeuStar, Inc. All other
* product names, company names, marks, logos and symbols may be trademarks
* of their respective owners.
*/
/*
* meter.h
*
* Created on: Jun 4, 2014
* Author: vpoliboy
*/
#ifndef METER_H_
#define METER_H_
#include <boost/chrono.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/scoped_ptr.hpp>
#include <boost/atomic.hpp>
#include "cppmetrics/core/metered.h"
namespace cppmetrics {
namespace core {
/**
* A meter metric which measures mean throughput and one-, five-, and fifteen-minute
* exponentially-weighted moving average throughputs.
*/
class Meter: public Metered {
public:
/**
* Creates a meter with the specified rate unit.
* @param rate_unit The rate unit in nano seconds.
*/
Meter(boost::chrono::nanoseconds rate_unit = boost::chrono::seconds(1));
virtual ~Meter();
/**
* @returns the number of events that have been marked.
*/
virtual boost::uint64_t getCount() const;
/**
* @return the fifteen-minute exponentially-weighted moving average rate at which events have
* occurred since the meter was created.
*/
virtual double getFifteenMinuteRate();
/**
* @return the five-minute exponentially-weighted moving average rate at which events have
* occurred since the meter was created.
*/
virtual double getFiveMinuteRate();
/**
* @return the one-minute exponentially-weighted moving average rate at which events have
* occurred since the meter was created.
*/
virtual double getOneMinuteRate();
/**
* @return the mean rate at which events have occurred since the meter was created.
*/
virtual double getMeanRate();
/**
* Mark the occurrence of a given number of events.
* @param n the number of events with the default being 1.
*/
void mark(boost::uint64_t n = 1);
private:
class Impl;
boost::scoped_ptr<Impl> impl_;
};
typedef boost::shared_ptr<Meter> MeterPtr;
} /* namespace core */
} /* namespace cppmetrics */
#endif /* METER_H_ */
/*
* Copyright 2000-2014 NeuStar, Inc. All rights reserved.
* NeuStar, the Neustar logo and related names and logos are registered
* trademarks, service marks or tradenames of NeuStar, Inc. All other
* product names, company names, marks, logos and symbols may be trademarks
* of their respective owners.
*/
/*
* metered.h
*
* Created on: Jun 4, 2014
* Author: vpoliboy
*/
#ifndef METERED_H_
#define METERED_H_
#include <boost/shared_ptr.hpp>
#include <boost/cstdint.hpp>
#include <string>
#include <boost/chrono.hpp>
#include "cppmetrics/core/metric.h"
namespace cppmetrics {
namespace core {
/**
* Interface for objects which maintains mean and exponentially-weighted rate.
*/
class Metered: public Metric {
public:
virtual ~Metered() {
}
/**
* @returns the number of events that have been marked.
*/
virtual boost::uint64_t getCount() const = 0;
/**
* @return the fifteen-minute exponentially-weighted moving average rate at which events have
* occurred since the meter was created.
*/
virtual double getFifteenMinuteRate() = 0;
/**
* @return the fifteen-minute exponentially-weighted moving average rate at which events have
* occurred since the meter was created.
*/
virtual double getFiveMinuteRate() = 0;
/**
* @return the fifteen-minute exponentially-weighted moving average rate at which events have
* occurred since the meter was created.
*/
virtual double getOneMinuteRate() = 0;
/**
* @return the average rate at which events have occurred since the meter was created.
*/
virtual double getMeanRate() = 0;
};
typedef boost::shared_ptr<Metered> MeteredPtr;
} /* namespace core */
} /* namespace cppmetrics */
#endif /* METERED_H_ */
/*
* Copyright 2000-2014 NeuStar, Inc. All rights reserved.
* NeuStar, the Neustar logo and related names and logos are registered
* trademarks, service marks or tradenames of NeuStar, Inc. All other
* product names, company names, marks, logos and symbols may be trademarks
* of their respective owners.
*/
/*
* metric.h
*
* Created on: Jun 4, 2014
* Author: vpoliboy
*/
#ifndef METRIC_H_
#define METRIC_H_
#include <boost/shared_ptr.hpp>
namespace cppmetrics {
namespace core {
/**
* The base class for all metrics types.
*/
class Metric {
public:
virtual ~Metric() = 0;
};
inline Metric::~Metric() {
}
typedef boost::shared_ptr<Metric> MetricPtr;
} /* namespace core */
} /* namespace cppmetrics */
#endif /* METRIC_H_ */
/*
* Copyright 2000-2014 NeuStar, Inc. All rights reserved.
* NeuStar, the Neustar logo and related names and logos are registered
* trademarks, service marks or tradenames of NeuStar, Inc. All other
* product names, company names, marks, logos and symbols may be trademarks
* of their respective owners.
*/
/*
* metric_registry.h
*
* Created on: Jun 9, 2014
* Author: vpoliboy
*/
#ifndef METRIC_REGISTRY_H_
#define METRIC_REGISTRY_H_
#include <boost/noncopyable.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/scoped_ptr.hpp>
#include <string>
#include <map>
#include "cppmetrics/core/counter.h"
#include "cppmetrics/core/gauge.h"
#include "cppmetrics/core/histogram.h"
#include "cppmetrics/core/meter.h"
#include "cppmetrics/core/timer.h"
namespace cppmetrics {
namespace core {
typedef std::map<std::string, CounterPtr> CounterMap;
typedef std::map<std::string, HistogramPtr> HistogramMap;
typedef std::map<std::string, MeteredPtr> MeteredMap;
typedef std::map<std::string, TimerPtr> TimerMap;
typedef std::map<std::string, GaugePtr> GaugeMap;
class MetricRegistry;
typedef boost::shared_ptr<MetricRegistry> MetricRegistryPtr;
/**
* The thread-safe registry class for all metrics.
*/
class MetricRegistry: boost::noncopyable {
public:
/**
* Singleton factory method for the Metric registry.
* @return The default singleton metric registry
*/
static MetricRegistryPtr DEFAULT_REGISTRY();
/**
* Creates a new registry.
*/
MetricRegistry();
~MetricRegistry();
/**
* Adds a gauge with the given name to the registry.
* @param name The name of the gauge metric.
* @param metric A subclass object of the Gauge.
* @return True on creation, false if the gauge is already present.
* @throws std::invalid_argument exception if a metric of different type with the same name is already present.
*/
bool addGauge(const std::string& name, GaugePtr metric);
/**
* Removes the metric with the given name from the registry.
* @param name The name of the metric
* @return True on success, false if the metric with the name is not present.
*/
bool removeMetric(const std::string& name);
/**
* Gets a {@link Counter} from the registry with the given name if present otherwise creates and adds a new
* {@link Counter} and returns the newly added one.
* @param name The name of the Counter.
* @return shared_ptr to the Counter object.
* @throws std::invalid_argument if a metric with the same name but different type exists in the registry.
*/
CounterPtr counter(const std::string& name);
/**
* Gets a {@link Histogram} from the registry with the given name if present otherwise creates and adds a new
* {@link Histogram} and returns the newly added one.
* @param name The name of the Histogram.
* @return shared_ptr to the Histogram ojbect.
* @throws std::invalid_argument if a metric with the same name but different type exists in the registry.
*/
HistogramPtr histogram(const std::string& name);
/**
* Gets a {@link Meter} from the registry with the given name if present otherwise creates and adds a new
* {@link Meter} and returns the newly added one.
* @param name The name of the Meter.
* @return shared_ptr to the Meter ojbect.
* @throws std::invalid_argument if a metric with the same name but different type exists in the registry.
*/
MeterPtr meter(const std::string& name);
/**
* Gets a {@link Timer} from the registry with the given name if present otherwise creates and adds a new
* {@link Timer} and returns the newly added one.
* @param name The name of the Timer.
* @return shared_ptr to the Timer ojbect.
* @throws std::invalid_argument if a metric with the same name but different type exists in the registry.
*/
TimerPtr timer(const std::string& name);
/**
* Returns all the counters and their names currently in the registry.
* @return all the counters in the registry.
*/
CounterMap getCounters() const;
/**
* Returns all the histograms and their names currently in the registry.
* @return all the histograms in the registry.
*/
HistogramMap getHistograms() const;
/**
* Returns all the meters and their names currently in the registry.
* @return all the meters in the registry.
*/
MeteredMap getMeters() const;
/**
* Returns all the timers and their names currently in the registry.
* @return all the timers in the registry.
*/
TimerMap getTimers() const;
/**
* Returns all the gauges and their names currently in the registry.
* @return all the gauges in the registry.
*/
GaugeMap getGauges() const;
/**
* Gets the total number of metrics in the registry.
* @return the total metrics count.
*/
size_t count() const;
private:
class Impl;
boost::scoped_ptr<Impl> impl_; /**< The pimpl pointer */
};
} /* namespace core */
} /* namespace cppmetrics */
#endif /* METRIC_REGISTRY_H_ */
/*
* Copyright 2000-2014 NeuStar, Inc. All rights reserved.
* NeuStar, the Neustar logo and related names and logos are registered
* trademarks, service marks or tradenames of NeuStar, Inc. All other
* product names, company names, marks, logos and symbols may be trademarks
* of their respective owners.
*/
/*
* reporter.h
*
* Created on: Jun 10, 2014
* Author: vpoliboy
*/
#ifndef REPORTER_H_
#define REPORTER_H_
namespace cppmetrics {
namespace core {
/**
* The interface for all the reporter sub classes.
*/
class Reporter {
public:
virtual ~Reporter() {
}
/**
* reports the metrics.
*/
virtual void report() = 0;
};
} /* namespace core */
} /* namespace cppmetrics */
#endif /* REPORTER_H_ */
/*
* Copyright 2000-2014 NeuStar, Inc. All rights reserved.
* NeuStar, the Neustar logo and related names and logos are registered
* trademarks, service marks or tradenames of NeuStar, Inc. All other
* product names, company names, marks, logos and symbols may be trademarks
* of their respective owners.
*/
/*
* sample.h
*
* Created on: Jun 5, 2014
* Author: vpoliboy
*/
#ifndef SAMPLE_H_
#define SAMPLE_H_
#include "cppmetrics/core/snapshot.h"
namespace cppmetrics {
namespace core {
/**
* A statistically representative sample of a data stream.
*/
class Sample {
public:
virtual ~Sample() {
}
/**
* Clears the values in the sample.
*/
virtual void clear() = 0;
/**
* Returns the number of values recorded.
* @return the number of values recorded
*/
virtual boost::uint64_t size() const = 0;
/**
* Adds a new recorded value to the sample.
* @param value a new recorded value
*/
virtual void update(boost::int64_t value) = 0;
/**
* Returns a snapshot of the sample's values.
* @return a snapshot of the sample's values
*/
virtual SnapshotPtr getSnapshot() const = 0;
};
} /* namespace core */
} /* namespace cppmetrics */
#endif /* SAMPLE_H_ */
/*
* Copyright 2000-2014 NeuStar, Inc. All rights reserved.
* NeuStar, the Neustar logo and related names and logos are registered
* trademarks, service marks or tradenames of NeuStar, Inc. All other
* product names, company names, marks, logos and symbols may be trademarks
* of their respective owners.
*/
/*
* sampling.h
*
* Created on: Jun 5, 2014
* Author: vpoliboy
*/
#ifndef SAMPLING_H_
#define SAMPLING_H_
#include "cppmetrics/core/snapshot.h"
namespace cppmetrics {
namespace core {
/**
* The interface for all classes that sample values.
*/
class Sampling {
public:
enum SampleType {
kUniform, kBiased
};
virtual ~Sampling() {
}
/**
* Returns the snapshot of values in the sample.
* @return the snapshot of values in the sample.
*/
virtual SnapshotPtr getSnapshot() const = 0;
};
} /* namespace core */
} /* namespace cppmetrics */
#endif /* SAMPLING_H_ */
/*
* Copyright 2000-2014 NeuStar, Inc. All rights reserved.
* NeuStar, the Neustar logo and related names and logos are registered
* trademarks, service marks or tradenames of NeuStar, Inc. All other
* product names, company names, marks, logos and symbols may be trademarks
* of their respective owners.
*/
/*
* scheduled_reporter.h
*
* Created on: Jun 10, 2014
* Author: vpoliboy
*/
#ifndef SCHEDULED_REPORTER_H_
#define SCHEDULED_REPORTER_H_
#include "reporter.h"
#include "cppmetrics/concurrent/simple_scheduled_thread_pool_executor.h"
#include "cppmetrics/core/metric_registry.h"
namespace cppmetrics {
namespace core {
/**
* The abstract base class for all scheduled reporters (i.e., reporters which process a registry's
* metrics periodically).
*/
class ScheduledReporter: public Reporter {
public:
virtual ~ScheduledReporter();
/**
* Report the current values of all metrics in the registry.
*/
virtual void report();
/**
* Called periodically by the polling thread. Subclasses should report all the given metrics.
* @param gauge_map all of the gauges in the registry
* @param counter_map all of the counters in the registry
* @param histogram_map all of the histograms in the registry
* @param meter_map all of the meters in the registry
* @param timer_map all of the timers in the registry
*/
virtual void report(CounterMap counter_map,
HistogramMap histogram_map,
MeteredMap meter_map,
TimerMap timer_map,
GaugeMap gauge_map) = 0;
/**
* Starts a background thread which polls and published the metrics from the registry periodically at the given
* interval.
* @param period the amount of time between polls in milliseconds.
*/
virtual void start(boost::chrono::milliseconds period);
/**
* Shuts down the background thread that polls/publishes the metrics from the registry.
*/
virtual void stop();
protected:
/**
* Creates a new {@link ScheduledReporter} instance.
* @param registry the {@link MetricRegistry} shared_ptr containing the metrics this
* reporter will report
* @param rate_unit a unit of time used for publishing the rate metrics like meter.
*/
ScheduledReporter(MetricRegistryPtr registry,
boost::chrono::milliseconds rate_unit);
/**
* Converts the duration value to the milliseconds (from nanoseconds).
* @param duration_value The duration value from a metric like timer.
* @return The converted duration value in terms number of millis.
*/
double convertDurationUnit(double duration_value) const;
/**
* Converts the rate value based on the unit of duration.
* @param rate_value The duration value from a metric like meter.
* @return The converted rate value.
*/
double convertRateUnit(double rate_value) const;
/**
*
* @returns the Rate unit in seconds in string format.
*/
std::string rateUnitInSec() const;
private:
bool running_;
MetricRegistryPtr metric_registry_;
concurrent::SimpleScheduledThreadPoolExecutor scheduled_executor_;
double rate_factor_;
double duration_factor_;
};
} /* namespace core */
} /* namespace cppmetrics */
#endif /* SCHEDULED_REPORTER_H_ */
/*
* Copyright 2000-2014 NeuStar, Inc. All rights reserved.
* NeuStar, the Neustar logo and related names and logos are registered
* trademarks, service marks or tradenames of NeuStar, Inc. All other
* product names, company names, marks, logos and symbols may be trademarks
* of their respective owners.
*/
/*
* snapshot.h
*
* Created on: Jun 5, 2014
* Author: vpoliboy
*/
#ifndef SNAPSHOT_H_
#define SNAPSHOT_H_
#include <boost/cstdint.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/scoped_ptr.hpp>
#include <vector>
namespace cppmetrics {
namespace core {
typedef std::vector<boost::int64_t> ValueVector;
/**
* A statistical snapshot of a {@link Sample}.
*/
class Snapshot {
public:
/**
* Create a new {@link Snapshot} with the given values.
* @param values an unordered set of values in the reservoir
*/
Snapshot(const ValueVector& values);
~Snapshot();
/**
* Returns the number of values in the snapshot.
* @return the number of values
*/
size_t size() const;
/**
* Returns the lowest value in the snapshot.
* @return the lowest value
*/
ValueVector::value_type getMin() const;
/**
* Returns the highest value in the snapshot.
* @return the highest value
*/
ValueVector::value_type getMax() const;
/**
* Returns the arithmetic mean of the values in the snapshot.
* @return the arithmetic mean
*/
double getMean() const;
/**
* Returns the standard deviation of the values in the snapshot.
* @return the standard deviation value
*/
double getStdDev() const;
/**
* Returns all the values in the snapshot.
* @return All the values in the snapshot.
*/
const ValueVector& getValues() const;
/**
* Returns the value at the given quantile.
* @param quantile a given quantile, in {@code [0..1]}
* @return the value in the distribution at {@code quantile}
*/
double getValue(double quantile) const;
/**
* Returns the median value in the distribution.
* @return the median value
*/
double getMedian() const;
/**
* Returns the value at the 75th percentile in the distribution.
* @return the value at the 75th percentile
*/
double get75thPercentile() const;
/**
* Returns the value at the 95th percentile in the distribution.
* @return the value at the 95th percentile
*/
double get95thPercentile() const;
/**
* Returns the value at the 98th percentile in the distribution.
* @return the value at the 98th percentile
*/
double get98thPercentile() const;
/**
* Returns the value at the 99th percentile in the distribution.
* @return the value at the 99th percentile
*/
double get99thPercentile() const;
/**
* Returns the value at the 999th percentile in the distribution.
* @return the value at the 999th percentile
*/
double get999thPercentile() const;
private:
ValueVector values_;
};
typedef boost::shared_ptr<Snapshot> SnapshotPtr;
} /* namespace core */
} /* namespace cppmetrics */
#endif /* SNAPSHOT_H_ */
/*
* Copyright 2000-2014 NeuStar, Inc. All rights reserved.
* NeuStar, the Neustar logo and related names and logos are registered
* trademarks, service marks or tradenames of NeuStar, Inc. All other
* product names, company names, marks, logos and symbols may be trademarks
* of their respective owners.
*/
/*
* timer.h
*
* Created on: Jun 5, 2014
* Author: vpoliboy
*/
#ifndef TIMER_H_
#define TIMER_H_
#include <string>
#include <boost/chrono.hpp>
#include <boost/cstdint.hpp>
#include <boost/function.hpp>
#include <boost/scoped_ptr.hpp>
#include <boost/shared_ptr.hpp>
#include "cppmetrics/core/metered.h"
#include "cppmetrics/core/metric.h"
#include "cppmetrics/core/sampling.h"
#include "cppmetrics/core/timer_context.h"
#include "cppmetrics/core/meter.h"
#include "cppmetrics/core/histogram.h"
namespace cppmetrics {
namespace core {
/**
* A timer metric which aggregates timing durations and provides duration statistics, plus
* throughput statistics via {@link Meter} and {@link Histogram}.
*/
class Timer: public Metered, Sampling {
public:
/**
* Creates a new {@link Timer} using an {@link ExpDecaySample}.
*/
Timer();
virtual ~Timer();
/**
* @returns the number of events that have been measured.
*/
virtual boost::uint64_t getCount() const;
/**
* @return the fifteen-minute exponentially-weighted moving average rate at which events have
* occurred since the timer was created.
*/
virtual double getFifteenMinuteRate();
/**
* @return the five-minute exponentially-weighted moving average rate at which events have
* occurred since the timer was created.
*/
virtual double getFiveMinuteRate();
/**
* @return the one-minute exponentially-weighted moving average rate at which events have
* occurred since the timer was created.
*/
virtual double getOneMinuteRate();
/**
* @return the average rate at which events have occurred since the meter was created.
*/
virtual double getMeanRate();
/**
* @return the current snapshot based on the sample.
*/
virtual SnapshotPtr getSnapshot() const;
/**
* Clears the underlying metrics.
*/
void clear();
/**
* Adds a recorded duration.
* @param duration the length of the duration in nanos.
*/
void update(boost::chrono::nanoseconds duration);
/**
* Creates a new TimerContext instance that measures the duration and updates the
* duration before the instance goes out of scope.
* @return The TimerContext object.
* @note The TimerContextPtr should not be shared.
*/
TimerContextPtr timerContextPtr() {
return boost::shared_ptr<TimerContext>(new TimerContext(*this));
}
/**
* Times the duration of a function that will be executed internally and updates the duration.
* @param The fn to be timed.
*/
void time(boost::function<void()> fn);
private:
Meter meter_; /**< The underlying meter object */
Histogram histogram_; /**< The underlying histogram object */
};
typedef boost::shared_ptr<Timer> TimerPtr;
} /* namespace core */
} /* namespace cppmetrics */
#endif /* TIMER_H_ */
/*
* Copyright 2000-2014 NeuStar, Inc. All rights reserved.
* NeuStar, the Neustar logo and related names and logos are registered
* trademarks, service marks or tradenames of NeuStar, Inc. All other
* product names, company names, marks, logos and symbols may be trademarks
* of their respective owners.
*/
/*
* timer_context.h
*
* Created on: Jun 5, 2014
* Author: vpoliboy
*/
#ifndef TIMER_CONTEXT_H_
#define TIMER_CONTEXT_H_
#include <boost/chrono.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/scoped_ptr.hpp>
#include "cppmetrics/core/types.h"
namespace cppmetrics {
namespace core {
class Timer;
/**
* Class that actually measures the wallclock time.
*/
class TimerContext {
public:
/**
* Creates a TimerContext.
* @param timer The parent timer metric.
*/
TimerContext(Timer& timer);
~TimerContext();
/**
* Resets the underlying clock.
*/
void reset();
/**
* Stops recording the elapsed time and updates the timer.
* @return the elapsed time in nanoseconds
*/
boost::chrono::nanoseconds stop();
private:
TimerContext& operator=(const TimerContext&);
Clock::time_point start_time_; ///< The start time on instantitation */
Timer& timer_; ///< The parent timer object. */
bool active_; ///< Whether the timer is active or not */
};
typedef boost::shared_ptr<TimerContext> TimerContextPtr;
} /* namespace cppmetrics */
} /* namespace core */
#endif /* TIMER_CONTEXT_H_ */
/*
* Copyright 2000-2014 NeuStar, Inc. All rights reserved.
* NeuStar, the Neustar logo and related names and logos are registered
* trademarks, service marks or tradenames of NeuStar, Inc. All other
* product names, company names, marks, logos and symbols may be trademarks
* of their respective owners.
*/
/*
* types.h
*
* Created on: Jun 4, 2014
* Author: vpoliboy
*/
#ifndef TYPES_H_
#define TYPES_H_
#include <boost/chrono.hpp>
namespace cppmetrics {
namespace core {
typedef boost::chrono::high_resolution_clock Clock;
}
}
#endif /* TYPES_H_ */
/*
* Copyright 2000-2014 NeuStar, Inc. All rights reserved.
* NeuStar, the Neustar logo and related names and logos are registered
* trademarks, service marks or tradenames of NeuStar, Inc. All other
* product names, company names, marks, logos and symbols may be trademarks
* of their respective owners.
*/
/*
* uniform_sample.h
*
* Created on: Jun 5, 2014
* Author: vpoliboy
*/
#ifndef UNIFORM_SAMPLE_H_
#define UNIFORM_SAMPLE_H_
#include <vector>
#include <iterator>
#include <boost/atomic.hpp>
#include <boost/thread/mutex.hpp>
#include <boost/thread/lock_guard.hpp>
#include <boost/random/mersenne_twister.hpp>
#include <boost/random/uniform_int_distribution.hpp>
#include "cppmetrics/core/sample.h"
namespace cppmetrics {
namespace core {
/**
* A random sampling reservoir of a stream of {@code long}s. Uses Vitter's Algorithm R to produce a
* statistically representative sample.
*/
class UniformSample: public Sample {
public:
/**
* Creates a new {@link UniformReservoir}.
* @param size the number of samples to keep in the sampling reservoir
*/
UniformSample(boost::uint32_t reservoirSize = DEFAULT_SAMPLE_SIZE);
virtual ~UniformSample();
/**
* Clears the values in the sample.
*/
virtual void clear();
/**
* Returns the number of values recorded.
* @return the number of values recorded
*/
virtual boost::uint64_t size() const;
/**
* Adds a new recorded value to the sample.
* @param value a new recorded value
*/
virtual void update(boost::int64_t value);
/**
* Returns a snapshot of the sample's values.
* @return a snapshot of the sample's values
*/
virtual SnapshotPtr getSnapshot() const;
/**< The Maximum sample size at any given time. */
static const boost::uint64_t DEFAULT_SAMPLE_SIZE;
private:
boost::uint64_t getRandom(boost::uint64_t count) const;
const boost::uint64_t reservoir_size_;
boost::atomic<boost::uint64_t> count_;
typedef std::vector<boost::int64_t> Int64Vector;
Int64Vector values_;
mutable boost::mt11213b rng_;
mutable boost::mutex mutex_;
};
} /* namespace core */
} /* namespace cppmetrics */
#endif /* UNIFORM_SAMPLE_H_ */
/*
* Copyright 2000-2014 NeuStar, Inc. All rights reserved.
* NeuStar, the Neustar logo and related names and logos are registered
* trademarks, service marks or tradenames of NeuStar, Inc. All other
* product names, company names, marks, logos and symbols may be trademarks
* of their respective owners.
*/
/*
* cppmetrics.h"
*
* Created on: Jun 30, 2014
* Author: vpoliboy
*/
#ifndef CPPMETRICS_H_
#define CPPMETRICS_H_
// Global header that includes all the public headers.
#include "cppmetrics/concurrent/simple_thread_pool_executor.h"
#include "cppmetrics/concurrent/simple_scheduled_thread_pool_executor.h"
#include "cppmetrics/core/counter.h"
#include "cppmetrics/core/histogram.h"
#include "cppmetrics/core/gauge.h"
#include "cppmetrics/core/meter.h"
#include "cppmetrics/core/metered.h"
#include "cppmetrics/core/metric.h"
#include "cppmetrics/core/metric_registry.h"
#include "cppmetrics/core/reporter.h"
#include "cppmetrics/core/scheduled_reporter.h"
#include "cppmetrics/core/timer.h"
#include "cppmetrics/core/exp_decay_sample.h"
#include "cppmetrics/core/sample.h"
#include "cppmetrics/core/snapshot.h"
#include "cppmetrics/core/uniform_sample.h"
#include "cppmetrics/core/sampling.h"
#include "cppmetrics/core/types.h"
#include "cppmetrics/graphite/graphite_sender.h"
#include "cppmetrics/graphite/graphite_sender_tcp.h"
#include "cppmetrics/graphite/graphite_reporter.h"
#include "cppmetrics/core/console_reporter.h"
#endif /* CPPMETRICS_H_ */
/*
* Copyright 2000-2014 NeuStar, Inc. All rights reserved.
* NeuStar, the Neustar logo and related names and logos are registered
* trademarks, service marks or tradenames of NeuStar, Inc. All other
* product names, company names, marks, logos and symbols may be trademarks
* of their respective owners.
*/
/*
* graphite_reporter.h
*
* Created on: Jun 12, 2014
* Author: vpoliboy
*/
#ifndef GRAPHITE_REPORTER_H_
#define GRAPHITE_REPORTER_H_
#include <boost/scoped_ptr.hpp>
#include <boost/noncopyable.hpp>
#include <boost/chrono.hpp>
#include "cppmetrics/core/scheduled_reporter.h"
#include "cppmetrics/graphite/graphite_sender.h"
namespace cppmetrics {
namespace graphite {
/**
* A reporter which publishes metric values to a Graphite server.
* @see <a href="http://graphite.wikidot.com/">Graphite - Scalable Realtime Graphing</a>
*/
class GraphiteReporter: public core::ScheduledReporter, boost::noncopyable {
public:
/**
* Creates a {@link GraphiteReporter} instance. Uses the given registry, metricname prefix.
* @param registry The metric registry.
* @param graphite_sender The graphite server sender.
* @param prefix The prefix thats added to all the metric names in the registry before posting to graphite.
* @param rateUnit The conversion unit user for the rate metrics.
* @param durationUnit The conversion unit used for the duration metrics.
*/
GraphiteReporter(core::MetricRegistryPtr registry,
GraphiteSenderPtr graphite_sender,
std::string prefix,
boost::chrono::milliseconds rateUnit = boost::chrono::seconds(1));
virtual ~GraphiteReporter();
/**
* Reports all the metrics from the registry periodically to the graphite server.
* @param gauge_map all of the gauges in the registry
* @param counter_map all of the counters in the registry
* @param histogram_map all of the histograms in the registry
* @param meter_map all of the meters in the registry
* @param timer_map all of the timers in the registry
*/
virtual void report(core::CounterMap counter_map,
core::HistogramMap histogram_map,
core::MeteredMap meter_map,
core::TimerMap timer_map,
core::GaugeMap gauge_map);
private:
std::string prefix(const std::string& name, const char* extra = NULL);
template<class T> std::string format(T o);
void reportTimer(const std::string& name,
core::TimerPtr timer,
boost::uint64_t timestamp);
void reportMeter(const std::string& name,
core::MeteredPtr meter,
boost::uint64_t timestamp);
void reportHistogram(const std::string& name,
core::HistogramPtr histogram,
boost::uint64_t timestamp);
void reportCounter(const std::string& name,
core::CounterPtr counter,
boost::uint64_t timestamp);
void reportGauge(const std::string& name,
core::GaugePtr gauge,
boost::uint64_t timestamp);
core::MetricRegistryPtr registry_;
GraphiteSenderPtr sender_;
std::string prefix_;
boost::chrono::milliseconds rate_unit_;
boost::chrono::milliseconds duration_unit_;
};
} /* namespace graphite */
} /* namespace cppmetrics */
#endif /* GRAPHITE_REPORTER_H_ */
/*
* Copyright 2000-2014 NeuStar, Inc. All rights reserved.
* NeuStar, the Neustar logo and related names and logos are registered
* trademarks, service marks or tradenames of NeuStar, Inc. All other
* product names, company names, marks, logos and symbols may be trademarks
* of their respective owners.
*/
/*
* graphite_sender.h
*
* Created on: Jun 11, 2014
* Author: vpoliboy
*/
#ifndef GRAPHITE_SENDER_H_
#define GRAPHITE_SENDER_H_
#include <boost/shared_ptr.hpp>
namespace cppmetrics {
namespace graphite {
/**
* Interface to all graphite senders using different protocols like TCP UDP and AMQP etc.
*/
class GraphiteSender {
public:
virtual ~GraphiteSender() {
}
/**
* Connects to the graphite sender
* @return True on success, false otherwise.
* @throws boost::system_error if there is a problem.
*/
virtual void connect() = 0;
/**
* Posts the metric name, value and timestamp to the graphite server.
* @param name The name of the metric
* @param value The value of the metric
* @param timestamp The timestamp of the metric.
* @return True on success false otherwise.
* @throws boost::system_error if there is a problem.
*/
virtual void send(const std::string& name,
const std::string& value,
boost::uint64_t timestamp) = 0;
/**
* Closes the connection.
*/
virtual void close() = 0;
};
typedef boost::shared_ptr<GraphiteSender> GraphiteSenderPtr;
} /* namespace graphite */
} /* namespace cppmetrics */
#endif /* GRAPHITE_SENDER_H_ */
/*
* Copyright 2000-2014 NeuStar, Inc. All rights reserved.
* NeuStar, the Neustar logo and related names and logos are registered
* trademarks, service marks or tradenames of NeuStar, Inc. All other
* product names, company names, marks, logos and symbols may be trademarks
* of their respective owners.
*/
/*
* graphite_sender_tcp.h
*
* Created on: Jun 16, 2014
* Author: vpoliboy
*/
#ifndef GRAPHITE_SENDER_TCP_H_
#define GRAPHITE_SENDER_TCP_H_
#include <boost/cstdint.hpp>
#include <boost/asio.hpp>
#include <boost/scoped_ptr.hpp>
#include "cppmetrics/graphite/graphite_sender.h"
namespace cppmetrics {
namespace graphite {
/**
* Graphite TCP sender.
*/
class GraphiteSenderTCP: public GraphiteSender {
public:
/**
* Creates a new sender with the given params.
* @param host The graphite server host.
* @param port The graphite server port.
*/
GraphiteSenderTCP(const std::string& host, boost::uint32_t port);
virtual ~GraphiteSenderTCP();
/**
* Connects to the graphite sender over TCP.
* @return True on success, false otherwise.
* @throws std::runtime_error if there is a problem.
*/
virtual void connect();
/**
* Posts the metric name, value and timestamp to the graphite server.
* @param name The name of the metric
* @param value The value of the metric
* @param timestamp The timestamp of the metric.
* @return True on success false otherwise.
* @throws std::runtime_error if there is a problem.
*/
virtual void send(const std::string& name,
const std::string& value,
boost::uint64_t timestamp);
/**
* Closes the TCP connection.
*/
virtual void close();
private:
bool connected_;
std::string host_;
std::string port_;
boost::scoped_ptr<boost::asio::io_service> io_service_;
boost::scoped_ptr<boost::asio::ip::tcp::socket> socket_;
};
} /* namespace graphite */
} /* namespace cppmetrics */
#endif /* GRAPHITE_SENDER_TCP_H_ */
cmake_minimum_required(VERSION 2.8.12)
project(Microservice)
# version stuff
set (Microservice_VERSION_MAJOR 1)
set (Microservice_VERSION_MINOR 5)
set (Microservice_VERSION_PATCH 3)
set(Microservice_VERSION_STRING ${Microservice_VERSION_MAJOR}.${Microservice_VERSION_MINOR}.${Microservice_VERSION_PATCH})
# type build flags
#set(CMAKE_BUILD_TYPE Release)
set(BUILD_DIR build)
set(CMAKE_BUILD_TYPE Debug)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17 -m64 -g")
set(CMAKE_CXX_FLAGS_DEBUG "-O0")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${BUILD_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${BUILD_DIR}/bin)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# libcpprest is here for pplx tasks
# linked libs and their locations
set ( PROJECT_LINK_LIBS -lPocoFoundation -ljson -lhiredis -lcpprest -lcppmetrics -lboost_random -lboost_timer -lboost_chrono
-lboost_system -lboost_thread -lboost_date_time -lboost_regex -lboost_filesystem -lpthread
-lboost_random -lboost_chrono -lboost_system -lboost_thread -lssl
-lcrypto -lzmqpp -lzmq -levpp -levent)
# set ( PROJECT_LINK_LIBS -lPocoFoundation -ljson -lhiredis -lcpprest -lcppmetrics -lboost_random -lboost_timer -lboost_chrono
# -lboost_system -lboost_thread -lboost_date_time -lboost_regex -lboost_filesystem -lpthread
# -lboost_random -lboost_chrono -lboost_system -lboost_thread -lssl
# -lcrypto -lRabbitmq -lrabbitmq -llog4cpp -lglog -lzmqpp -lzmq )
link_directories( ../3party/lib )
#link_directories( ../internals/lib )
# h files locations
include_directories(src)
include_directories(SYSTEM ../3party/cereal-1.2.1/include)
include_directories(SYSTEM ../3party/rapidjson-cereal-1.2.1)
#include_directories(SYSTEM ../3party/rapidjson-0.11/include/rapidjson)
include_directories(SYSTEM ../3party/cppmetrics-0.1.1-Linux/include)
#include_directories(SYSTEM ../3party/civetweb/include)
#include_directories(SYSTEM ../3party/cpprest/Release/include)
include_directories(SYSTEM ../3party/rabbitmq)
include_directories(SYSTEM ../3party/flatbuffers/include)
#include_directories(SYSTEM ../3party/poco-1.7.8/Foundation/include)
include_directories(SYSTEM ../3party/evpp/build-release/include)
include_directories(SYSTEM ../3party/spdlog/include)
# include_directories(SYSTEM ../internals/include/Rabbitmq)
include_directories(SYSTEM /usr/include/Poco)
include_directories(SYSTEM /usr/include/hiredis)
# recursive search files cpp files
file(GLOB_RECURSE SOURCES "src/*.cpp" "src/*.h")
set (3PARTY_SOURCES )
# remove RMQ for now
get_filename_component(RMQHandler_file_path ${CMAKE_CURRENT_SOURCE_DIR}/src/handlers/Microservice_RMQHandler.cpp ABSOLUTE)
get_filename_component(RMQRequest_file_path ${CMAKE_CURRENT_SOURCE_DIR}/src/impl/Microservice_IRequestRMQImpl.cpp ABSOLUTE)
get_filename_component(RMQResponse_file_path ${CMAKE_CURRENT_SOURCE_DIR}/src/impl/Microservice_IResponseRMQImpl.cpp ABSOLUTE)
get_filename_component(RMQServer_file_path ${CMAKE_CURRENT_SOURCE_DIR}/src/impl/servers/Microservice_IRestServerRMQImpl.cpp ABSOLUTE)
get_filename_component(RMQClient_file_path ${CMAKE_CURRENT_SOURCE_DIR}/src/impl/clients/MSICommandClientRMQImpl.cpp ABSOLUTE)
get_filename_component(LOG4Cpp_file_path ${CMAKE_CURRENT_SOURCE_DIR}/src/impl/Microservices_ILoggerLog4cppImpl.cpp ABSOLUTE)
message("${RMQHandler_file_path}")
list(REMOVE_ITEM SOURCES "${RMQHandler_file_path}"
"${RMQRequest_file_path}"
"${RMQResponse_file_path}"
"${RMQServer_file_path}"
"${RMQClient_file_path}"
"${LOG4Cpp_file_path}")
message("${SOURCES}")
#Generate the shared library from the sources
add_library(Microservice SHARED ${SOURCES} ${3PARTY_SOURCES})
#add_library(Microservice SHARED ${SOURCES} ${3PARTY_SOURCES} src/impl/servers/Microservice_IRestServerEvppImpl.cpp src/impl/servers/Microservice_IRestServerEvppImpl.h src/impl/servers/Microservice_IRestServerZmqImpl.cpp src/impl/servers/Microservice_IRestServerZmqImpl.h src/common/Microservice_Iface.cpp src/impl/clients/MSICommandClientZmqImpl.cpp src/impl/clients/MSICommandClientZmqImpl.h src/impl/Microservice_ICacheClientPocoImpl.h src/handlers/Microservice_TestHandler.cpp src/handlers/Microservice_TestHandler.h)
target_link_libraries(Microservice ${PROJECT_LINK_LIBS} )
set_target_properties(Microservice PROPERTIES VERSION ${Microservice_VERSION_STRING}
SOVERSION ${Microservice_VERSION_MAJOR})
# Test part
#set (Microservice_TEST_SOURCES test/Microservice_Test.cpp )
# test_Microservice
add_executable(test_Microservice test/Microservice_Test.cpp) #EXCLUDE_FROM_ALL ${Microservice_TEST_SOURCES})
target_link_libraries (test_Microservice Microservice)
# test_MicroserviceClient
add_executable(test_MicroserviceClient test/Microservice_ClientTest.cpp) #EXCLUDE_FROM_ALL ${Microservice_TEST_SOURCES})
target_link_libraries (test_MicroserviceClient Microservice)
# test_ZMQ
#add_executable(test_ZMQ test/Microservice_ZMQTest.cpp) #EXCLUDE_FROM_ALL ${Microservice_TEST_SOURCES})
#target_link_libraries (test_ZMQ Microservice)
# install part
#set (CMAKE_INSTALL_PREFIX ../internals)
#file (GLOB_RECURSE INSTALL_FILES "src/*.h")
#install(FILES ${INSTALL_FILES} DESTINATION include/microservice)
#file (GLOB_RECURSE INSTALL_FILES "src/*.h")
#set (CMAKE_INSTALL_PREFIX ../internals)
#foreach ( file ${INSTALL_FILES} )
# get_filename_component(dir ${file} REALPATH )
# install( FILES ${file} DESTINATION include/${dir} )
#endforeach()
# install include files
#
#set (CMAKE_INSTALL_PREFIX ../internals)
set (CMAKE_INSTALL_PREFIX dist)
# src
file (GLOB INSTALL_FILES "src/*.h")
install(FILES ${INSTALL_FILES} DESTINATION include/microservice)
# src/common
file (GLOB INSTALL_FILES "src/common/*.h*")
install(FILES ${INSTALL_FILES} DESTINATION include/microservice/common)
# src/params
file (GLOB INSTALL_FILES "src/params/*.h")
install(FILES ${INSTALL_FILES} DESTINATION include/microservice/params)
# src/impl
file (GLOB INSTALL_FILES "src/impl/*.h")
install(FILES ${INSTALL_FILES} DESTINATION include/microservice/impl)
# src/impl/clients
file (GLOB INSTALL_FILES "src/impl/clients/*.h")
install(FILES ${INSTALL_FILES} DESTINATION include/microservice/impl/clients)
# src/impl/servers
file (GLOB INSTALL_FILES "src/impl/servers/*.h")
install(FILES ${INSTALL_FILES} DESTINATION include/microservice/impl/servers)
# src/handlers
file (GLOB INSTALL_FILES "src/handlers/*.h")
install(FILES ${INSTALL_FILES} DESTINATION include/microservice/handlers)
# src/utils
file (GLOB INSTALL_FILES "src/utils/*.h")
install(FILES ${INSTALL_FILES} DESTINATION include/microservice/utils)
# 3party libs
INSTALL( DIRECTORY ../3party/lib DESTINATION lib/3party )
# internal libs
#file (GLOB INSTALL_FILES "../internals/lib/libRabbitmq.*")
#install(FILES ${INSTALL_FILES} DESTINATION lib/internals)
#include 3party files
INSTALL( DIRECTORY ../3party/cereal-1.2.1/include DESTINATION include/3party/cereal-1.2.1 )
INSTALL( DIRECTORY ../3party/rapidjson-cereal-1.2.1 DESTINATION include/3party )
INSTALL( DIRECTORY ../3party/cppmetrics-0.1.1-Linux/include DESTINATION include/3party/cppmetrics )
file (GLOB INSTALL_FILES "../3party/mongoose/mongoose.*")
install(FILES ${INSTALL_FILES} DESTINATION include/3party/mongoose)
#INSTALL( DIRECTORY ../3party/cpprest/Release/include DESTINATION include/3party/cpprest )
INSTALL( DIRECTORY ../3party/evpp/build-release/include DESTINATION include/3party/evpp )
INSTALL( DIRECTORY ../3party/rabbitmq DESTINATION include/3party )
#INSTALL( DIRECTORY ../internals/include/Rabbitmq DESTINATION include/internals )
INSTALL( DIRECTORY /usr/include/hiredis DESTINATION include/3party )
INSTALL( DIRECTORY ../3party/flatbuffers/include DESTINATION include/3party/flatbuffers )
#CPack
include (InstallRequiredSystemLibraries)
set(CPACK_PACKAGE_VERSION_MAJOR ${Microservice_VERSION_MAJOR})
set(CPACK_PACKAGE_VERSION_MINOR ${Microservice_VERSION_MINOR})
set(CPACK_PACKAGE_VERSION_PATCH ${Microservice_VERSION_PATCH})
set(CPACK_SOURCE_PACKAGE_FILE_NAME
"${CMAKE_PROJECT_NAME}-${Microservice_VERSION_STRING}")
set(CPACK_SOURCE_GENERATOR "ZIP")
set(CPACK_PACKAGE_INSTALL_DIRECTORY dist)
set(CPACK_SET_DESTDIR "ON")
set(CPACK_PACKAGE_DEFAULT_LOCATION "./dist")
#set(CPACK_RESOURCE_FILE_LICENSE "./LICENSE")
#set(CPACK_SOURCE_IGNORE_FILES
# "/build/;/.bzr/;~$;${CPACK_SOURCE_IGNORE_FILES}")
include(CPack)
#add_custom_target(dist COMMAND ${CMAKE_MAKE_PROGRAM} package_source)
# RUN make package
#gradle uploadArchives -Pcversion=[version] -Ppublish_file=[the gz file]
# install lib files
#
install(TARGETS Microservice DESTINATION lib)
set(PUBLISH_FILE target/${CPACK_PACKAGE_FILE_NAME}-${CPACK_SYSTEM_NAME}.tar.gz)
add_custom_target(publish COMMAND gradle uploadArchives -Pcversion=${Microservice_VERSION_STRING} -Ppublish_file=${PUBLISH_FILE})
\ No newline at end of file
cmake_minimum_required(VERSION 2.8.12) cmake_minimum_required(VERSION 3.0)
project(Microservice) project(Microservice)
# version stuff # version stuff
set (Microservice_VERSION_MAJOR 1) set (Microservice_VERSION_MAJOR 1)
...@@ -16,6 +16,18 @@ set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${BUILD_DIR}/lib) ...@@ -16,6 +16,18 @@ set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${BUILD_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${BUILD_DIR}/bin) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${BUILD_DIR}/bin)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON) set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# add vcpkg toochain
include(/home/vscode/vcpkg/scripts/buildsystems/vcpkg.cmake)
find_package(glog CONFIG REQUIRED)
find_package(RapidJSON CONFIG REQUIRED)
find_package(Flatbuffers CONFIG REQUIRED)
find_package(nlohmann_json CONFIG REQUIRED)
#find_package(Poco CONFIG REQUIRED)
find_package(spdlog CONFIG REQUIRED)
find_package(cereal CONFIG REQUIRED)
#find_package(cpprestsdk CONFIG REQUIRED)
# libcpprest is here for pplx tasks # libcpprest is here for pplx tasks
# linked libs and their locations # linked libs and their locations
set ( PROJECT_LINK_LIBS -lPocoFoundation -ljson -lhiredis -lcpprest -lcppmetrics -lboost_random -lboost_timer -lboost_chrono set ( PROJECT_LINK_LIBS -lPocoFoundation -ljson -lhiredis -lcpprest -lcppmetrics -lboost_random -lboost_timer -lboost_chrono
...@@ -23,29 +35,25 @@ set ( PROJECT_LINK_LIBS -lPocoFoundation -ljson -lhiredis -lcpprest -lcppmetri ...@@ -23,29 +35,25 @@ set ( PROJECT_LINK_LIBS -lPocoFoundation -ljson -lhiredis -lcpprest -lcppmetri
-lboost_random -lboost_chrono -lboost_system -lboost_thread -lssl -lboost_random -lboost_chrono -lboost_system -lboost_thread -lssl
-lcrypto -lzmqpp -lzmq -levpp -levent) -lcrypto -lzmqpp -lzmq -levpp -levent)
# set ( PROJECT_LINK_LIBS -lPocoFoundation -ljson -lhiredis -lcpprest -lcppmetrics -lboost_random -lboost_timer -lboost_chrono link_directories( 3party/lib )
# -lboost_system -lboost_thread -lboost_date_time -lboost_regex -lboost_filesystem -lpthread
# -lboost_random -lboost_chrono -lboost_system -lboost_thread -lssl
# -lcrypto -lRabbitmq -lrabbitmq -llog4cpp -lglog -lzmqpp -lzmq )
link_directories( ../3party/lib )
#link_directories( ../internals/lib ) #link_directories( ../internals/lib )
# h files locations # h files locations
include_directories(src) include_directories(src)
include_directories(SYSTEM ../3party/cereal-1.2.1/include) include_directories(3party/include)
include_directories(SYSTEM ../3party/rapidjson-cereal-1.2.1) include_directories(PRIVATE /home/vscode/vcpkg/installed/x64-linux/include)
#include_directories(PRIVATE ${RAPIDJSON_INCLUDE_DIRS})
#include_directories(PRIVATE ${FLATBUFFERS_INCLUDE_DIRS})
#include_directories(SYSTEM ../3party/cereal-1.2.1/include)
#include_directories(SYSTEM ../3party/rapidjson-cereal-1.2.1)
#include_directories(SYSTEM ../3party/rapidjson-0.11/include/rapidjson) #include_directories(SYSTEM ../3party/rapidjson-0.11/include/rapidjson)
include_directories(SYSTEM ../3party/cppmetrics-0.1.1-Linux/include) #include_directories(SYSTEM ../3party/cppmetrics-0.1.1-Linux/include)
#include_directories(SYSTEM ../3party/civetweb/include) #include_directories(SYSTEM ../3party/rabbitmq)
#include_directories(SYSTEM ../3party/cpprest/Release/include) #include_directories(SYSTEM ../3party/flatbuffers/include)
include_directories(SYSTEM ../3party/rabbitmq) #include_directories(SYSTEM ../3party/evpp/build-release/include)
include_directories(SYSTEM ../3party/flatbuffers/include) #include_directories(SYSTEM ../3party/spdlog/include)
#include_directories(SYSTEM ../3party/poco-1.7.8/Foundation/include) #include_directories(SYSTEM /usr/include/Poco)
include_directories(SYSTEM ../3party/evpp/build-release/include) #include_directories(SYSTEM /usr/include/hiredis)
include_directories(SYSTEM ../3party/spdlog/include)
# include_directories(SYSTEM ../internals/include/Rabbitmq)
include_directories(SYSTEM /usr/include/Poco)
include_directories(SYSTEM /usr/include/hiredis)
# recursive search files cpp files # recursive search files cpp files
file(GLOB_RECURSE SOURCES "src/*.cpp" "src/*.h") file(GLOB_RECURSE SOURCES "src/*.cpp" "src/*.h")
...@@ -61,6 +69,7 @@ get_filename_component(LOG4Cpp_file_path ${CMAKE_CURRENT_SOURCE_DIR}/src/impl/Mi ...@@ -61,6 +69,7 @@ get_filename_component(LOG4Cpp_file_path ${CMAKE_CURRENT_SOURCE_DIR}/src/impl/Mi
message("${RMQHandler_file_path}") message("${RMQHandler_file_path}")
list(REMOVE_ITEM SOURCES "${RMQHandler_file_path}" list(REMOVE_ITEM SOURCES "${RMQHandler_file_path}"
"${RMQRequest_file_path}" "${RMQRequest_file_path}"
"${RMQResponse_file_path}" "${RMQResponse_file_path}"
...@@ -70,8 +79,10 @@ list(REMOVE_ITEM SOURCES "${RMQHandler_file_path}" ...@@ -70,8 +79,10 @@ list(REMOVE_ITEM SOURCES "${RMQHandler_file_path}"
message("${SOURCES}") message("${SOURCES}")
#Generate the shared library from the sources #Generate the shared library from the sources
add_library(Microservice SHARED ${SOURCES} ${3PARTY_SOURCES}) add_library(Microservice SHARED ${SOURCES} ${3PARTY_SOURCES})
#add_library(Microservice SHARED ${SOURCES} ${3PARTY_SOURCES} src/impl/servers/Microservice_IRestServerEvppImpl.cpp src/impl/servers/Microservice_IRestServerEvppImpl.h src/impl/servers/Microservice_IRestServerZmqImpl.cpp src/impl/servers/Microservice_IRestServerZmqImpl.h src/common/Microservice_Iface.cpp src/impl/clients/MSICommandClientZmqImpl.cpp src/impl/clients/MSICommandClientZmqImpl.h src/impl/Microservice_ICacheClientPocoImpl.h src/handlers/Microservice_TestHandler.cpp src/handlers/Microservice_TestHandler.h) #add_library(Microservice SHARED ${SOURCES} ${3PARTY_SOURCES} src/impl/servers/Microservice_IRestServerEvppImpl.cpp src/impl/servers/Microservice_IRestServerEvppImpl.h src/impl/servers/Microservice_IRestServerZmqImpl.cpp src/impl/servers/Microservice_IRestServerZmqImpl.h src/common/Microservice_Iface.cpp src/impl/clients/MSICommandClientZmqImpl.cpp src/impl/clients/MSICommandClientZmqImpl.h src/impl/Microservice_ICacheClientPocoImpl.h src/handlers/Microservice_TestHandler.cpp src/handlers/Microservice_TestHandler.h)
#target_include_directories(Microservice PRIVATE ${RAPIDJSON_INCLUDE_DIRS})
target_link_libraries(Microservice ${PROJECT_LINK_LIBS} ) target_link_libraries(Microservice ${PROJECT_LINK_LIBS} )
set_target_properties(Microservice PROPERTIES VERSION ${Microservice_VERSION_STRING} set_target_properties(Microservice PROPERTIES VERSION ${Microservice_VERSION_STRING}
SOVERSION ${Microservice_VERSION_MAJOR}) SOVERSION ${Microservice_VERSION_MAJOR})
......
#FROM ubuntu:14.04 #FROM municipalitybank.com:5050/mcx/devops/dev-cpp:gcc7
#FROM ubuntu-debootstrap:14.04 FROM municipalitybank.com:5050/mcx/devops/dev-cpp:vscode-gcc8
FROM municipalitybank.com:5050/mcx/devops/dev-cpp:gcc7
# install deb packages
USER root USER root
COPY ./doc/install-dependencies.sh /usr/ COPY ./doc/install-deb-dependencies.sh /usr/
RUN chmod +x /usr/install-dependencies.sh RUN chmod +x /usr/install-deb-dependencies.sh
RUN apt-get update RUN apt-get update
RUN /usr/install-dependencies.sh RUN /usr/install-deb-dependencies.sh
# Clean up APT when done. # Clean up APT when done.
RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
# setting for gcc >= 4.9.2 COPY ./doc/install-vcpkg-dependencies.sh /tmp/
#RUN rm /usr/lib/x86_64-linux-gnu/libstdc++.so.6 RUN chmod +x /tmp/install-vcpkg-dependencies.sh
#COPY ./tmp/libstdc++.so.6 /usr/lib/x86_64-linux-gnu/libstdc++.so.6 # install vcpkg packages
USER vscode
# setting for shared-memory WORKDIR /home/vscode
#RUN echo kernel.shmmax=49249672960 >> /etc/sysctl.conf RUN /tmp/install-vcpkg-dependencies.sh
#RUN echo kernel.shmall=10485760 >> /etc/sysctl.conf
# app
# COPY ./tmp/* /usr/lib/x86_64-linux-gnu/
# COPY ./bin/test_MicroserviceClient /usr/
# WORKDIR /usr #USER develop
USER develop #EXPOSE 50010
EXPOSE 50010
# ENTRYPOINT ["/bin/bash"] # ENTRYPOINT ["/bin/bash"]
...@@ -5,9 +5,12 @@ ...@@ -5,9 +5,12 @@
# #
# Created on May 8, 2016, 9:59:18 AM # Created on May 8, 2016, 9:59:18 AM
# #
# apt-get install -y libhiredis0.13 libhiredis-dev libzmq5 libzmq3-dev liblog4cpp5v5 liblog4cpp5-dev \ # apt-get install -y libhiredis-dev libzmq3-dev liblog4cpp5-dev \
# libgoogle-glog-dev libboost-all-dev libssl-dev uuid-dev libzmqpp-dev libmhash-dev libevent-dev # libgoogle-glog-dev libboost-all-dev libssl-dev uuid-dev libzmqpp-dev libmhash-dev libevent-dev \
# libpoco-dev libcpprest-dev
# bison flex pkg-config is for poco
echo "Installing deb packages..."
apt-get install -y libzmq3-dev libssl-dev libzmqpp-dev libmhash-dev bison flex pkg-config
#apt-get install -y libzmq3-dev libssl-dev libmhash-dev
apt-get install -y libhiredis-dev libzmq3-dev liblog4cpp5-dev \
libgoogle-glog-dev libboost-all-dev libssl-dev uuid-dev libzmqpp-dev libmhash-dev libevent-dev \
libpoco-dev libcpprest-dev
\ No newline at end of file
#!/bin/bash
#
# File: install-dependencies.sh
# Author: amir
#
# Created on May 8, 2016, 9:59:18 AM
#
# apt-get install -y libhiredis-dev libzmq3-dev liblog4cpp5-dev \
# libgoogle-glog-dev libboost-all-dev libssl-dev uuid-dev libzmqpp-dev libmhash-dev libevent-dev \
# libpoco-dev libcpprest-dev
source /home/vscode/.bashrc
echo "Installing vcpkg packages..."
cd vcpkg && git pull
#/home/vscode/vcpkg/vcpkg install evpp spdlog nlohmann-json cereal rapidjson flatbuffers poco hiredis glog log4cpp libuuid cppzmq
/home/vscode/vcpkg/vcpkg install evpp spdlog nlohmann-json cereal rapidjson flatbuffers poco hiredis glog log4cpp libuuid boost-foreach
- memory leak on performance testing of SendZmqRestRequests - memory leak on performance testing of SendZmqRestRequests
- upon receiving the response , forward it to a new task to be carried by another thread - upon receiving the response , forward it to a new task to be carried by another thread
- catch http exception when callback url is down - catch http exception when callback url is down
+ add Qihoo360/evpp as the http client with async, maybe also as server + add Qihoo360/evpp as the http client with async, maybe also as server
\ No newline at end of file
RemoteVSContainers and c++17 feature:
- Create a remote development container with vcpkg
- CMake Additions:
"-DCMAKE_TOOLCHAIN_FILE=/home/vscode/vcpkg/scripts/buildsystems/vcpkg.cmake"
find_package(glog CONFIG REQUIRED)
target_link_libraries(main PRIVATE glog::glog)
find_package(RapidJSON CONFIG REQUIRED)
target_include_directories(main PRIVATE ${RAPIDJSON_INCLUDE_DIRS})
find_package(Flatbuffers CONFIG REQUIRED)
target_link_libraries(main PRIVATE flatbuffers::flatbuffers)
find_package(nlohmann_json CONFIG REQUIRED)
target_link_libraries(main PRIVATE nlohmann_json nlohmann_json::nlohmann_json)
find_package(Poco CONFIG REQUIRED)
# Note: 11 target(s) were omitted.
target_link_libraries(main PRIVATE Poco::Net Poco::XML Poco::Zip Poco::Data)
find_package(spdlog CONFIG REQUIRED)
target_link_libraries(main PRIVATE spdlog::spdlog spdlog::spdlog_header_only)
target_link_libraries(main PRIVATE cpprestsdk::cpprest cpprestsdk::cpprestsdk_zlib_internal cpprestsdk::cpprestsdk_boost_internal cpprestsdk::cpprestsdk_openssl_internal)
- Check CMake https://cmake.org/cmake/help/v3.11/module/FetchContent.html for fetching external project directly from github
- remove cppmetrics for now, after add influxdb from https://github.com/awegrzyn/influxdb-cxx and create our own cppmetrics (maybe open source)
or fork it for c++17 and no boost
- remove cpprest
- remove pplx tasks, and replace with evpp for client async
- replace boost with std
[packages available via vcpkg]
evpp
spdlog
nlohmann-json
cereal
rapidjson
flatbuffers
poco
hiredis
glog
log4cpp
libuuid
...@@ -9,9 +9,9 @@ services: ...@@ -9,9 +9,9 @@ services:
privileged: true privileged: true
container_name: devenv container_name: devenv
volumes: volumes:
- "./:/home/develop/project" - "./:/home/vscode/project"
- "./../3party:/home/develop/3party" # - "./../3party:/home/vscode/3party"
command: tail -f /dev/null # command: tail -f /dev/null
networks: networks:
- devnet - devnet
networks: networks:
......
namespace common.context; namespace common.context;
/// compile by running 'compile RestMsg.fbs' task
enum CrudMethod:byte { Create = 0, Read, Update, Delete } enum CrudMethod:byte { Create = 0, Read, Update, Delete }
...@@ -10,5 +11,4 @@ table RestMsg { ...@@ -10,5 +11,4 @@ table RestMsg {
queryString:string; queryString:string;
content:string; content:string;
} }
root_type RestMsg; root_type RestMsg;
...@@ -10,6 +10,7 @@ namespace common { ...@@ -10,6 +10,7 @@ namespace common {
namespace context { namespace context {
struct RestMsg; struct RestMsg;
struct RestMsgBuilder;
enum CrudMethod { enum CrudMethod {
CrudMethod_Create = 0, CrudMethod_Create = 0,
...@@ -20,8 +21,18 @@ enum CrudMethod { ...@@ -20,8 +21,18 @@ enum CrudMethod {
CrudMethod_MAX = CrudMethod_Delete CrudMethod_MAX = CrudMethod_Delete
}; };
inline const char **EnumNamesCrudMethod() { inline const CrudMethod (&EnumValuesCrudMethod())[4] {
static const char *names[] = { static const CrudMethod values[] = {
CrudMethod_Create,
CrudMethod_Read,
CrudMethod_Update,
CrudMethod_Delete
};
return values;
}
inline const char * const *EnumNamesCrudMethod() {
static const char * const names[5] = {
"Create", "Create",
"Read", "Read",
"Update", "Update",
...@@ -32,12 +43,14 @@ inline const char **EnumNamesCrudMethod() { ...@@ -32,12 +43,14 @@ inline const char **EnumNamesCrudMethod() {
} }
inline const char *EnumNameCrudMethod(CrudMethod e) { inline const char *EnumNameCrudMethod(CrudMethod e) {
const size_t index = static_cast<int>(e); if (flatbuffers::IsOutRange(e, CrudMethod_Create, CrudMethod_Delete)) return "";
const size_t index = static_cast<size_t>(e);
return EnumNamesCrudMethod()[index]; return EnumNamesCrudMethod()[index];
} }
struct RestMsg FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { struct RestMsg FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
enum { typedef RestMsgBuilder Builder;
enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE {
VT_RCID = 4, VT_RCID = 4,
VT_SOURCE = 6, VT_SOURCE = 6,
VT_CRUDMETHOD = 8, VT_CRUDMETHOD = 8,
...@@ -51,8 +64,8 @@ struct RestMsg FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { ...@@ -51,8 +64,8 @@ struct RestMsg FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
const flatbuffers::String *source() const { const flatbuffers::String *source() const {
return GetPointer<const flatbuffers::String *>(VT_SOURCE); return GetPointer<const flatbuffers::String *>(VT_SOURCE);
} }
CrudMethod crudMethod() const { common::context::CrudMethod crudMethod() const {
return static_cast<CrudMethod>(GetField<int8_t>(VT_CRUDMETHOD, 1)); return static_cast<common::context::CrudMethod>(GetField<int8_t>(VT_CRUDMETHOD, 1));
} }
const flatbuffers::String *url() const { const flatbuffers::String *url() const {
return GetPointer<const flatbuffers::String *>(VT_URL); return GetPointer<const flatbuffers::String *>(VT_URL);
...@@ -66,20 +79,21 @@ struct RestMsg FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { ...@@ -66,20 +79,21 @@ struct RestMsg FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
bool Verify(flatbuffers::Verifier &verifier) const { bool Verify(flatbuffers::Verifier &verifier) const {
return VerifyTableStart(verifier) && return VerifyTableStart(verifier) &&
VerifyField<uint64_t>(verifier, VT_RCID) && VerifyField<uint64_t>(verifier, VT_RCID) &&
VerifyField<flatbuffers::uoffset_t>(verifier, VT_SOURCE) && VerifyOffset(verifier, VT_SOURCE) &&
verifier.Verify(source()) && verifier.VerifyString(source()) &&
VerifyField<int8_t>(verifier, VT_CRUDMETHOD) && VerifyField<int8_t>(verifier, VT_CRUDMETHOD) &&
VerifyField<flatbuffers::uoffset_t>(verifier, VT_URL) && VerifyOffset(verifier, VT_URL) &&
verifier.Verify(url()) && verifier.VerifyString(url()) &&
VerifyField<flatbuffers::uoffset_t>(verifier, VT_QUERYSTRING) && VerifyOffset(verifier, VT_QUERYSTRING) &&
verifier.Verify(queryString()) && verifier.VerifyString(queryString()) &&
VerifyField<flatbuffers::uoffset_t>(verifier, VT_CONTENT) && VerifyOffset(verifier, VT_CONTENT) &&
verifier.Verify(content()) && verifier.VerifyString(content()) &&
verifier.EndTable(); verifier.EndTable();
} }
}; };
struct RestMsgBuilder { struct RestMsgBuilder {
typedef RestMsg Table;
flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::FlatBufferBuilder &fbb_;
flatbuffers::uoffset_t start_; flatbuffers::uoffset_t start_;
void add_rcid(uint64_t rcid) { void add_rcid(uint64_t rcid) {
...@@ -88,7 +102,7 @@ struct RestMsgBuilder { ...@@ -88,7 +102,7 @@ struct RestMsgBuilder {
void add_source(flatbuffers::Offset<flatbuffers::String> source) { void add_source(flatbuffers::Offset<flatbuffers::String> source) {
fbb_.AddOffset(RestMsg::VT_SOURCE, source); fbb_.AddOffset(RestMsg::VT_SOURCE, source);
} }
void add_crudMethod(CrudMethod crudMethod) { void add_crudMethod(common::context::CrudMethod crudMethod) {
fbb_.AddElement<int8_t>(RestMsg::VT_CRUDMETHOD, static_cast<int8_t>(crudMethod), 1); fbb_.AddElement<int8_t>(RestMsg::VT_CRUDMETHOD, static_cast<int8_t>(crudMethod), 1);
} }
void add_url(flatbuffers::Offset<flatbuffers::String> url) { void add_url(flatbuffers::Offset<flatbuffers::String> url) {
...@@ -100,13 +114,13 @@ struct RestMsgBuilder { ...@@ -100,13 +114,13 @@ struct RestMsgBuilder {
void add_content(flatbuffers::Offset<flatbuffers::String> content) { void add_content(flatbuffers::Offset<flatbuffers::String> content) {
fbb_.AddOffset(RestMsg::VT_CONTENT, content); fbb_.AddOffset(RestMsg::VT_CONTENT, content);
} }
RestMsgBuilder(flatbuffers::FlatBufferBuilder &_fbb) explicit RestMsgBuilder(flatbuffers::FlatBufferBuilder &_fbb)
: fbb_(_fbb) { : fbb_(_fbb) {
start_ = fbb_.StartTable(); start_ = fbb_.StartTable();
} }
RestMsgBuilder &operator=(const RestMsgBuilder &); RestMsgBuilder &operator=(const RestMsgBuilder &);
flatbuffers::Offset<RestMsg> Finish() { flatbuffers::Offset<RestMsg> Finish() {
const auto end = fbb_.EndTable(start_, 6); const auto end = fbb_.EndTable(start_);
auto o = flatbuffers::Offset<RestMsg>(end); auto o = flatbuffers::Offset<RestMsg>(end);
return o; return o;
} }
...@@ -116,7 +130,7 @@ inline flatbuffers::Offset<RestMsg> CreateRestMsg( ...@@ -116,7 +130,7 @@ inline flatbuffers::Offset<RestMsg> CreateRestMsg(
flatbuffers::FlatBufferBuilder &_fbb, flatbuffers::FlatBufferBuilder &_fbb,
uint64_t rcid = 0, uint64_t rcid = 0,
flatbuffers::Offset<flatbuffers::String> source = 0, flatbuffers::Offset<flatbuffers::String> source = 0,
CrudMethod crudMethod = CrudMethod_Read, common::context::CrudMethod crudMethod = common::context::CrudMethod_Read,
flatbuffers::Offset<flatbuffers::String> url = 0, flatbuffers::Offset<flatbuffers::String> url = 0,
flatbuffers::Offset<flatbuffers::String> queryString = 0, flatbuffers::Offset<flatbuffers::String> queryString = 0,
flatbuffers::Offset<flatbuffers::String> content = 0) { flatbuffers::Offset<flatbuffers::String> content = 0) {
...@@ -134,35 +148,54 @@ inline flatbuffers::Offset<RestMsg> CreateRestMsgDirect( ...@@ -134,35 +148,54 @@ inline flatbuffers::Offset<RestMsg> CreateRestMsgDirect(
flatbuffers::FlatBufferBuilder &_fbb, flatbuffers::FlatBufferBuilder &_fbb,
uint64_t rcid = 0, uint64_t rcid = 0,
const char *source = nullptr, const char *source = nullptr,
CrudMethod crudMethod = CrudMethod_Read, common::context::CrudMethod crudMethod = common::context::CrudMethod_Read,
const char *url = nullptr, const char *url = nullptr,
const char *queryString = nullptr, const char *queryString = nullptr,
const char *content = nullptr) { const char *content = nullptr) {
auto source__ = source ? _fbb.CreateString(source) : 0;
auto url__ = url ? _fbb.CreateString(url) : 0;
auto queryString__ = queryString ? _fbb.CreateString(queryString) : 0;
auto content__ = content ? _fbb.CreateString(content) : 0;
return common::context::CreateRestMsg( return common::context::CreateRestMsg(
_fbb, _fbb,
rcid, rcid,
source ? _fbb.CreateString(source) : 0, source__,
crudMethod, crudMethod,
url ? _fbb.CreateString(url) : 0, url__,
queryString ? _fbb.CreateString(queryString) : 0, queryString__,
content ? _fbb.CreateString(content) : 0); content__);
} }
inline const common::context::RestMsg *GetRestMsg(const void *buf) { inline const common::context::RestMsg *GetRestMsg(const void *buf) {
return flatbuffers::GetRoot<common::context::RestMsg>(buf); return flatbuffers::GetRoot<common::context::RestMsg>(buf);
} }
inline const common::context::RestMsg *GetSizePrefixedRestMsg(const void *buf) {
return flatbuffers::GetSizePrefixedRoot<common::context::RestMsg>(buf);
}
inline bool VerifyRestMsgBuffer( inline bool VerifyRestMsgBuffer(
flatbuffers::Verifier &verifier) { flatbuffers::Verifier &verifier) {
return verifier.VerifyBuffer<common::context::RestMsg>(nullptr); return verifier.VerifyBuffer<common::context::RestMsg>(nullptr);
} }
inline bool VerifySizePrefixedRestMsgBuffer(
flatbuffers::Verifier &verifier) {
return verifier.VerifySizePrefixedBuffer<common::context::RestMsg>(nullptr);
}
inline void FinishRestMsgBuffer( inline void FinishRestMsgBuffer(
flatbuffers::FlatBufferBuilder &fbb, flatbuffers::FlatBufferBuilder &fbb,
flatbuffers::Offset<common::context::RestMsg> root) { flatbuffers::Offset<common::context::RestMsg> root) {
fbb.Finish(root); fbb.Finish(root);
} }
inline void FinishSizePrefixedRestMsgBuffer(
flatbuffers::FlatBufferBuilder &fbb,
flatbuffers::Offset<common::context::RestMsg> root) {
fbb.FinishSizePrefixed(root);
}
} // namespace context } // namespace context
} // namespace common } // namespace common
......
// automatically generated by the FlatBuffers compiler, do not modify
#ifndef FLATBUFFERS_GENERATED_RESTMSG_COMMON_CONTEXT_H_
#define FLATBUFFERS_GENERATED_RESTMSG_COMMON_CONTEXT_H_
#include "flatbuffers/flatbuffers.h"
namespace common {
namespace context {
struct RestMsg;
enum CrudMethod {
CrudMethod_Create = 0,
CrudMethod_Read = 1,
CrudMethod_Update = 2,
CrudMethod_Delete = 3,
CrudMethod_MIN = CrudMethod_Create,
CrudMethod_MAX = CrudMethod_Delete
};
inline const char **EnumNamesCrudMethod() {
static const char *names[] = {
"Create",
"Read",
"Update",
"Delete",
nullptr
};
return names;
}
inline const char *EnumNameCrudMethod(CrudMethod e) {
const size_t index = static_cast<int>(e);
return EnumNamesCrudMethod()[index];
}
struct RestMsg FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
enum {
VT_RCID = 4,
VT_SOURCE = 6,
VT_CRUDMETHOD = 8,
VT_URL = 10,
VT_QUERYSTRING = 12,
VT_CONTENT = 14
};
uint64_t rcid() const {
return GetField<uint64_t>(VT_RCID, 0);
}
const flatbuffers::String *source() const {
return GetPointer<const flatbuffers::String *>(VT_SOURCE);
}
CrudMethod crudMethod() const {
return static_cast<CrudMethod>(GetField<int8_t>(VT_CRUDMETHOD, 1));
}
const flatbuffers::String *url() const {
return GetPointer<const flatbuffers::String *>(VT_URL);
}
const flatbuffers::String *queryString() const {
return GetPointer<const flatbuffers::String *>(VT_QUERYSTRING);
}
const flatbuffers::String *content() const {
return GetPointer<const flatbuffers::String *>(VT_CONTENT);
}
bool Verify(flatbuffers::Verifier &verifier) const {
return VerifyTableStart(verifier) &&
VerifyField<uint64_t>(verifier, VT_RCID) &&
VerifyField<flatbuffers::uoffset_t>(verifier, VT_SOURCE) &&
verifier.Verify(source()) &&
VerifyField<int8_t>(verifier, VT_CRUDMETHOD) &&
VerifyField<flatbuffers::uoffset_t>(verifier, VT_URL) &&
verifier.Verify(url()) &&
VerifyField<flatbuffers::uoffset_t>(verifier, VT_QUERYSTRING) &&
verifier.Verify(queryString()) &&
VerifyField<flatbuffers::uoffset_t>(verifier, VT_CONTENT) &&
verifier.Verify(content()) &&
verifier.EndTable();
}
};
struct RestMsgBuilder {
flatbuffers::FlatBufferBuilder &fbb_;
flatbuffers::uoffset_t start_;
void add_rcid(uint64_t rcid) {
fbb_.AddElement<uint64_t>(RestMsg::VT_RCID, rcid, 0);
}
void add_source(flatbuffers::Offset<flatbuffers::String> source) {
fbb_.AddOffset(RestMsg::VT_SOURCE, source);
}
void add_crudMethod(CrudMethod crudMethod) {
fbb_.AddElement<int8_t>(RestMsg::VT_CRUDMETHOD, static_cast<int8_t>(crudMethod), 1);
}
void add_url(flatbuffers::Offset<flatbuffers::String> url) {
fbb_.AddOffset(RestMsg::VT_URL, url);
}
void add_queryString(flatbuffers::Offset<flatbuffers::String> queryString) {
fbb_.AddOffset(RestMsg::VT_QUERYSTRING, queryString);
}
void add_content(flatbuffers::Offset<flatbuffers::String> content) {
fbb_.AddOffset(RestMsg::VT_CONTENT, content);
}
RestMsgBuilder(flatbuffers::FlatBufferBuilder &_fbb)
: fbb_(_fbb) {
start_ = fbb_.StartTable();
}
RestMsgBuilder &operator=(const RestMsgBuilder &);
flatbuffers::Offset<RestMsg> Finish() {
const auto end = fbb_.EndTable(start_, 6);
auto o = flatbuffers::Offset<RestMsg>(end);
return o;
}
};
inline flatbuffers::Offset<RestMsg> CreateRestMsg(
flatbuffers::FlatBufferBuilder &_fbb,
uint64_t rcid = 0,
flatbuffers::Offset<flatbuffers::String> source = 0,
CrudMethod crudMethod = CrudMethod_Read,
flatbuffers::Offset<flatbuffers::String> url = 0,
flatbuffers::Offset<flatbuffers::String> queryString = 0,
flatbuffers::Offset<flatbuffers::String> content = 0) {
RestMsgBuilder builder_(_fbb);
builder_.add_rcid(rcid);
builder_.add_content(content);
builder_.add_queryString(queryString);
builder_.add_url(url);
builder_.add_source(source);
builder_.add_crudMethod(crudMethod);
return builder_.Finish();
}
inline flatbuffers::Offset<RestMsg> CreateRestMsgDirect(
flatbuffers::FlatBufferBuilder &_fbb,
uint64_t rcid = 0,
const char *source = nullptr,
CrudMethod crudMethod = CrudMethod_Read,
const char *url = nullptr,
const char *queryString = nullptr,
const char *content = nullptr) {
return common::context::CreateRestMsg(
_fbb,
rcid,
source ? _fbb.CreateString(source) : 0,
crudMethod,
url ? _fbb.CreateString(url) : 0,
queryString ? _fbb.CreateString(queryString) : 0,
content ? _fbb.CreateString(content) : 0);
}
inline const common::context::RestMsg *GetRestMsg(const void *buf) {
return flatbuffers::GetRoot<common::context::RestMsg>(buf);
}
inline bool VerifyRestMsgBuffer(
flatbuffers::Verifier &verifier) {
return verifier.VerifyBuffer<common::context::RestMsg>(nullptr);
}
inline void FinishRestMsgBuffer(
flatbuffers::FlatBufferBuilder &fbb,
flatbuffers::Offset<common::context::RestMsg> root) {
fbb.Finish(root);
}
} // namespace context
} // namespace common
#endif // FLATBUFFERS_GENERATED_RESTMSG_COMMON_CONTEXT_H_
namespace common.context; namespace common.context;
/// compile by running 'compile RestResponse.fbs' task
table RestResponse { table RestResponse {
rcid:ulong; rcid:ulong;
......
...@@ -10,9 +10,11 @@ namespace common { ...@@ -10,9 +10,11 @@ namespace common {
namespace context { namespace context {
struct RestResponse; struct RestResponse;
struct RestResponseBuilder;
struct RestResponse FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { struct RestResponse FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
enum { typedef RestResponseBuilder Builder;
enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE {
VT_RCID = 4, VT_RCID = 4,
VT_RESPONSE = 6 VT_RESPONSE = 6
}; };
...@@ -25,13 +27,14 @@ struct RestResponse FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { ...@@ -25,13 +27,14 @@ struct RestResponse FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
bool Verify(flatbuffers::Verifier &verifier) const { bool Verify(flatbuffers::Verifier &verifier) const {
return VerifyTableStart(verifier) && return VerifyTableStart(verifier) &&
VerifyField<uint64_t>(verifier, VT_RCID) && VerifyField<uint64_t>(verifier, VT_RCID) &&
VerifyField<flatbuffers::uoffset_t>(verifier, VT_RESPONSE) && VerifyOffset(verifier, VT_RESPONSE) &&
verifier.Verify(response()) && verifier.VerifyString(response()) &&
verifier.EndTable(); verifier.EndTable();
} }
}; };
struct RestResponseBuilder { struct RestResponseBuilder {
typedef RestResponse Table;
flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::FlatBufferBuilder &fbb_;
flatbuffers::uoffset_t start_; flatbuffers::uoffset_t start_;
void add_rcid(uint64_t rcid) { void add_rcid(uint64_t rcid) {
...@@ -40,13 +43,13 @@ struct RestResponseBuilder { ...@@ -40,13 +43,13 @@ struct RestResponseBuilder {
void add_response(flatbuffers::Offset<flatbuffers::String> response) { void add_response(flatbuffers::Offset<flatbuffers::String> response) {
fbb_.AddOffset(RestResponse::VT_RESPONSE, response); fbb_.AddOffset(RestResponse::VT_RESPONSE, response);
} }
RestResponseBuilder(flatbuffers::FlatBufferBuilder &_fbb) explicit RestResponseBuilder(flatbuffers::FlatBufferBuilder &_fbb)
: fbb_(_fbb) { : fbb_(_fbb) {
start_ = fbb_.StartTable(); start_ = fbb_.StartTable();
} }
RestResponseBuilder &operator=(const RestResponseBuilder &); RestResponseBuilder &operator=(const RestResponseBuilder &);
flatbuffers::Offset<RestResponse> Finish() { flatbuffers::Offset<RestResponse> Finish() {
const auto end = fbb_.EndTable(start_, 2); const auto end = fbb_.EndTable(start_);
auto o = flatbuffers::Offset<RestResponse>(end); auto o = flatbuffers::Offset<RestResponse>(end);
return o; return o;
} }
...@@ -66,27 +69,43 @@ inline flatbuffers::Offset<RestResponse> CreateRestResponseDirect( ...@@ -66,27 +69,43 @@ inline flatbuffers::Offset<RestResponse> CreateRestResponseDirect(
flatbuffers::FlatBufferBuilder &_fbb, flatbuffers::FlatBufferBuilder &_fbb,
uint64_t rcid = 0, uint64_t rcid = 0,
const char *response = nullptr) { const char *response = nullptr) {
auto response__ = response ? _fbb.CreateString(response) : 0;
return common::context::CreateRestResponse( return common::context::CreateRestResponse(
_fbb, _fbb,
rcid, rcid,
response ? _fbb.CreateString(response) : 0); response__);
} }
inline const common::context::RestResponse *GetRestResponse(const void *buf) { inline const common::context::RestResponse *GetRestResponse(const void *buf) {
return flatbuffers::GetRoot<common::context::RestResponse>(buf); return flatbuffers::GetRoot<common::context::RestResponse>(buf);
} }
inline const common::context::RestResponse *GetSizePrefixedRestResponse(const void *buf) {
return flatbuffers::GetSizePrefixedRoot<common::context::RestResponse>(buf);
}
inline bool VerifyRestResponseBuffer( inline bool VerifyRestResponseBuffer(
flatbuffers::Verifier &verifier) { flatbuffers::Verifier &verifier) {
return verifier.VerifyBuffer<common::context::RestResponse>(nullptr); return verifier.VerifyBuffer<common::context::RestResponse>(nullptr);
} }
inline bool VerifySizePrefixedRestResponseBuffer(
flatbuffers::Verifier &verifier) {
return verifier.VerifySizePrefixedBuffer<common::context::RestResponse>(nullptr);
}
inline void FinishRestResponseBuffer( inline void FinishRestResponseBuffer(
flatbuffers::FlatBufferBuilder &fbb, flatbuffers::FlatBufferBuilder &fbb,
flatbuffers::Offset<common::context::RestResponse> root) { flatbuffers::Offset<common::context::RestResponse> root) {
fbb.Finish(root); fbb.Finish(root);
} }
inline void FinishSizePrefixedRestResponseBuffer(
flatbuffers::FlatBufferBuilder &fbb,
flatbuffers::Offset<common::context::RestResponse> root) {
fbb.FinishSizePrefixed(root);
}
} // namespace context } // namespace context
} // namespace common } // namespace common
......
// automatically generated by the FlatBuffers compiler, do not modify
#ifndef FLATBUFFERS_GENERATED_RESTRESPONSE_COMMON_CONTEXT_H_
#define FLATBUFFERS_GENERATED_RESTRESPONSE_COMMON_CONTEXT_H_
#include "flatbuffers/flatbuffers.h"
namespace common {
namespace context {
struct RestResponse;
struct RestResponse FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
enum {
VT_RCID = 4,
VT_RESPONSE = 6
};
uint64_t rcid() const {
return GetField<uint64_t>(VT_RCID, 0);
}
const flatbuffers::String *response() const {
return GetPointer<const flatbuffers::String *>(VT_RESPONSE);
}
bool Verify(flatbuffers::Verifier &verifier) const {
return VerifyTableStart(verifier) &&
VerifyField<uint64_t>(verifier, VT_RCID) &&
VerifyField<flatbuffers::uoffset_t>(verifier, VT_RESPONSE) &&
verifier.Verify(response()) &&
verifier.EndTable();
}
};
struct RestResponseBuilder {
flatbuffers::FlatBufferBuilder &fbb_;
flatbuffers::uoffset_t start_;
void add_rcid(uint64_t rcid) {
fbb_.AddElement<uint64_t>(RestResponse::VT_RCID, rcid, 0);
}
void add_response(flatbuffers::Offset<flatbuffers::String> response) {
fbb_.AddOffset(RestResponse::VT_RESPONSE, response);
}
RestResponseBuilder(flatbuffers::FlatBufferBuilder &_fbb)
: fbb_(_fbb) {
start_ = fbb_.StartTable();
}
RestResponseBuilder &operator=(const RestResponseBuilder &);
flatbuffers::Offset<RestResponse> Finish() {
const auto end = fbb_.EndTable(start_, 2);
auto o = flatbuffers::Offset<RestResponse>(end);
return o;
}
};
inline flatbuffers::Offset<RestResponse> CreateRestResponse(
flatbuffers::FlatBufferBuilder &_fbb,
uint64_t rcid = 0,
flatbuffers::Offset<flatbuffers::String> response = 0) {
RestResponseBuilder builder_(_fbb);
builder_.add_rcid(rcid);
builder_.add_response(response);
return builder_.Finish();
}
inline flatbuffers::Offset<RestResponse> CreateRestResponseDirect(
flatbuffers::FlatBufferBuilder &_fbb,
uint64_t rcid = 0,
const char *response = nullptr) {
return common::context::CreateRestResponse(
_fbb,
rcid,
response ? _fbb.CreateString(response) : 0);
}
inline const common::context::RestResponse *GetRestResponse(const void *buf) {
return flatbuffers::GetRoot<common::context::RestResponse>(buf);
}
inline bool VerifyRestResponseBuffer(
flatbuffers::Verifier &verifier) {
return verifier.VerifyBuffer<common::context::RestResponse>(nullptr);
}
inline void FinishRestResponseBuffer(
flatbuffers::FlatBufferBuilder &fbb,
flatbuffers::Offset<common::context::RestResponse> root) {
fbb.Finish(root);
}
} // namespace context
} // namespace common
#endif // FLATBUFFERS_GENERATED_RESTRESPONSE_COMMON_CONTEXT_H_
- Compiling:
Run the tasks: "compile RestMsg.fbs", "compile RestResponse.fbs" make sure that the new files are generated in the schema folder
- move the files to the src/common folder
\ No newline at end of file
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
* Author: amir * Author: amir
*/ */
#define RAPIDJSON_NAMESPACE msrapidjson
#include <Microservice_App.h> #include <Microservice_App.h>
#include <params/Microservice_Params.h> #include <params/Microservice_Params.h>
#include <handlers/Microservice_RestHandler.h> #include <handlers/Microservice_RestHandler.h>
......
...@@ -14,14 +14,26 @@ ...@@ -14,14 +14,26 @@
#ifndef MICROSERVICE_BASERESPONSE_H #ifndef MICROSERVICE_BASERESPONSE_H
#define MICROSERVICE_BASERESPONSE_H #define MICROSERVICE_BASERESPONSE_H
#include <string> #include <string>
#include <document.h>
// #ifndef MS_RAPIDJSON_NAMESPACE
// #define MS_RAPIDJSON_NAMESPACE ms::rapidjson
// #endif
// #ifndef MS_RAPIDJSON_NAMESPACE_BEGIN
// #define MS_RAPIDJSON_NAMESPACE_BEGIN namespace MS_RAPIDJSON_NAMESPACE {
// #endif
// #ifndef MS_RAPIDJSON_NAMESPACE_END
// #define MS_RAPIDJSON_NAMESPACE_END }
// #endif
#include <rapidjson/document.h>
class cMicroservice_BaseRestResponse { class cMicroservice_BaseRestResponse {
public: public:
cMicroservice_BaseRestResponse(): mb_Success(true){} cMicroservice_BaseRestResponse(): mb_Success(true){}
cMicroservice_BaseRestResponse(bool b_Success, std::string& c_Error) cMicroservice_BaseRestResponse(bool b_Success, std::string& c_Error)
:mb_Success(b_Success), mc_Error(c_Error) {} :mb_Success(b_Success), mc_Error(c_Error) {}
cMicroservice_BaseRestResponse(bool b_Success, std::string& c_Error, rapidjson::Document& c_ObjectNode) cMicroservice_BaseRestResponse(bool b_Success, std::string& c_Error, msrapidjson::Document& c_ObjectNode)
:mb_Success(b_Success), mc_Error(c_Error) { :mb_Success(b_Success), mc_Error(c_Error) {
mc_ObjectNode.Swap(c_ObjectNode); mc_ObjectNode.Swap(c_ObjectNode);
} }
...@@ -46,7 +58,7 @@ public: ...@@ -46,7 +58,7 @@ public:
return mc_Error; return mc_Error;
} }
rapidjson::Document& GetObjectNode() { msrapidjson::Document& GetObjectNode() {
return mc_ObjectNode; return mc_ObjectNode;
} }
...@@ -66,7 +78,7 @@ private: ...@@ -66,7 +78,7 @@ private:
bool mb_Success; bool mb_Success;
std::string mc_Error; std::string mc_Error;
rapidjson::Document mc_ObjectNode; msrapidjson::Document mc_ObjectNode;
}; };
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
* Created on April 13, 2016, 12:21 PM * Created on April 13, 2016, 12:21 PM
*/ */
#define RAPIDJSON_NAMESPACE msrapidjson
#include "Microservice_Client.h" #include "Microservice_Client.h"
#include "impl/Microservice_ICacheClientRedisImpl.h" #include "impl/Microservice_ICacheClientRedisImpl.h"
#include <pplx/pplxtasks.h> #include <pplx/pplxtasks.h>
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
#include <array> #include <array>
#include <map> #include <map>
#include <string.h>
/** /**
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
// Created by amir on 05/04/17. // Created by amir on 05/04/17.
// //
#define RAPIDJSON_NAMESPACE msrapidjson
#include "Microservice_Iface.h" #include "Microservice_Iface.h"
#include <Microservice_BaseRestResponse.h> #include <Microservice_BaseRestResponse.h>
...@@ -24,12 +25,12 @@ void IContainer::SendErrorResp(IResponse* pti_Response,std::string error){ ...@@ -24,12 +25,12 @@ void IContainer::SendErrorResp(IResponse* pti_Response,std::string error){
} }
void IContainer::WriteObjectToResponse(nsMicroservice_Iface::IResponse *pti_Response, void IContainer::WriteObjectToResponse(nsMicroservice_Iface::IResponse *pti_Response,
rapidjson::Document &t_ObjectDoc) { msrapidjson::Document &t_ObjectDoc) {
std::ostringstream c_OutputStream; std::ostringstream c_OutputStream;
if(!t_ObjectDoc.IsNull()) { if(!t_ObjectDoc.IsNull()) {
rapidjson::StringBuffer buffer; msrapidjson::StringBuffer buffer;
rapidjson::Writer<rapidjson::StringBuffer> writer(buffer); msrapidjson::Writer<msrapidjson::StringBuffer> writer(buffer);
t_ObjectDoc.Accept(writer); t_ObjectDoc.Accept(writer);
c_OutputStream << nsMicroservice_Constants::SUCCESS_REST_RESPONSE_TEMPLATE << buffer.GetString() << '}'; c_OutputStream << nsMicroservice_Constants::SUCCESS_REST_RESPONSE_TEMPLATE << buffer.GetString() << '}';
} else { } else {
...@@ -57,7 +58,7 @@ void IContainer::WriteStringToResponse(nsMicroservice_Iface::IResponse *pti_Resp ...@@ -57,7 +58,7 @@ void IContainer::WriteStringToResponse(nsMicroservice_Iface::IResponse *pti_Resp
} }
bool IContainer::ReadObjectFromRequest(nsMicroservice_Iface::IRequest *pti_Request, bool IContainer::ReadObjectFromRequest(nsMicroservice_Iface::IRequest *pti_Request,
rapidjson::Document &t_ObjectDoc) { msrapidjson::Document &t_ObjectDoc) {
const char* pba_Content = pti_Request->GetContent(); const char* pba_Content = pti_Request->GetContent();
if (pba_Content) if (pba_Content)
{ {
......
...@@ -11,7 +11,6 @@ ...@@ -11,7 +11,6 @@
#include <string> #include <string>
#include <map> #include <map>
#include <vector> #include <vector>
#include <document.h>
#include <functional> #include <functional>
#include <chrono> #include <chrono>
...@@ -21,7 +20,9 @@ ...@@ -21,7 +20,9 @@
#include "json.hpp" #include "json.hpp"
#include <boost/function.hpp> #include <boost/function.hpp>
#include <cereal/archives/json.hpp> #include <cereal/archives/json.hpp>
#include <rapidjson/document.h>
#include <atomic> #include <atomic>
//#include <cereal/external/rapidjson/document.h>
class cMicroservice_BaseRestResponse; class cMicroservice_BaseRestResponse;
class cMicroservice_BaseHandler; class cMicroservice_BaseHandler;
...@@ -391,7 +392,7 @@ namespace nsMicroservice_Iface ...@@ -391,7 +392,7 @@ namespace nsMicroservice_Iface
* @param res * @param res
* @param value * @param value
*/ */
virtual void WriteObjectToResponse(nsMicroservice_Iface::IResponse* pti_Response,rapidjson::Document& t_ObjectDoc); virtual void WriteObjectToResponse(nsMicroservice_Iface::IResponse* pti_Response,msrapidjson::Document& t_ObjectDoc);
virtual void WriteObjectToResponse(nsMicroservice_Iface::IResponse* pti_Response,cMicroservice_BaseRestResponse& t_BaseRestResponse); virtual void WriteObjectToResponse(nsMicroservice_Iface::IResponse* pti_Response,cMicroservice_BaseRestResponse& t_BaseRestResponse);
virtual void WriteStringToResponse(nsMicroservice_Iface::IResponse* pti_Response,const char* pba_Doc); virtual void WriteStringToResponse(nsMicroservice_Iface::IResponse* pti_Response,const char* pba_Doc);
...@@ -401,7 +402,7 @@ namespace nsMicroservice_Iface ...@@ -401,7 +402,7 @@ namespace nsMicroservice_Iface
* @param ObjClass * @param ObjClass
* @return * @return
*/ */
virtual bool ReadObjectFromRequest(nsMicroservice_Iface::IRequest* pti_Request,rapidjson::Document& t_ObjectDoc); virtual bool ReadObjectFromRequest(nsMicroservice_Iface::IRequest* pti_Request,msrapidjson::Document& t_ObjectDoc);
/** /**
* reading the object from the request body json * reading the object from the request body json
* @param req * @param req
......
...@@ -13,11 +13,11 @@ ...@@ -13,11 +13,11 @@
#include <vector> #include <vector>
#include <string> #include <string>
#include <common/Microservice_Defines.h> #include <common/Microservice_Defines.h>
#include <stringbuffer.h> //rapidjson string #include <rapidjson/stringbuffer.h> //rapidjson string
#include <writer.h> //rapidjson writer #include <rapidjson/writer.h> //rapidjson writer
#include <common/Microservice_Iface.h> #include <common/Microservice_Iface.h>
typedef rapidjson::Writer<rapidjson::StringBuffer> JsonStringWriter; typedef msrapidjson::Writer<msrapidjson::StringBuffer> JsonStringWriter;
typedef cMicroservice_Enums::eCrudMethod eCrudMethod; typedef cMicroservice_Enums::eCrudMethod eCrudMethod;
/** /**
* *
......
...@@ -10,6 +10,7 @@ namespace common { ...@@ -10,6 +10,7 @@ namespace common {
namespace context { namespace context {
struct RestMsg; struct RestMsg;
struct RestMsgBuilder;
enum CrudMethod { enum CrudMethod {
CrudMethod_Create = 0, CrudMethod_Create = 0,
...@@ -20,8 +21,18 @@ enum CrudMethod { ...@@ -20,8 +21,18 @@ enum CrudMethod {
CrudMethod_MAX = CrudMethod_Delete CrudMethod_MAX = CrudMethod_Delete
}; };
inline const char **EnumNamesCrudMethod() { inline const CrudMethod (&EnumValuesCrudMethod())[4] {
static const char *names[] = { static const CrudMethod values[] = {
CrudMethod_Create,
CrudMethod_Read,
CrudMethod_Update,
CrudMethod_Delete
};
return values;
}
inline const char * const *EnumNamesCrudMethod() {
static const char * const names[5] = {
"Create", "Create",
"Read", "Read",
"Update", "Update",
...@@ -32,12 +43,14 @@ inline const char **EnumNamesCrudMethod() { ...@@ -32,12 +43,14 @@ inline const char **EnumNamesCrudMethod() {
} }
inline const char *EnumNameCrudMethod(CrudMethod e) { inline const char *EnumNameCrudMethod(CrudMethod e) {
const size_t index = static_cast<int>(e); if (flatbuffers::IsOutRange(e, CrudMethod_Create, CrudMethod_Delete)) return "";
const size_t index = static_cast<size_t>(e);
return EnumNamesCrudMethod()[index]; return EnumNamesCrudMethod()[index];
} }
struct RestMsg FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { struct RestMsg FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
enum { typedef RestMsgBuilder Builder;
enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE {
VT_RCID = 4, VT_RCID = 4,
VT_SOURCE = 6, VT_SOURCE = 6,
VT_CRUDMETHOD = 8, VT_CRUDMETHOD = 8,
...@@ -51,8 +64,8 @@ struct RestMsg FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { ...@@ -51,8 +64,8 @@ struct RestMsg FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
const flatbuffers::String *source() const { const flatbuffers::String *source() const {
return GetPointer<const flatbuffers::String *>(VT_SOURCE); return GetPointer<const flatbuffers::String *>(VT_SOURCE);
} }
CrudMethod crudMethod() const { common::context::CrudMethod crudMethod() const {
return static_cast<CrudMethod>(GetField<int8_t>(VT_CRUDMETHOD, 1)); return static_cast<common::context::CrudMethod>(GetField<int8_t>(VT_CRUDMETHOD, 1));
} }
const flatbuffers::String *url() const { const flatbuffers::String *url() const {
return GetPointer<const flatbuffers::String *>(VT_URL); return GetPointer<const flatbuffers::String *>(VT_URL);
...@@ -66,20 +79,21 @@ struct RestMsg FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { ...@@ -66,20 +79,21 @@ struct RestMsg FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
bool Verify(flatbuffers::Verifier &verifier) const { bool Verify(flatbuffers::Verifier &verifier) const {
return VerifyTableStart(verifier) && return VerifyTableStart(verifier) &&
VerifyField<uint64_t>(verifier, VT_RCID) && VerifyField<uint64_t>(verifier, VT_RCID) &&
VerifyField<flatbuffers::uoffset_t>(verifier, VT_SOURCE) && VerifyOffset(verifier, VT_SOURCE) &&
verifier.Verify(source()) && verifier.VerifyString(source()) &&
VerifyField<int8_t>(verifier, VT_CRUDMETHOD) && VerifyField<int8_t>(verifier, VT_CRUDMETHOD) &&
VerifyField<flatbuffers::uoffset_t>(verifier, VT_URL) && VerifyOffset(verifier, VT_URL) &&
verifier.Verify(url()) && verifier.VerifyString(url()) &&
VerifyField<flatbuffers::uoffset_t>(verifier, VT_QUERYSTRING) && VerifyOffset(verifier, VT_QUERYSTRING) &&
verifier.Verify(queryString()) && verifier.VerifyString(queryString()) &&
VerifyField<flatbuffers::uoffset_t>(verifier, VT_CONTENT) && VerifyOffset(verifier, VT_CONTENT) &&
verifier.Verify(content()) && verifier.VerifyString(content()) &&
verifier.EndTable(); verifier.EndTable();
} }
}; };
struct RestMsgBuilder { struct RestMsgBuilder {
typedef RestMsg Table;
flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::FlatBufferBuilder &fbb_;
flatbuffers::uoffset_t start_; flatbuffers::uoffset_t start_;
void add_rcid(uint64_t rcid) { void add_rcid(uint64_t rcid) {
...@@ -88,7 +102,7 @@ struct RestMsgBuilder { ...@@ -88,7 +102,7 @@ struct RestMsgBuilder {
void add_source(flatbuffers::Offset<flatbuffers::String> source) { void add_source(flatbuffers::Offset<flatbuffers::String> source) {
fbb_.AddOffset(RestMsg::VT_SOURCE, source); fbb_.AddOffset(RestMsg::VT_SOURCE, source);
} }
void add_crudMethod(CrudMethod crudMethod) { void add_crudMethod(common::context::CrudMethod crudMethod) {
fbb_.AddElement<int8_t>(RestMsg::VT_CRUDMETHOD, static_cast<int8_t>(crudMethod), 1); fbb_.AddElement<int8_t>(RestMsg::VT_CRUDMETHOD, static_cast<int8_t>(crudMethod), 1);
} }
void add_url(flatbuffers::Offset<flatbuffers::String> url) { void add_url(flatbuffers::Offset<flatbuffers::String> url) {
...@@ -100,13 +114,13 @@ struct RestMsgBuilder { ...@@ -100,13 +114,13 @@ struct RestMsgBuilder {
void add_content(flatbuffers::Offset<flatbuffers::String> content) { void add_content(flatbuffers::Offset<flatbuffers::String> content) {
fbb_.AddOffset(RestMsg::VT_CONTENT, content); fbb_.AddOffset(RestMsg::VT_CONTENT, content);
} }
RestMsgBuilder(flatbuffers::FlatBufferBuilder &_fbb) explicit RestMsgBuilder(flatbuffers::FlatBufferBuilder &_fbb)
: fbb_(_fbb) { : fbb_(_fbb) {
start_ = fbb_.StartTable(); start_ = fbb_.StartTable();
} }
RestMsgBuilder &operator=(const RestMsgBuilder &); RestMsgBuilder &operator=(const RestMsgBuilder &);
flatbuffers::Offset<RestMsg> Finish() { flatbuffers::Offset<RestMsg> Finish() {
const auto end = fbb_.EndTable(start_, 6); const auto end = fbb_.EndTable(start_);
auto o = flatbuffers::Offset<RestMsg>(end); auto o = flatbuffers::Offset<RestMsg>(end);
return o; return o;
} }
...@@ -116,7 +130,7 @@ inline flatbuffers::Offset<RestMsg> CreateRestMsg( ...@@ -116,7 +130,7 @@ inline flatbuffers::Offset<RestMsg> CreateRestMsg(
flatbuffers::FlatBufferBuilder &_fbb, flatbuffers::FlatBufferBuilder &_fbb,
uint64_t rcid = 0, uint64_t rcid = 0,
flatbuffers::Offset<flatbuffers::String> source = 0, flatbuffers::Offset<flatbuffers::String> source = 0,
CrudMethod crudMethod = CrudMethod_Read, common::context::CrudMethod crudMethod = common::context::CrudMethod_Read,
flatbuffers::Offset<flatbuffers::String> url = 0, flatbuffers::Offset<flatbuffers::String> url = 0,
flatbuffers::Offset<flatbuffers::String> queryString = 0, flatbuffers::Offset<flatbuffers::String> queryString = 0,
flatbuffers::Offset<flatbuffers::String> content = 0) { flatbuffers::Offset<flatbuffers::String> content = 0) {
...@@ -134,35 +148,54 @@ inline flatbuffers::Offset<RestMsg> CreateRestMsgDirect( ...@@ -134,35 +148,54 @@ inline flatbuffers::Offset<RestMsg> CreateRestMsgDirect(
flatbuffers::FlatBufferBuilder &_fbb, flatbuffers::FlatBufferBuilder &_fbb,
uint64_t rcid = 0, uint64_t rcid = 0,
const char *source = nullptr, const char *source = nullptr,
CrudMethod crudMethod = CrudMethod_Read, common::context::CrudMethod crudMethod = common::context::CrudMethod_Read,
const char *url = nullptr, const char *url = nullptr,
const char *queryString = nullptr, const char *queryString = nullptr,
const char *content = nullptr) { const char *content = nullptr) {
auto source__ = source ? _fbb.CreateString(source) : 0;
auto url__ = url ? _fbb.CreateString(url) : 0;
auto queryString__ = queryString ? _fbb.CreateString(queryString) : 0;
auto content__ = content ? _fbb.CreateString(content) : 0;
return common::context::CreateRestMsg( return common::context::CreateRestMsg(
_fbb, _fbb,
rcid, rcid,
source ? _fbb.CreateString(source) : 0, source__,
crudMethod, crudMethod,
url ? _fbb.CreateString(url) : 0, url__,
queryString ? _fbb.CreateString(queryString) : 0, queryString__,
content ? _fbb.CreateString(content) : 0); content__);
} }
inline const common::context::RestMsg *GetRestMsg(const void *buf) { inline const common::context::RestMsg *GetRestMsg(const void *buf) {
return flatbuffers::GetRoot<common::context::RestMsg>(buf); return flatbuffers::GetRoot<common::context::RestMsg>(buf);
} }
inline const common::context::RestMsg *GetSizePrefixedRestMsg(const void *buf) {
return flatbuffers::GetSizePrefixedRoot<common::context::RestMsg>(buf);
}
inline bool VerifyRestMsgBuffer( inline bool VerifyRestMsgBuffer(
flatbuffers::Verifier &verifier) { flatbuffers::Verifier &verifier) {
return verifier.VerifyBuffer<common::context::RestMsg>(nullptr); return verifier.VerifyBuffer<common::context::RestMsg>(nullptr);
} }
inline bool VerifySizePrefixedRestMsgBuffer(
flatbuffers::Verifier &verifier) {
return verifier.VerifySizePrefixedBuffer<common::context::RestMsg>(nullptr);
}
inline void FinishRestMsgBuffer( inline void FinishRestMsgBuffer(
flatbuffers::FlatBufferBuilder &fbb, flatbuffers::FlatBufferBuilder &fbb,
flatbuffers::Offset<common::context::RestMsg> root) { flatbuffers::Offset<common::context::RestMsg> root) {
fbb.Finish(root); fbb.Finish(root);
} }
inline void FinishSizePrefixedRestMsgBuffer(
flatbuffers::FlatBufferBuilder &fbb,
flatbuffers::Offset<common::context::RestMsg> root) {
fbb.FinishSizePrefixed(root);
}
} // namespace context } // namespace context
} // namespace common } // namespace common
......
...@@ -10,9 +10,11 @@ namespace common { ...@@ -10,9 +10,11 @@ namespace common {
namespace context { namespace context {
struct RestResponse; struct RestResponse;
struct RestResponseBuilder;
struct RestResponse FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { struct RestResponse FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
enum { typedef RestResponseBuilder Builder;
enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE {
VT_RCID = 4, VT_RCID = 4,
VT_RESPONSE = 6 VT_RESPONSE = 6
}; };
...@@ -25,13 +27,14 @@ struct RestResponse FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { ...@@ -25,13 +27,14 @@ struct RestResponse FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
bool Verify(flatbuffers::Verifier &verifier) const { bool Verify(flatbuffers::Verifier &verifier) const {
return VerifyTableStart(verifier) && return VerifyTableStart(verifier) &&
VerifyField<uint64_t>(verifier, VT_RCID) && VerifyField<uint64_t>(verifier, VT_RCID) &&
VerifyField<flatbuffers::uoffset_t>(verifier, VT_RESPONSE) && VerifyOffset(verifier, VT_RESPONSE) &&
verifier.Verify(response()) && verifier.VerifyString(response()) &&
verifier.EndTable(); verifier.EndTable();
} }
}; };
struct RestResponseBuilder { struct RestResponseBuilder {
typedef RestResponse Table;
flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::FlatBufferBuilder &fbb_;
flatbuffers::uoffset_t start_; flatbuffers::uoffset_t start_;
void add_rcid(uint64_t rcid) { void add_rcid(uint64_t rcid) {
...@@ -40,13 +43,13 @@ struct RestResponseBuilder { ...@@ -40,13 +43,13 @@ struct RestResponseBuilder {
void add_response(flatbuffers::Offset<flatbuffers::String> response) { void add_response(flatbuffers::Offset<flatbuffers::String> response) {
fbb_.AddOffset(RestResponse::VT_RESPONSE, response); fbb_.AddOffset(RestResponse::VT_RESPONSE, response);
} }
RestResponseBuilder(flatbuffers::FlatBufferBuilder &_fbb) explicit RestResponseBuilder(flatbuffers::FlatBufferBuilder &_fbb)
: fbb_(_fbb) { : fbb_(_fbb) {
start_ = fbb_.StartTable(); start_ = fbb_.StartTable();
} }
RestResponseBuilder &operator=(const RestResponseBuilder &); RestResponseBuilder &operator=(const RestResponseBuilder &);
flatbuffers::Offset<RestResponse> Finish() { flatbuffers::Offset<RestResponse> Finish() {
const auto end = fbb_.EndTable(start_, 2); const auto end = fbb_.EndTable(start_);
auto o = flatbuffers::Offset<RestResponse>(end); auto o = flatbuffers::Offset<RestResponse>(end);
return o; return o;
} }
...@@ -66,27 +69,43 @@ inline flatbuffers::Offset<RestResponse> CreateRestResponseDirect( ...@@ -66,27 +69,43 @@ inline flatbuffers::Offset<RestResponse> CreateRestResponseDirect(
flatbuffers::FlatBufferBuilder &_fbb, flatbuffers::FlatBufferBuilder &_fbb,
uint64_t rcid = 0, uint64_t rcid = 0,
const char *response = nullptr) { const char *response = nullptr) {
auto response__ = response ? _fbb.CreateString(response) : 0;
return common::context::CreateRestResponse( return common::context::CreateRestResponse(
_fbb, _fbb,
rcid, rcid,
response ? _fbb.CreateString(response) : 0); response__);
} }
inline const common::context::RestResponse *GetRestResponse(const void *buf) { inline const common::context::RestResponse *GetRestResponse(const void *buf) {
return flatbuffers::GetRoot<common::context::RestResponse>(buf); return flatbuffers::GetRoot<common::context::RestResponse>(buf);
} }
inline const common::context::RestResponse *GetSizePrefixedRestResponse(const void *buf) {
return flatbuffers::GetSizePrefixedRoot<common::context::RestResponse>(buf);
}
inline bool VerifyRestResponseBuffer( inline bool VerifyRestResponseBuffer(
flatbuffers::Verifier &verifier) { flatbuffers::Verifier &verifier) {
return verifier.VerifyBuffer<common::context::RestResponse>(nullptr); return verifier.VerifyBuffer<common::context::RestResponse>(nullptr);
} }
inline bool VerifySizePrefixedRestResponseBuffer(
flatbuffers::Verifier &verifier) {
return verifier.VerifySizePrefixedBuffer<common::context::RestResponse>(nullptr);
}
inline void FinishRestResponseBuffer( inline void FinishRestResponseBuffer(
flatbuffers::FlatBufferBuilder &fbb, flatbuffers::FlatBufferBuilder &fbb,
flatbuffers::Offset<common::context::RestResponse> root) { flatbuffers::Offset<common::context::RestResponse> root) {
fbb.Finish(root); fbb.Finish(root);
} }
inline void FinishSizePrefixedRestResponseBuffer(
flatbuffers::FlatBufferBuilder &fbb,
flatbuffers::Offset<common::context::RestResponse> root) {
fbb.FinishSizePrefixed(root);
}
} // namespace context } // namespace context
} // namespace common } // namespace common
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
* Created on April 13, 2016, 10:58 AM * Created on April 13, 2016, 10:58 AM
*/ */
#define RAPIDJSON_NAMESPACE msrapidjson
#include "Microservice_MonitorHandler.h" #include "Microservice_MonitorHandler.h"
#include "Microservice_BaseRestResponse.h" #include "Microservice_BaseRestResponse.h"
#include "../Microservice_App.h" #include "../Microservice_App.h"
...@@ -80,8 +81,8 @@ void cMicroservice_MonitorHandler::HandleStatistics(cMicroservice_RequestContext ...@@ -80,8 +81,8 @@ void cMicroservice_MonitorHandler::HandleStatistics(cMicroservice_RequestContext
cMicroservice_BaseRestResponse brr; cMicroservice_BaseRestResponse brr;
std::map<std::string, long> metrics_map; std::map<std::string, long> metrics_map;
metrics_map.clear(); metrics_map.clear();
rapidjson::Document& doc = brr.GetObjectNode(); msrapidjson::Document& doc = brr.GetObjectNode();
rapidjson::Document::AllocatorType& rpj_Alloc = doc.GetAllocator(); msrapidjson::Document::AllocatorType& rpj_Alloc = doc.GetAllocator();
doc.SetObject(); doc.SetObject();
/* /*
* getting clients metrics * getting clients metrics
...@@ -89,15 +90,15 @@ void cMicroservice_MonitorHandler::HandleStatistics(cMicroservice_RequestContext ...@@ -89,15 +90,15 @@ void cMicroservice_MonitorHandler::HandleStatistics(cMicroservice_RequestContext
for(auto client : Microservice_App::GetInstance()->GetClientMap()) for(auto client : Microservice_App::GetInstance()->GetClientMap())
{ {
metrics_map.clear(); metrics_map.clear();
rapidjson::Value counters(rapidjson::kObjectType); msrapidjson::Value counters(msrapidjson::kObjectType);
client.second->GetMetrics(metrics_map); client.second->GetMetrics(metrics_map);
if(!metrics_map.empty()) if(!metrics_map.empty())
{ {
for(auto counter : metrics_map) for(auto counter : metrics_map)
{ {
counters.AddMember(rapidjson::StringRef(counter.first.c_str()),rapidjson::Value(counter.second),rpj_Alloc); counters.AddMember(msrapidjson::StringRef(counter.first.c_str()),msrapidjson::Value(counter.second),rpj_Alloc);
} }
doc.AddMember(rapidjson::StringRef(client.first.c_str()),counters,rpj_Alloc); doc.AddMember(msrapidjson::StringRef(client.first.c_str()),counters,rpj_Alloc);
} }
} }
...@@ -106,16 +107,16 @@ void cMicroservice_MonitorHandler::HandleStatistics(cMicroservice_RequestContext ...@@ -106,16 +107,16 @@ void cMicroservice_MonitorHandler::HandleStatistics(cMicroservice_RequestContext
*/ */
metrics_map.clear(); metrics_map.clear();
rapidjson::Value counters(rapidjson::kObjectType); msrapidjson::Value counters(msrapidjson::kObjectType);
Microservice_App::GetInstance()->GetMetricsFactory()->GetMetrics(metrics_map); Microservice_App::GetInstance()->GetMetricsFactory()->GetMetrics(metrics_map);
if(!metrics_map.empty()) if(!metrics_map.empty())
{ {
for(auto counter : metrics_map) for(auto counter : metrics_map)
{ {
counters.AddMember(rapidjson::StringRef(counter.first.c_str()),rapidjson::Value(counter.second),rpj_Alloc); counters.AddMember(msrapidjson::StringRef(counter.first.c_str()),msrapidjson::Value(counter.second),rpj_Alloc);
} }
doc.AddMember(rapidjson::StringRef("handlers"),counters,rpj_Alloc); doc.AddMember(msrapidjson::StringRef("handlers"),counters,rpj_Alloc);
} }
// for (auto p_handler : handlers_) // for (auto p_handler : handlers_)
// { // {
...@@ -126,10 +127,10 @@ void cMicroservice_MonitorHandler::HandleStatistics(cMicroservice_RequestContext ...@@ -126,10 +127,10 @@ void cMicroservice_MonitorHandler::HandleStatistics(cMicroservice_RequestContext
void cMicroservice_MonitorHandler::HandleReadLogLevel(cMicroservice_RequestContext *p_reqCtx) { void cMicroservice_MonitorHandler::HandleReadLogLevel(cMicroservice_RequestContext *p_reqCtx) {
auto level = Microservice_App::GetInstance()->GetLogger()->getLevel(); auto level = Microservice_App::GetInstance()->GetLogger()->getLevel();
rapidjson::Document rpj_Doc; msrapidjson::Document rpj_Doc;
rapidjson::Document::AllocatorType& rpj_Alloc = rpj_Doc.GetAllocator(); msrapidjson::Document::AllocatorType& rpj_Alloc = rpj_Doc.GetAllocator();
rpj_Doc.SetObject(); rpj_Doc.SetObject();
rpj_Doc.AddMember(rapidjson::StringRef(LEVEL),rapidjson::StringRef(_microservice_LogLevels[(int)level].c_str()),rpj_Alloc); rpj_Doc.AddMember(msrapidjson::StringRef(LEVEL),msrapidjson::StringRef(_microservice_LogLevels[(int)level].c_str()),rpj_Alloc);
WriteObjectToResponse(p_reqCtx,rpj_Doc); WriteObjectToResponse(p_reqCtx,rpj_Doc);
} }
...@@ -151,7 +152,7 @@ void cMicroservice_MonitorHandler::HandleSetLogLevel(cMicroservice_RequestContex ...@@ -151,7 +152,7 @@ void cMicroservice_MonitorHandler::HandleSetLogLevel(cMicroservice_RequestContex
} else } else
brr.SetError(FAILED_RESOLVE_LOG_LEVEL); brr.SetError(FAILED_RESOLVE_LOG_LEVEL);
} else { } else {
rapidjson::Document doc; msrapidjson::Document doc;
if (ReadObjectFromRequest(p_reqCtx, doc)) { if (ReadObjectFromRequest(p_reqCtx, doc)) {
auto &levelNode = doc[LEVEL]; auto &levelNode = doc[LEVEL];
if (levelNode.IsString()) { if (levelNode.IsString()) {
......
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
cMicroservice_RMQHandler::cMicroservice_RMQHandler(std::string apiContextPath,Microservice_RestHandler* pc_Handler): cMicroservice_RMQHandler::cMicroservice_RMQHandler(std::string apiContextPath,Microservice_RestHandler* pc_Handler):
mpc_Handler(pc_Handler) mpc_Handler(pc_Handler)
{ {
mpc_Buffer = new rapidjson::StringBuffer(0,nsMicroservice_Constants::MAX_JSON_BUFFER); mpc_Buffer = new msrapidjson::StringBuffer(0,nsMicroservice_Constants::MAX_JSON_BUFFER);
mpc_Writer = new JsonStringWriter(*mpc_Buffer); mpc_Writer = new JsonStringWriter(*mpc_Buffer);
mpc_RequestContext = new cMicroservice_RequestContext(this, mpc_RequestContext = new cMicroservice_RequestContext(this,
//mpc_Writer, //mpc_Writer,
...@@ -174,14 +174,14 @@ void cMicroservice_RMQHandler::SendErrorResp(nsMicroservice_Iface::IResponse* pt ...@@ -174,14 +174,14 @@ void cMicroservice_RMQHandler::SendErrorResp(nsMicroservice_Iface::IResponse* pt
// pti_Response->Send(mba_ErrorBuff); // pti_Response->Send(mba_ErrorBuff);
} }
void cMicroservice_RMQHandler::WriteObjectToResponse(nsMicroservice_Iface::IResponse* pti_Response,rapidjson::Document& t_ObjectDoc) void cMicroservice_RMQHandler::WriteObjectToResponse(nsMicroservice_Iface::IResponse* pti_Response,msrapidjson::Document& t_ObjectDoc)
{ {
std::ostringstream c_OutputStream; std::ostringstream c_OutputStream;
if(!t_ObjectDoc.IsNull()) { if(!t_ObjectDoc.IsNull()) {
rapidjson::StringBuffer buffer; msrapidjson::StringBuffer buffer;
rapidjson::Writer<rapidjson::StringBuffer> writer(buffer); msrapidjson::Writer<msrapidjson::StringBuffer> writer(buffer);
t_ObjectDoc.Accept(writer); t_ObjectDoc.Accept(writer);
c_OutputStream << nsMicroservice_Constants::SUCCESS_REST_RESPONSE_TEMPLATE << buffer.GetString() << '}'; c_OutputStream << nsMicroservice_Constants::SUCCESS_REST_RESPONSE_TEMPLATE << buffer.GetString() << '}';
} else { } else {
...@@ -214,7 +214,7 @@ void cMicroservice_RMQHandler::WriteStringToResponse(nsMicroservice_Iface::IResp ...@@ -214,7 +214,7 @@ void cMicroservice_RMQHandler::WriteStringToResponse(nsMicroservice_Iface::IResp
pti_Response->Send(c_OutputStream.str().c_str()); pti_Response->Send(c_OutputStream.str().c_str());
} }
bool cMicroservice_RMQHandler::ReadObjectFromRequest(nsMicroservice_Iface::IRequest* pti_Request,rapidjson::Document& t_ObjectDoc) bool cMicroservice_RMQHandler::ReadObjectFromRequest(nsMicroservice_Iface::IRequest* pti_Request,msrapidjson::Document& t_ObjectDoc)
{ {
const char* pba_Content = pti_Request->GetContent(); const char* pba_Content = pti_Request->GetContent();
if (pba_Content) if (pba_Content)
......
// //
// Created by amir on 14/11/16. // Created by amir on 14/11/16.
// //
#define RAPIDJSON_NAMESPACE msrapidjson
#include "Microservice_Reactor.h" #include "Microservice_Reactor.h"
MSRetStat Microservice_Reactor::Delegate(std::string& key, nsMicroservice_Iface::IContext* p_Ctx) { MSRetStat Microservice_Reactor::Delegate(std::string& key, nsMicroservice_Iface::IContext* p_Ctx) {
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
#ifndef MICROSERVICE_BASEHANDLER_H_ #ifndef MICROSERVICE_BASEHANDLER_H_
#define MICROSERVICE_BASEHANDLER_H_ #define MICROSERVICE_BASEHANDLER_H_
#include <writer.h> //rapidjson writer #include <rapidjson/writer.h> //rapidjson writer
#include <common/Microservice_RequestContext.h> #include <common/Microservice_RequestContext.h>
#include "common/json.hpp" #include "common/json.hpp"
...@@ -39,7 +39,7 @@ public: ...@@ -39,7 +39,7 @@ public:
pc_reqCtx->mpti_Container->SendErrorResp(pc_reqCtx->mpti_Response, error); pc_reqCtx->mpti_Container->SendErrorResp(pc_reqCtx->mpti_Response, error);
} }
void WriteObjectToResponse(cMicroservice_RequestContext* pc_reqCtx, rapidjson::Document& t_ObjectDoc) void WriteObjectToResponse(cMicroservice_RequestContext* pc_reqCtx, msrapidjson::Document& t_ObjectDoc)
{ {
pc_reqCtx->mpti_Container->WriteObjectToResponse(pc_reqCtx->mpti_Response, t_ObjectDoc); pc_reqCtx->mpti_Container->WriteObjectToResponse(pc_reqCtx->mpti_Response, t_ObjectDoc);
} }
...@@ -54,7 +54,7 @@ public: ...@@ -54,7 +54,7 @@ public:
pc_reqCtx->mpti_Container->WriteStringToResponse(pc_reqCtx->mpti_Response, pba_Doc); pc_reqCtx->mpti_Container->WriteStringToResponse(pc_reqCtx->mpti_Response, pba_Doc);
} }
bool ReadObjectFromRequest(cMicroservice_RequestContext* pc_reqCtx, rapidjson::Document& t_ObjectDoc) bool ReadObjectFromRequest(cMicroservice_RequestContext* pc_reqCtx, msrapidjson::Document& t_ObjectDoc)
{ {
return pc_reqCtx->mpti_Container->ReadObjectFromRequest(pc_reqCtx->mpti_Request,t_ObjectDoc); return pc_reqCtx->mpti_Container->ReadObjectFromRequest(pc_reqCtx->mpti_Request,t_ObjectDoc);
} }
......
// //
// Created by amir on 19/04/17. // Created by amir on 19/04/17.
// //
#define RAPIDJSON_NAMESPACE msrapidjson
#include <Microservice_BaseRestResponse.h> #include <Microservice_BaseRestResponse.h>
#include "Microservice_TestHandler.h" #include "Microservice_TestHandler.h"
...@@ -17,12 +17,12 @@ void Microservice_TestHandler::DoRead(cMicroservice_RequestContext *pc_reqCtx) { ...@@ -17,12 +17,12 @@ void Microservice_TestHandler::DoRead(cMicroservice_RequestContext *pc_reqCtx) {
* return all test and names * return all test and names
*/ */
if (!testsMap_.empty()){ if (!testsMap_.empty()){
rapidjson::Document& doc = brr.GetObjectNode(); msrapidjson::Document& doc = brr.GetObjectNode();
rapidjson::Document::AllocatorType& rpj_Alloc = doc.GetAllocator(); msrapidjson::Document::AllocatorType& rpj_Alloc = doc.GetAllocator();
doc.SetArray(); doc.SetArray();
for (auto entry : testsMap_){ for (auto entry : testsMap_){
doc.PushBack(rapidjson::StringRef(entry.first.c_str()),rpj_Alloc); doc.PushBack(msrapidjson::StringRef(entry.first.c_str()),rpj_Alloc);
} }
} else { } else {
brr.SetError("NO TESTS FOR YOU (;-)"); brr.SetError("NO TESTS FOR YOU (;-)");
...@@ -36,10 +36,10 @@ void Microservice_TestHandler::DoRead(cMicroservice_RequestContext *pc_reqCtx) { ...@@ -36,10 +36,10 @@ void Microservice_TestHandler::DoRead(cMicroservice_RequestContext *pc_reqCtx) {
std::stringstream ss; std::stringstream ss;
MSRetStat retStat = funcIterator->second(ss,pc_reqCtx->mc_QueryParameters); MSRetStat retStat = funcIterator->second(ss,pc_reqCtx->mc_QueryParameters);
if (retStat.IsSuccess()){ if (retStat.IsSuccess()){
rapidjson::Document& doc = brr.GetObjectNode(); msrapidjson::Document& doc = brr.GetObjectNode();
rapidjson::Document::AllocatorType& rpj_Alloc = doc.GetAllocator(); msrapidjson::Document::AllocatorType& rpj_Alloc = doc.GetAllocator();
doc.SetObject(); doc.SetObject();
doc.AddMember(rapidjson::StringRef(funcIterator->first.c_str()),rapidjson::StringRef(ss.str().c_str()),rpj_Alloc); doc.AddMember(msrapidjson::StringRef(funcIterator->first.c_str()),msrapidjson::StringRef(ss.str().c_str()),rpj_Alloc);
} else { } else {
ss.clear(); ss.clear();
ss << "Test Failed: " << retStat.GetError().c_str(); ss << "Test Failed: " << retStat.GetError().c_str();
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
* Created on May 9, 2016, 10:43 AM * Created on May 9, 2016, 10:43 AM
*/ */
#define RAPIDJSON_NAMESPACE msrapidjson
#include "MSIMetricsFactoryStdImpl.h" #include "MSIMetricsFactoryStdImpl.h"
MSIMetricsFactoryStdImpl::MSIMetricsFactoryStdImpl() { MSIMetricsFactoryStdImpl::MSIMetricsFactoryStdImpl() {
......
...@@ -11,8 +11,9 @@ ...@@ -11,8 +11,9 @@
* Created on May 5, 2016, 1:59 PM * Created on May 5, 2016, 1:59 PM
*/ */
#define RAPIDJSON_NAMESPACE msrapidjson
#include "Microservice_ICacheClientRedisImpl.h" #include "Microservice_ICacheClientRedisImpl.h"
#include <hiredis.h> #include <hiredis/hiredis.h>
#define M_FREE_RESPONSE_OR_ERROR(resp) { if(resp){ freeReplyObject(resp); } else { t_stat.AddFreeGeneralErrorCode((const char*)mpt_redisContext->errstr); } } #define M_FREE_RESPONSE_OR_ERROR(resp) { if(resp){ freeReplyObject(resp); } else { t_stat.AddFreeGeneralErrorCode((const char*)mpt_redisContext->errstr); } }
#define M_FREE_RESPONSE(resp) { if(resp){ freeReplyObject(resp); } } #define M_FREE_RESPONSE(resp) { if(resp){ freeReplyObject(resp); } }
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
* Created on May 5, 2016, 11:16 AM * Created on May 5, 2016, 11:16 AM
*/ */
#define RAPIDJSON_NAMESPACE msrapidjson
#include "Microservice_IConfigurationConfigPropImpl.h" #include "Microservice_IConfigurationConfigPropImpl.h"
#include <fstream> #include <fstream>
......
#define RAPIDJSON_NAMESPACE msrapidjson
#include "Microservice_ILoggerSpdlogImpl.h" #include "Microservice_ILoggerSpdlogImpl.h"
#include <spdlog/sinks/stdout_color_sinks.h> #include <spdlog/sinks/stdout_color_sinks.h>
#include <stdarg.h>
thread_local char ba_LogBuffer[nsMicroservice_Constants::MAX_LOGEER_BUFF_LENGTH]; thread_local char ba_LogBuffer[nsMicroservice_Constants::MAX_LOGEER_BUFF_LENGTH];
......
#define RAPIDJSON_NAMESPACE msrapidjson
#include "MSICommandClientEvppImpl.h" #include "MSICommandClientEvppImpl.h"
#include <utils/EvppRequest.h> #include <utils/EvppRequest.h>
#include <evpp/httpc/conn.h> #include <evpp/httpc/conn.h>
...@@ -5,7 +7,7 @@ ...@@ -5,7 +7,7 @@
#include <mutex> #include <mutex>
#include <condition_variable> #include <condition_variable>
#include <common/Microservice_RestResponse.h> #include <common/Microservice_RestResponse.h>
#include <error/en.h> #include <rapidjson/error/en.h>
static const char *COMMAND_TIMEOUT_PARAM = "command.timeout"; static const char *COMMAND_TIMEOUT_PARAM = "command.timeout";
static const double DEFAULT_COMMAND_TIMEOUT = 5.0; static const double DEFAULT_COMMAND_TIMEOUT = 5.0;
...@@ -314,7 +316,7 @@ void MSICommandClientEvppImpl::handleRequestFailed(const ICommandClient::HttpCom ...@@ -314,7 +316,7 @@ void MSICommandClientEvppImpl::handleRequestFailed(const ICommandClient::HttpCom
void MSICommandClientEvppImpl::handleRequestSuccess(const ICommandClient::HttpCommandDataPtr &cmdDataPtr, void MSICommandClientEvppImpl::handleRequestSuccess(const ICommandClient::HttpCommandDataPtr &cmdDataPtr,
const std::shared_ptr<evpp::httpc::EvppResponse> &responsePtr) const std::shared_ptr<evpp::httpc::EvppResponse> &responsePtr)
{ {
rapidjson::Document& doc = cmdDataPtr->p_response->GetObjectNode(); msrapidjson::Document& doc = cmdDataPtr->p_response->GetObjectNode();
const char* respBody = responsePtr->body().data(); const char* respBody = responsePtr->body().data();
if(!doc.Parse<0>(respBody).HasParseError()) { if(!doc.Parse<0>(respBody).HasParseError()) {
cmdDataPtr->p_command_counters->succeed++; cmdDataPtr->p_command_counters->succeed++;
...@@ -325,7 +327,7 @@ void MSICommandClientEvppImpl::handleRequestSuccess(const ICommandClient::HttpCo ...@@ -325,7 +327,7 @@ void MSICommandClientEvppImpl::handleRequestSuccess(const ICommandClient::HttpCo
p_rr->setCommandId(cmdDataPtr->p_cmd_params->GetCommandId()); p_rr->setCommandId(cmdDataPtr->p_cmd_params->GetCommandId());
} }
} else { } else {
handleRequestFailed(cmdDataPtr,rapidjson::GetParseError_En(doc.GetParseError())); handleRequestFailed(cmdDataPtr,msrapidjson::GetParseError_En(doc.GetParseError()));
} }
} }
...@@ -338,7 +340,7 @@ void MSICommandClientEvppImpl::handleAsyncRequestFailed(const ICommandClient::Ha ...@@ -338,7 +340,7 @@ void MSICommandClientEvppImpl::handleAsyncRequestFailed(const ICommandClient::Ha
void MSICommandClientEvppImpl::handleAsyncRequestSuccess(const ICommandClient::HandleAsyncCommandDataPtr &asyncCmdDataPtr,const std::shared_ptr<evpp::httpc::EvppResponse> &responsePtr){ void MSICommandClientEvppImpl::handleAsyncRequestSuccess(const ICommandClient::HandleAsyncCommandDataPtr &asyncCmdDataPtr,const std::shared_ptr<evpp::httpc::EvppResponse> &responsePtr){
Microservice_RestResponse brr; Microservice_RestResponse brr;
rapidjson::Document& doc = brr.GetObjectNode(); msrapidjson::Document& doc = brr.GetObjectNode();
/** /**
* check for returned body * check for returned body
* and parse it * and parse it
...@@ -352,7 +354,7 @@ void MSICommandClientEvppImpl::handleAsyncRequestSuccess(const ICommandClient::H ...@@ -352,7 +354,7 @@ void MSICommandClientEvppImpl::handleAsyncRequestSuccess(const ICommandClient::H
brr.setCommandId(asyncCmdDataPtr->p_cmd_params->GetCommandId()); brr.setCommandId(asyncCmdDataPtr->p_cmd_params->GetCommandId());
asyncCmdDataPtr->crudHandler(&brr); asyncCmdDataPtr->crudHandler(&brr);
} else { } else {
handleAsyncRequestFailed(asyncCmdDataPtr,rapidjson::GetParseError_En(doc.GetParseError())); handleAsyncRequestFailed(asyncCmdDataPtr,msrapidjson::GetParseError_En(doc.GetParseError()));
} }
} else { } else {
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
// Created by amir on 05/04/17. // Created by amir on 05/04/17.
// //
#define RAPIDJSON_NAMESPACE msrapidjson
#include <Microservice_App.h> #include <Microservice_App.h>
#include <flatbuffers/flatbuffers.h> #include <flatbuffers/flatbuffers.h>
#include <thread> #include <thread>
...@@ -11,7 +12,7 @@ ...@@ -11,7 +12,7 @@
#include <utils/CommonUtils.h> #include <utils/CommonUtils.h>
#include <impl/Microservice_ICacheClientPocoImpl.h> #include <impl/Microservice_ICacheClientPocoImpl.h>
#include <common/Microservice_RestResponse.h> #include <common/Microservice_RestResponse.h>
#include <error/en.h> #include <rapidjson/error/en.h>
#include "MSICommandClientZmqImpl.h" #include "MSICommandClientZmqImpl.h"
...@@ -67,7 +68,7 @@ void MSICommandClientZmqImpl::HandleCommandAndCallback(ICommandClient::HttpComma ...@@ -67,7 +68,7 @@ void MSICommandClientZmqImpl::HandleCommandAndCallback(ICommandClient::HttpComma
*/ */
cmdDataPtr->p_retstat->Reset(); cmdDataPtr->p_retstat->Reset();
cmdDataPtr->p_response->Reset(); cmdDataPtr->p_response->Reset();
rapidjson::Document& doc = cmdDataPtr->p_response->GetObjectNode(); msrapidjson::Document& doc = cmdDataPtr->p_response->GetObjectNode();
if(!doc.Parse<0>(p_response).HasParseError()) { if(!doc.Parse<0>(p_response).HasParseError()) {
cmdDataPtr->p_command_counters->succeed++; cmdDataPtr->p_command_counters->succeed++;
...@@ -76,7 +77,7 @@ void MSICommandClientZmqImpl::HandleCommandAndCallback(ICommandClient::HttpComma ...@@ -76,7 +77,7 @@ void MSICommandClientZmqImpl::HandleCommandAndCallback(ICommandClient::HttpComma
this->DelegateRestResponse(cmdDataPtr->p_response, cmndId); this->DelegateRestResponse(cmdDataPtr->p_response, cmndId);
} else { } else {
cmdDataPtr->p_retstat->SetError(rapidjson::GetParseError_En(doc.GetParseError())); cmdDataPtr->p_retstat->SetError(msrapidjson::GetParseError_En(doc.GetParseError()));
cmdDataPtr->p_command_counters->failed++; cmdDataPtr->p_command_counters->failed++;
cmdDataPtr->p_response->SetError(cmdDataPtr->p_retstat->GetError()); cmdDataPtr->p_response->SetError(cmdDataPtr->p_retstat->GetError());
} }
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
// Created by amir on 18/12/16. // Created by amir on 18/12/16.
// //
#define RAPIDJSON_NAMESPACE msrapidjson
#include <Microservice_App.h> #include <Microservice_App.h>
#include <zmqpp/message.hpp> #include <zmqpp/message.hpp>
#include "MSIPubSubClientImpl.h" #include "MSIPubSubClientImpl.h"
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
// //
#include <zmqpp/message.hpp> #include <zmqpp/message.hpp>
#define RAPIDJSON_NAMESPACE msrapidjson
#include <Microservice_App.h> #include <Microservice_App.h>
#include "MSZMQClientImpl.h" #include "MSZMQClientImpl.h"
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
// Created by amir on 15/11/16. // Created by amir on 15/11/16.
// //
#define RAPIDJSON_NAMESPACE msrapidjson
#include <common/Microservice_MsgQContext.h> #include <common/Microservice_MsgQContext.h>
#include "Microservice_IMsgQueueServerZmqImpl.h" #include "Microservice_IMsgQueueServerZmqImpl.h"
#include <handlers/Microservice_Reactor.h> #include <handlers/Microservice_Reactor.h>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment