void berkeleydb_store<Object>::key_lpid_to_char(const timestamp& tmstmp, const long lp_id_, std::vector<char>& ret) { ret = std::vector<char>(60, '0'); /* convert object id to char[20] */ ret[59] = '\0'; std::stringstream obj_id_ss_; obj_id_ss_ << tmstmp.id(); std::string obj_id_str_ = obj_id_ss_.str(); for (int i = 0; i < obj_id_str_.size(); ++i) { ret[58 - i] = obj_id_str_[obj_id_str_.size() - 1 - i]; } /* convert time to char[20] */ ret[39] = '\0'; std::stringstream time_ss_; time_ss_ << tmstmp.time(); std::string time_str = time_ss_.str(); for (int i = 0; i < time_str.size(); ++i) { ret[38 - i] = time_str[time_str.size() - 1 - i]; } /* convert lp id to char[20] */ ret[19] = '\0'; std::stringstream lp_id_ss_; lp_id_ss_ << lp_id_; std::string lp_id_str_ = lp_id_ss_.str(); for (int i = 0; i < lp_id_str_.size(); ++i) { ret[18 - i] = lp_id_str_[lp_id_str_.size() - 1 - i]; } };
void redis_store<Object>::get(const timestamp& key, const long lp_id, obj_ptr& ret) { boost::lock_guard<boost::mutex> guard(get_mutex_); std::stringstream lpid_ss_; lpid_ss_ << lp_id; std::stringstream time_ss_; time_ss_ << key.time(); std::string command = "ZRANGEBYSCORE " + type_rank_ + lpid_ss_.str() + " " + time_ss_.str() + " " + time_ss_.str(); reply = (redisReply*) redisCommand(context, command.c_str()); if (reply->type == REDIS_REPLY_ARRAY) { Object obj; for (int i = 0; i < reply->elements; ++i) { std::stringstream ss; ss << reply->element[i]->str; boost::archive::text_iarchive iar(ss); iar >> obj; if (obj.id() == key.id()) break; } ret = boost::make_shared<Object>(obj); }
void redis_store<Object>::put(const timestamp& key, const long lp_id, const Object& value) { boost::lock_guard<boost::mutex> guard(put_mutex_); /* serialize value */ std::stringstream ss; boost::archive::text_oarchive ar(ss); ar << value; std::string binary = ss.str(); /* put event */ std::stringstream lpid_ss_; lpid_ss_ << lp_id; std::stringstream time_ss_; time_ss_ << key.time(); std::string command = "ZADD " + type_rank_ + lpid_ss_.str() + " " + time_ss_.str() + " %b"; reply = (redisReply*) redisCommand(context, command.c_str(), binary.c_str(), binary.size()); freeReplyObject(reply); };
int logger_impl::format_message( char* buf, size_t size, bool add_new_line, bool a_show_ident, bool a_show_location, const timestamp& a_tv, const log_msg_info& info, const char* fmt, va_list args ) throw (badarg_error) { int len = a_tv.write(m_log_mgr->timestamp_type(), buf, size); const char* end = buf + size - 2; const char* q = logger::log_level_to_str(info.level()); char* p = buf + len; *p++ = '|'; const char* e = p + 7; while (*q) *p++ = *q++; while (p < e) *p++ = ' '; *p++ = '|'; if (a_show_ident) { q = info.get_logger().ident().c_str(); while (*q) *p++ = *q++; *p++ = '|'; } int n = vsnprintf(p, end - p, fmt, args); if (n < 0) throw badarg_error("Error formatting string:", fmt, ' ', (info.has_src_location() ? info.src_location() : "")); p += n; if (info.has_src_location() && a_show_location) { q = info.src_location(); while (*q && p != end) *p++ = *q++; if (add_new_line) *p++ = '\n'; } else if (add_new_line) *p++ = '\n'; *p = '\0'; len = p - buf; BOOST_ASSERT(len <= (int)size); return len; }
void scalar_base::put_(timestamp x) { atom_.u.as_timestamp = x.milliseconds(); atom_.type = PN_TIMESTAMP; }
inline duration operator-(timestamp t0, timestamp t1) { return duration(t0.ms() - t1.ms()); }
inline timestamp operator+(timestamp ts, duration d) { return timestamp(ts.ms() + d.ms()); }
inline bool operator<(timestamp x, timestamp y) { return x.ms() < y.ms(); }
///@name Comparison and arithmetic operators ///@{ inline bool operator==(timestamp x, timestamp y) { return x.ms() == y.ms(); }
void message::expiry_time(timestamp t) { pn_message_set_expiry_time(pn_msg(), t.milliseconds()); }
inline bool operator != (timestamp l, timestamp r) noexcept { return l.microseconds_since_epoc () != r.microseconds_since_epoc (); }
encoder operator<<(encoder e, timestamp x) { return insert(e, e.pn_object(), x.ms(), pn_data_put_timestamp); }
void message::creation_time(timestamp t) { pn_message_set_creation_time(pn_msg(), t.milliseconds()); }
timestamp operator-(const timestamp& ts) const { __hogl_ts_wrap_assert(to_nsec() > ts.to_nsec()); return timestamp(to_nsec() - ts.to_nsec()); }
inline double time_diff (timestamp high, timestamp low) noexcept { auto diff = high.microseconds_since_epoc () - low.microseconds_since_epoc (); return static_cast<double> (diff) / timestamp::microseconds_per_second; }
timestamp operator+(const timestamp& ts) const { return timestamp(to_nsec() + ts.to_nsec()); }
timestamp::timestamp( const timestamp& rhs ) : _tick( rhs.tick() ) { }