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];
  }
};
示例#2
0
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);
  }
示例#3
0
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);
};
示例#4
0
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; }
示例#6
0
inline duration operator-(timestamp t0, timestamp t1) { return duration(t0.ms() - t1.ms()); }
示例#7
0
inline timestamp operator+(timestamp ts, duration d) { return timestamp(ts.ms() + d.ms()); }
示例#8
0
inline bool operator<(timestamp x, timestamp y) { return x.ms() < y.ms(); }
示例#9
0
///@name Comparison and arithmetic operators
///@{
inline bool operator==(timestamp x, timestamp y) { return x.ms() == y.ms(); }
示例#10
0
void message::expiry_time(timestamp t) {
    pn_message_set_expiry_time(pn_msg(), t.milliseconds());
}
示例#11
0
inline bool operator != (timestamp l, timestamp r) noexcept
{
	return l.microseconds_since_epoc () != r.microseconds_since_epoc ();
}
示例#12
0
encoder operator<<(encoder e, timestamp x) { return insert(e, e.pn_object(), x.ms(), pn_data_put_timestamp); }
示例#13
0
void message::creation_time(timestamp t) {
    pn_message_set_creation_time(pn_msg(), t.milliseconds());
}
示例#14
0
	timestamp operator-(const timestamp& ts) const
	{
		__hogl_ts_wrap_assert(to_nsec() > ts.to_nsec());
		return timestamp(to_nsec() - ts.to_nsec());
	}
示例#15
0
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;
}
示例#16
0
	timestamp operator+(const timestamp& ts) const
	{
		return timestamp(to_nsec() + ts.to_nsec());
	}
示例#17
0
 timestamp::timestamp( const timestamp& rhs )
   : _tick( rhs.tick() )
 {
 }