XRootD
XrdCl::PostMaster Class Reference

A hub for dispatching and receiving messages. More...

#include <XrdClPostMaster.hh>

+ Collaboration diagram for XrdCl::PostMaster:

Public Member Functions

 PostMaster ()
 Constructor. More...
 
virtual ~PostMaster ()
 Destructor. More...
 
void CollapseRedirect (const URL &oldurl, const URL &newURL)
 Collapse channel URL - replace the URL of the channel. More...
 
void DecFileInstCnt (const URL &url)
 Decrement file object instance count bound to this channel. More...
 
bool Finalize ()
 Finalizer. More...
 
Status ForceDisconnect (const URL &url)
 Shut down a channel. More...
 
Status ForceDisconnect (const URL &url, bool hush)
 Shut down a channel. More...
 
Status ForceReconnect (const URL &url)
 Reconnect the channel. More...
 
JobManagerGetJobManager ()
 Get the job manager object user by the post master. More...
 
TaskManagerGetTaskManager ()
 Get the task manager object user by the post master. More...
 
bool Initialize ()
 Initializer. More...
 
bool IsRunning ()
 
uint16_t NbConnectedStrm (const URL &url)
 Get the number of connected data streams. More...
 
void NotifyConnectHandler (const URL &url)
 Notify the global on-connect handler. More...
 
void NotifyConnErrHandler (const URL &url, const XRootDStatus &status)
 Notify the global error connection handler. More...
 
Status QueryTransport (const URL &url, uint16_t query, AnyObject &result)
 
Status Redirect (const URL &url, Message *msg, MsgHandler *handler)
 
Status RegisterEventHandler (const URL &url, ChannelEventHandler *handler)
 Register channel event handler. More...
 
bool Reinitialize ()
 Reinitialize after fork. More...
 
Status RemoveEventHandler (const URL &url, ChannelEventHandler *handler)
 Remove a channel event handler. More...
 
XRootDStatus Send (const URL &url, Message *msg, MsgHandler *handler, bool stateful, time_t expires)
 
void SetConnectionErrorHandler (std::function< void(const URL &, const XRootDStatus &)> handler)
 Set the global on-error on-connect handler for control streams. More...
 
void SetOnConnectHandler (std::unique_ptr< Job > onConnJob)
 Set the global connection error handler. More...
 
void SetOnDataConnectHandler (const URL &url, std::shared_ptr< Job > onConnJob)
 Set the on-connect handler for data streams. More...
 
bool Start ()
 Start the post master. More...
 
bool Stop ()
 Stop the postmaster. More...
 

Detailed Description

A hub for dispatching and receiving messages.

Definition at line 47 of file XrdClPostMaster.hh.

Constructor & Destructor Documentation

◆ PostMaster()

XrdCl::PostMaster::PostMaster ( )

Constructor.

Definition at line 106 of file XrdClPostMaster.cc.

106  : pImpl( new PostMasterImpl() )
107  {
108  }

◆ ~PostMaster()

XrdCl::PostMaster::~PostMaster ( )
virtual

Destructor.

Definition at line 113 of file XrdClPostMaster.cc.

114  {
115  }

Member Function Documentation

◆ CollapseRedirect()

void XrdCl::PostMaster::CollapseRedirect ( const URL oldurl,
const URL newURL 
)

Collapse channel URL - replace the URL of the channel.

Definition at line 447 of file XrdClPostMaster.cc.

448  {
449  XrdSysRWLockHelper scopedDiscLock( pImpl->pDisconnectLock );
450  XrdSysMutexHelper scopedMapLock( pImpl->pChannelMapMutex );
451 
452  //--------------------------------------------------------------------------
453  // Get the passive channel
454  //--------------------------------------------------------------------------
455  PostMasterImpl::ChannelMap::iterator it =
456  pImpl->pChannelMap.find( alias.GetChannelId() );
457  Channel *passive = 0;
458  if( it != pImpl->pChannelMap.end() )
459  passive = it->second;
460  //--------------------------------------------------------------------------
461  // If the channel does not exist there's nothing to do
462  //--------------------------------------------------------------------------
463  else return;
464 
465  //--------------------------------------------------------------------------
466  // Check if this URL is eligible for collapsing
467  //--------------------------------------------------------------------------
468  if( !passive->CanCollapse( url ) ) return;
469 
470  //--------------------------------------------------------------------------
471  // Create the active channel
472  //--------------------------------------------------------------------------
473  TransportManager *trManager = DefaultEnv::GetTransportManager();
474  TransportHandler *trHandler = trManager->GetHandler( url.GetProtocol() );
475 
476  if( !trHandler )
477  {
478  Log *log = DefaultEnv::GetLog();
479  log->Error( PostMasterMsg, "Unable to get transport handler for %s "
480  "protocol", url.GetProtocol().c_str() );
481  return;
482  }
483 
484  Log *log = DefaultEnv::GetLog();
485  log->Info( PostMasterMsg, "Label channel %s with alias %s.",
486  url.GetHostId().c_str(), alias.GetHostId().c_str() );
487 
488  Channel *active = new Channel( alias, pImpl->pPoller, trHandler,
489  pImpl->pTaskManager, pImpl->pJobManager, url );
490  pImpl->pChannelMap[alias.GetChannelId()] = active;
491  pImpl->pCollapsedMap[&passive->GetURL()] = passive;
492 
493  //--------------------------------------------------------------------------
494  // The passive channel will be deallocated by TTL
495  //--------------------------------------------------------------------------
496  }
static TransportManager * GetTransportManager()
Get transport manager.
static Log * GetLog()
Get default log.
const uint64_t PostMasterMsg
XrdSysError Log
Definition: XrdConfig.cc:113

References XrdCl::Channel::CanCollapse(), XrdCl::Log::Error(), XrdCl::URL::GetChannelId(), XrdCl::TransportManager::GetHandler(), XrdCl::URL::GetHostId(), XrdCl::DefaultEnv::GetLog(), XrdCl::URL::GetProtocol(), XrdCl::DefaultEnv::GetTransportManager(), XrdCl::Channel::GetURL(), XrdCl::Log::Info(), and XrdCl::PostMasterMsg.

Referenced by XrdCl::XRootDMsgHandler::Process().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ DecFileInstCnt()

void XrdCl::PostMaster::DecFileInstCnt ( const URL url)

Decrement file object instance count bound to this channel.

Definition at line 501 of file XrdClPostMaster.cc.

502  {
503  XrdSysRWLockHelper scopedLock( pImpl->pDisconnectLock );
504  Channel *channel = GetChannel( url );
505 
506  if( !channel ) return;
507 
508  return channel->DecFileInstCnt();
509  }

References XrdCl::Channel::DecFileInstCnt().

Referenced by XrdCl::FileStateHandler::~FileStateHandler().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Finalize()

bool XrdCl::PostMaster::Finalize ( )

Finalizer.

Definition at line 147 of file XrdClPostMaster.cc.

148  {
149  //--------------------------------------------------------------------------
150  // Clean up the channels
151  //--------------------------------------------------------------------------
152  if( !pImpl->pInitialized )
153  return true;
154 
155  pImpl->pInitialized = false;
156  pImpl->pJobManager->Finalize();
157  PostMasterImpl::ChannelMap::iterator it;
158 
159  for( it = pImpl->pChannelMap.begin(); it != pImpl->pChannelMap.end(); ++it )
160  delete it->second;
161 
162  pImpl->pChannelMap.clear();
163  return pImpl->pPoller->Finalize();
164  }

Referenced by XrdCl::ForkHandler::Child(), and XrdCl::DefaultEnv::GetPostMaster().

+ Here is the caller graph for this function:

◆ ForceDisconnect() [1/2]

Status XrdCl::PostMaster::ForceDisconnect ( const URL url)

Shut down a channel.

Definition at line 324 of file XrdClPostMaster.cc.

325  {
326  return ForceDisconnect(url, false);
327  }
Status ForceDisconnect(const URL &url)
Shut down a channel.

Referenced by XrdCl::Stream::OnReadTimeout().

+ Here is the caller graph for this function:

◆ ForceDisconnect() [2/2]

Status XrdCl::PostMaster::ForceDisconnect ( const URL url,
bool  hush 
)

Shut down a channel.

Definition at line 332 of file XrdClPostMaster.cc.

333  {
334  XrdSysRWLockHelper scopedLock( pImpl->pDisconnectLock, false );
335  {
336  //--------------------------------------------------------------------
337  // See if this is called by channel replaced by collapse, reaching TTL
338  //--------------------------------------------------------------------
339  PostMasterImpl::CollapsedMap::iterator it =
340  pImpl->pCollapsedMap.find( &url );
341  if( it != pImpl->pCollapsedMap.end() )
342  {
343  Channel *passive = it->second;
344  passive->ForceDisconnect( hush );
345  delete passive;
346  pImpl->pCollapsedMap.erase( it );
347  return Status();
348  }
349  }
350 
351  PostMasterImpl::ChannelMap::iterator it =
352  pImpl->pChannelMap.find( url.GetChannelId() );
353 
354  if( it == pImpl->pChannelMap.end() )
355  return Status( stError, errInvalidOp );
356 
357  it->second->ForceDisconnect( hush );
358  delete it->second;
359  pImpl->pChannelMap.erase( it );
360 
361  return Status();
362  }
const uint16_t stError
An error occurred that could potentially be retried.
Definition: XrdClStatus.hh:32
const uint16_t errInvalidOp
Definition: XrdClStatus.hh:51

References XrdCl::errInvalidOp, XrdCl::Channel::ForceDisconnect(), XrdCl::URL::GetChannelId(), and XrdCl::stError.

+ Here is the call graph for this function:

◆ ForceReconnect()

Status XrdCl::PostMaster::ForceReconnect ( const URL url)

Reconnect the channel.

Definition at line 364 of file XrdClPostMaster.cc.

365  {
366  XrdSysRWLockHelper scopedLock( pImpl->pDisconnectLock, false );
367  PostMasterImpl::ChannelMap::iterator it =
368  pImpl->pChannelMap.find( url.GetChannelId() );
369 
370  if( it == pImpl->pChannelMap.end() )
371  return Status( stError, errInvalidOp );
372 
373  it->second->ForceReconnect();
374  return Status();
375  }

References XrdCl::errInvalidOp, XrdCl::URL::GetChannelId(), and XrdCl::stError.

+ Here is the call graph for this function:

◆ GetJobManager()

JobManager * XrdCl::PostMaster::GetJobManager ( )

Get the job manager object user by the post master.

Definition at line 316 of file XrdClPostMaster.cc.

317  {
318  return pImpl->pJobManager;
319  }

Referenced by XrdCl::FileStateHandler::Close(), XrdCl::Operation< HasHndl >::Run(), XrdEc::ScheduleHandler(), and XrdCl::FileStateHandler::TimeOutRequests().

+ Here is the caller graph for this function:

◆ GetTaskManager()

TaskManager * XrdCl::PostMaster::GetTaskManager ( )

Get the task manager object user by the post master.

Definition at line 308 of file XrdClPostMaster.cc.

309  {
310  return pImpl->pTaskManager;
311  }

Referenced by XrdCl::ForkHandler::Child(), XrdCl::DefaultEnv::GetPostMaster(), and XrdCl::XRootDMsgHandler::Process().

+ Here is the caller graph for this function:

◆ Initialize()

bool XrdCl::PostMaster::Initialize ( )

Initializer.

Definition at line 120 of file XrdClPostMaster.cc.

121  {
122  Env *env = DefaultEnv::GetEnv();
123  std::string pollerPref = DefaultPollerPreference;
124  env->GetString( "PollerPreference", pollerPref );
125 
126  pImpl->pPoller = PollerFactory::CreatePoller( pollerPref );
127 
128  if( !pImpl->pPoller )
129  return false;
130 
131  bool st = pImpl->pPoller->Initialize();
132 
133  if( !st )
134  {
135  delete pImpl->pPoller;
136  return false;
137  }
138 
139  pImpl->pJobManager->Initialize();
140  pImpl->pInitialized = true;
141  return true;
142  }
static Env * GetEnv()
Get default client environment.
static Poller * CreatePoller(const std::string &preference)
const char *const DefaultPollerPreference

References XrdCl::PollerFactory::CreatePoller(), XrdCl::DefaultPollerPreference, XrdCl::DefaultEnv::GetEnv(), and XrdCl::Env::GetString().

Referenced by XrdCl::ForkHandler::Child(), and XrdCl::DefaultEnv::GetPostMaster().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ IsRunning()

bool XrdCl::PostMaster::IsRunning ( )
Returns
: true if underlying threads are running, false otherwise

Definition at line 514 of file XrdClPostMaster.cc.

515  {
516  return pImpl->pRunning;
517  }

◆ NbConnectedStrm()

uint16_t XrdCl::PostMaster::NbConnectedStrm ( const URL url)

Get the number of connected data streams.

Definition at line 380 of file XrdClPostMaster.cc.

381  {
382  XrdSysRWLockHelper scopedLock( pImpl->pDisconnectLock );
383  Channel *channel = GetChannel( url );
384  if( !channel ) return 0;
385  return channel->NbConnectedStrm();
386  }

References XrdCl::Channel::NbConnectedStrm().

+ Here is the call graph for this function:

◆ NotifyConnectHandler()

void XrdCl::PostMaster::NotifyConnectHandler ( const URL url)

Notify the global on-connect handler.

Definition at line 421 of file XrdClPostMaster.cc.

422  {
423  XrdSysMutexHelper lck( pImpl->pMtx );
424  if( pImpl->pOnConnJob )
425  {
426  URL *ptr = new URL( url );
427  pImpl->pJobManager->QueueJob( pImpl->pOnConnJob.get(), ptr );
428  }
429  }

Referenced by XrdCl::Stream::OnConnect().

+ Here is the caller graph for this function:

◆ NotifyConnErrHandler()

void XrdCl::PostMaster::NotifyConnErrHandler ( const URL url,
const XRootDStatus status 
)

Notify the global error connection handler.

Definition at line 434 of file XrdClPostMaster.cc.

435  {
436  XrdSysMutexHelper lck( pImpl->pMtx );
437  if( pImpl->pOnConnErrCB )
438  {
439  ConnErrJob *job = new ConnErrJob( url, status, pImpl->pOnConnErrCB );
440  pImpl->pJobManager->QueueJob( job, nullptr );
441  }
442  }

Referenced by XrdCl::Stream::OnConnectError().

+ Here is the caller graph for this function:

◆ QueryTransport()

Status XrdCl::PostMaster::QueryTransport ( const URL url,
uint16_t  query,
AnyObject result 
)

Query the transport handler for a given URL

Parameters
urlthe channel to be queried
querythe query as defined in the TransportQuery struct or others that may be recognized by the protocol transport
resultthe result of the query
Returns
status of the query

Definition at line 252 of file XrdClPostMaster.cc.

255  {
256  XrdSysRWLockHelper scopedLock( pImpl->pDisconnectLock );
257  Channel *channel = 0;
258  {
259  XrdSysMutexHelper scopedLock2( pImpl->pChannelMapMutex );
260  PostMasterImpl::ChannelMap::iterator it =
261  pImpl->pChannelMap.find( url.GetChannelId() );
262  if( it == pImpl->pChannelMap.end() )
263  return Status( stError, errInvalidOp );
264  channel = it->second;
265  }
266 
267  if( !channel )
268  return Status( stError, errNotSupported );
269 
270  return channel->QueryTransport( query, result );
271  }
const uint16_t errNotSupported
Definition: XrdClStatus.hh:62

References XrdCl::errInvalidOp, XrdCl::errNotSupported, XrdCl::URL::GetChannelId(), XrdCl::Channel::QueryTransport(), and XrdCl::stError.

Referenced by XrdCl::FileSystem::DirList(), XrdCl::FileStateHandler::PgRead(), and XrdCl::XRootDMsgHandler::Process().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Redirect()

Status XrdCl::PostMaster::Redirect ( const URL url,
Message msg,
MsgHandler handler 
)

Definition at line 238 of file XrdClPostMaster.cc.

241  {
242  RedirectorRegistry &registry = RedirectorRegistry::Instance();
243  VirtualRedirector *redirector = registry.Get( url );
244  if( !redirector )
245  return Status( stError, errInvalidOp );
246  return redirector->HandleRequest( msg, inHandler );
247  }
static RedirectorRegistry & Instance()
Returns reference to the single instance.

References XrdCl::errInvalidOp, XrdCl::RedirectorRegistry::Get(), XrdCl::VirtualRedirector::HandleRequest(), XrdCl::RedirectorRegistry::Instance(), and XrdCl::stError.

Referenced by XrdCl::MessageUtils::RedirectMessage().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ RegisterEventHandler()

Status XrdCl::PostMaster::RegisterEventHandler ( const URL url,
ChannelEventHandler handler 
)

Register channel event handler.

Definition at line 276 of file XrdClPostMaster.cc.

278  {
279  XrdSysRWLockHelper scopedLock( pImpl->pDisconnectLock );
280  Channel *channel = GetChannel( url );
281 
282  if( !channel )
283  return Status( stError, errNotSupported );
284 
285  channel->RegisterEventHandler( handler );
286  return Status();
287  }

References XrdCl::errNotSupported, XrdCl::Channel::RegisterEventHandler(), and XrdCl::stError.

+ Here is the call graph for this function:

◆ Reinitialize()

bool XrdCl::PostMaster::Reinitialize ( )

Reinitialize after fork.

Definition at line 215 of file XrdClPostMaster.cc.

216  {
217  return true;
218  }

◆ RemoveEventHandler()

Status XrdCl::PostMaster::RemoveEventHandler ( const URL url,
ChannelEventHandler handler 
)

Remove a channel event handler.

Definition at line 292 of file XrdClPostMaster.cc.

294  {
295  XrdSysRWLockHelper scopedLock( pImpl->pDisconnectLock );
296  Channel *channel = GetChannel( url );
297 
298  if( !channel )
299  return Status( stError, errNotSupported );
300 
301  channel->RemoveEventHandler( handler );
302  return Status();
303  }

References XrdCl::errNotSupported, XrdCl::Channel::RemoveEventHandler(), and XrdCl::stError.

+ Here is the call graph for this function:

◆ Send()

XRootDStatus XrdCl::PostMaster::Send ( const URL url,
Message msg,
MsgHandler handler,
bool  stateful,
time_t  expires 
)

Send the message asynchronously - the message is inserted into the send queue and a listener is called when the message is succesfsully pushed through the wire or when the timeout elapses

DEADLOCK WARNING: no lock should be taken while calling this method that are used in the callback as well.

Parameters
urlrecipient of the message
msgmessage to be sent
expiresunix timestamp after which a failure is reported to the handler
handlerhandler will be notified about the status
statefulphysical stream disconnection causes an error
Returns
success if the message was successfully inserted into the send queues, failure otherwise

Definition at line 223 of file XrdClPostMaster.cc.

228  {
229  XrdSysRWLockHelper scopedLock( pImpl->pDisconnectLock );
230  Channel *channel = GetChannel( url );
231 
232  if( !channel )
233  return XRootDStatus( stError, errNotSupported );
234 
235  return channel->Send( msg, handler, stateful, expires );
236  }

References XrdCl::errNotSupported, XrdCl::Channel::Send(), and XrdCl::stError.

Referenced by XrdCl::MessageUtils::SendMessage().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ SetConnectionErrorHandler()

void XrdCl::PostMaster::SetConnectionErrorHandler ( std::function< void(const URL &, const XRootDStatus &)>  handler)

Set the global on-error on-connect handler for control streams.

Definition at line 412 of file XrdClPostMaster.cc.

413  {
414  XrdSysMutexHelper lck( pImpl->pMtx );
415  pImpl->pOnConnErrCB = std::move( handler );
416  }

◆ SetOnConnectHandler()

void XrdCl::PostMaster::SetOnConnectHandler ( std::unique_ptr< Job onConnJob)

Set the global connection error handler.

Set the global on-connect handler for control streams.

Definition at line 403 of file XrdClPostMaster.cc.

404  {
405  XrdSysMutexHelper lck( pImpl->pMtx );
406  pImpl->pOnConnJob = std::move( onConnJob );
407  }

Referenced by XrdPosixConfig::conTracker().

+ Here is the caller graph for this function:

◆ SetOnDataConnectHandler()

void XrdCl::PostMaster::SetOnDataConnectHandler ( const URL url,
std::shared_ptr< Job onConnJob 
)

Set the on-connect handler for data streams.

Definition at line 391 of file XrdClPostMaster.cc.

393  {
394  XrdSysRWLockHelper scopedLock( pImpl->pDisconnectLock );
395  Channel *channel = GetChannel( url );
396  if( !channel ) return;
397  channel->SetOnDataConnectHandler( onConnJob );
398  }

References XrdCl::Channel::SetOnDataConnectHandler().

+ Here is the call graph for this function:

◆ Start()

bool XrdCl::PostMaster::Start ( )

Start the post master.

Definition at line 169 of file XrdClPostMaster.cc.

170  {
171  if( !pImpl->pInitialized )
172  return false;
173 
174  if( !pImpl->pPoller->Start() )
175  return false;
176 
177  if( !pImpl->pTaskManager->Start() )
178  {
179  pImpl->pPoller->Stop();
180  return false;
181  }
182 
183  if( !pImpl->pJobManager->Start() )
184  {
185  pImpl->pPoller->Stop();
186  pImpl->pTaskManager->Stop();
187  return false;
188  }
189 
190  pImpl->pRunning = true;
191  return true;
192  }

Referenced by XrdCl::ForkHandler::Child(), XrdCl::DefaultEnv::GetPostMaster(), and XrdCl::ForkHandler::Parent().

+ Here is the caller graph for this function:

◆ Stop()

bool XrdCl::PostMaster::Stop ( )

Stop the postmaster.

Definition at line 197 of file XrdClPostMaster.cc.

198  {
199  if( !pImpl->pInitialized || !pImpl->pRunning )
200  return true;
201 
202  if( !pImpl->pJobManager->Stop() )
203  return false;
204  if( !pImpl->pPoller->Stop() )
205  return false;
206  if( !pImpl->pTaskManager->Stop() )
207  return false;
208  pImpl->pRunning = false;
209  return true;
210  }

Referenced by main(), and XrdCl::ForkHandler::Prepare().

+ Here is the caller graph for this function:

The documentation for this class was generated from the following files: