test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 (const QueryAttrHandler &)=delete
 
virtual ~QueryAttrHandler ()=default
 

Static Public Member Functions

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

Private Member Functions

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

Private Attributes

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 88 of file XrdSource.cc.

Constructor & Destructor Documentation

virtual QueryAttrHandler::~QueryAttrHandler ( )
virtualdefault
QueryAttrHandler::QueryAttrHandler ( const QueryAttrHandler )
delete
QueryAttrHandler::QueryAttrHandler ( )
inlineprivate

Definition at line 137 of file XrdSource.cc.

137 {}

Member Function Documentation

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

Definition at line 140 of file XrdSource.cc.

141  {
142  // NOTE: we own the status and response pointers.
143  std::unique_ptr<XrdCl::AnyObject> response_mgr;
144  response_mgr.reset(response);
145 
146  // Lock our state information then dispose of our object.
147  auto l_state = m_state.lock();
148  delete this;
149  if (!l_state) {return;}
150 
151  // On function exit, notify any waiting threads.
152  std::unique_ptr<char, std::function<void(char*)>> notify_guard(nullptr, [&](char *) {l_state->m_condvar.notify_all();});
153 
154  {
155  // On exit from the block, make sure m_status is set; it needs to be set before we notify threads.
156  std::unique_ptr<char, std::function<void(char*)>> exit_guard(nullptr, [&](char *) {if (!l_state->m_status) l_state->m_status.reset(new XrdCl::XRootDStatus(XrdCl::stError, XrdCl::errInternal));});
157  if (!status) {return;}
158  if (status->IsOK())
159  {
160  if (!response) {return;}
161  XrdCl::Buffer *buf_ptr;
162  response->Get(buf_ptr);
163  // AnyObject::Set lacks specialization for nullptr
164  response->Set(static_cast<int *>(nullptr));
165  l_state->m_response.reset(buf_ptr);
166  }
167  l_state->m_status.reset(status);
168  }
169  }
std::weak_ptr< QueryAttrState > m_state
Definition: XrdSource.cc:186
tuple status
Definition: mps_update.py:57
QueryAttrHandler& QueryAttrHandler::operator= ( const QueryAttrHandler )
delete
static XrdCl::XRootDStatus QueryAttrHandler::query ( XrdCl::FileSystem &  fs,
const std::string &  attr,
std::chrono::milliseconds  timeout,
std::string &  result 
)
inlinestatic

Definition at line 99 of file XrdSource.cc.

References helper::Config.

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

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

Friends And Related Function Documentation

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

Member Data Documentation

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

Definition at line 186 of file XrdSource.cc.