CMS 3D CMS Logo

List of all members | Classes | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | Friends
QueryAttrHandler Class Reference
Inheritance diagram for QueryAttrHandler:

Classes

struct  QueryAttrState
 

Public Member Functions

QueryAttrHandleroperator= (const QueryAttrHandler &)=delete
 
 QueryAttrHandler ()=delete
 
 QueryAttrHandler (const QueryAttrHandler &)=delete
 
 QueryAttrHandler (const std::string &url)
 
 ~QueryAttrHandler () override=default
 

Static Public Member Functions

static XrdCl::XRootDStatus query (const std::string &url, const std::string &attr, std::chrono::milliseconds timeout, std::string &result)
 

Private Member Functions

void HandleResponse (XrdCl::XRootDStatus *status, XrdCl::AnyObject *response) override
 

Private Attributes

XrdCl::FileSystem m_fs
 
std::weak_ptr< QueryAttrStatem_state
 

Friends

std::unique_ptr< QueryAttrHandlerstd::make_unique ()
 

Detailed Description

A handler for querying a XrdCl::FileSystem object which is safe to be invoked from an XrdCl callback (that is, we don't need an available callback thread to timeout).

Definition at line 82 of file XrdSource.cc.

Constructor & Destructor Documentation

◆ QueryAttrHandler() [1/3]

QueryAttrHandler::QueryAttrHandler ( )
delete

◆ ~QueryAttrHandler()

QueryAttrHandler::~QueryAttrHandler ( )
overridedefault

◆ QueryAttrHandler() [2/3]

QueryAttrHandler::QueryAttrHandler ( const QueryAttrHandler )
delete

◆ QueryAttrHandler() [3/3]

QueryAttrHandler::QueryAttrHandler ( const std::string &  url)
inline

Definition at line 91 of file XrdSource.cc.

Member Function Documentation

◆ HandleResponse()

void QueryAttrHandler::HandleResponse ( XrdCl::XRootDStatus *  status,
XrdCl::AnyObject *  response 
)
inlineoverrideprivate

Definition at line 127 of file XrdSource.cc.

References uploadConditions::response, and mps_update::status.

127  {
128  // NOTE: we own the status and response pointers.
129  std::unique_ptr<XrdCl::AnyObject> response_mgr;
130  response_mgr.reset(response);
131 
132  // Lock our state information then dispose of our object.
133  auto l_state = m_state.lock();
134  delete this;
135  if (!l_state) {
136  return;
137  }
138 
139  // On function exit, notify any waiting threads.
140  std::unique_ptr<char, std::function<void(char *)>> notify_guard(nullptr,
141  [&](char *) { l_state->m_condvar.notify_all(); });
142 
143  {
144  // On exit from the block, make sure m_status is set; it needs to be set before we notify threads.
145  std::unique_ptr<char, std::function<void(char *)>> exit_guard(nullptr, [&](char *) {
146  if (!l_state->m_status)
147  l_state->m_status = std::make_unique<XrdCl::XRootDStatus>(XrdCl::stError, XrdCl::errInternal);
148  });
149  if (!status) {
150  return;
151  }
152  if (status->IsOK()) {
153  if (!response) {
154  return;
155  }
156  XrdCl::Buffer *buf_ptr;
157  response->Get(buf_ptr);
158  // AnyObject::Set lacks specialization for nullptr
159  response->Set(static_cast<int *>(nullptr));
160  l_state->m_response.reset(buf_ptr);
161  }
162  l_state->m_status.reset(status);
163  }
164  }
std::weak_ptr< QueryAttrState > m_state
Definition: XrdSource.cc:179

◆ operator=()

QueryAttrHandler& QueryAttrHandler::operator= ( const QueryAttrHandler )
delete

◆ query()

static XrdCl::XRootDStatus QueryAttrHandler::query ( const std::string &  url,
const std::string &  attr,
std::chrono::milliseconds  timeout,
std::string &  result 
)
inlinestatic

Definition at line 93 of file XrdSource.cc.

References helper::Config, mps_fire::result, and relmon_authenticated_wget::url.

Referenced by XrdAdaptor::Source::getXrootdSiteFromURL().

96  {
97  auto handler = std::make_unique<QueryAttrHandler>(url);
98  auto l_state = std::make_shared<QueryAttrState>();
99  handler->m_state = l_state;
100  XrdCl::Buffer arg(attr.size());
101  arg.FromString(attr);
102 
103  XrdCl::XRootDStatus st = handler->m_fs.Query(XrdCl::QueryCode::Config, arg, handler.get());
104  if (!st.IsOK()) {
105  return st;
106  }
107 
108  // Successfully registered the callback; it will always delete itself, so we shouldn't.
109  handler.release();
110 
111  std::unique_lock<std::mutex> guard(l_state->m_mutex);
112  // Wait until some status is available or a timeout.
113  l_state->m_condvar.wait_for(guard, timeout, [&] { return l_state->m_status.get(); });
114 
115  if (l_state->m_status) {
116  if (l_state->m_status->IsOK()) {
117  result = l_state->m_response->ToString();
118  }
119  return *(l_state->m_status);
120  } else { // We had a timeout; construct a reasonable message.
121  return XrdCl::XRootDStatus(
122  XrdCl::stError, XrdCl::errSocketTimeout, 1, "Timeout when waiting for query callback.");
123  }
124  }
A arg
Definition: Factorize.h:31
Config
Definition: helper.py:10

Friends And Related Function Documentation

◆ std::make_unique

std::unique_ptr<QueryAttrHandler> std::make_unique ( )
friend

Member Data Documentation

◆ m_fs

XrdCl::FileSystem QueryAttrHandler::m_fs
private

Definition at line 180 of file XrdSource.cc.

◆ m_state

std::weak_ptr<QueryAttrState> QueryAttrHandler::m_state
private

Definition at line 179 of file XrdSource.cc.