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 97 of file XrdClPostMaster.cc.

97  : pImpl( new PostMasterImpl() )
98  {
99  }

◆ ~PostMaster()

XrdCl::PostMaster::~PostMaster ( )
virtual

Destructor.

Definition at line 104 of file XrdClPostMaster.cc.

105  {
106  }

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 422 of file XrdClPostMaster.cc.

423  {
424  XrdSysMutexHelper scopedLock( pImpl->pChannelMapMutex );
425 
426  //--------------------------------------------------------------------------
427  // Get the passive channel
428  //--------------------------------------------------------------------------
429  PostMasterImpl::ChannelMap::iterator it =
430  pImpl->pChannelMap.find( alias.GetChannelId() );
431  Channel *passive = 0;
432  if( it != pImpl->pChannelMap.end() )
433  passive = it->second;
434  //--------------------------------------------------------------------------
435  // If the channel does not exist there's nothing to do
436  //--------------------------------------------------------------------------
437  else return;
438 
439  //--------------------------------------------------------------------------
440  // Check if this URL is eligible for collapsing
441  //--------------------------------------------------------------------------
442  if( !passive->CanCollapse( url ) ) return;
443 
444  //--------------------------------------------------------------------------
445  // Create the active channel
446  //--------------------------------------------------------------------------
447  TransportManager *trManager = DefaultEnv::GetTransportManager();
448  TransportHandler *trHandler = trManager->GetHandler( url.GetProtocol() );
449 
450  if( !trHandler )
451  {
452  Log *log = DefaultEnv::GetLog();
453  log->Error( PostMasterMsg, "Unable to get transport handler for %s "
454  "protocol", url.GetProtocol().c_str() );
455  return;
456  }
457 
458  Log *log = DefaultEnv::GetLog();
459  log->Info( PostMasterMsg, "Label channel %s with alias %s.",
460  url.GetHostId().c_str(), alias.GetHostId().c_str() );
461 
462  Channel *active = new Channel( alias, pImpl->pPoller, trHandler,
463  pImpl->pTaskManager, pImpl->pJobManager, url );
464  pImpl->pChannelMap[alias.GetChannelId()] = active;
465 
466  //--------------------------------------------------------------------------
467  // The passive channel will be deallocated by TTL
468  //--------------------------------------------------------------------------
469  }
static TransportManager * GetTransportManager()
Get transport manager.
static Log * GetLog()
Get default log.
const uint64_t PostMasterMsg
XrdSysError Log
Definition: XrdConfig.cc:112

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::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 474 of file XrdClPostMaster.cc.

475  {
476  XrdSysRWLockHelper scopedLock( pImpl->pDisconnectLock );
477  Channel *channel = GetChannel( url );
478 
479  if( !channel ) return;
480 
481  return channel->DecFileInstCnt();
482  }

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 138 of file XrdClPostMaster.cc.

139  {
140  //--------------------------------------------------------------------------
141  // Clean up the channels
142  //--------------------------------------------------------------------------
143  if( !pImpl->pInitialized )
144  return true;
145 
146  pImpl->pInitialized = false;
147  pImpl->pJobManager->Finalize();
148  PostMasterImpl::ChannelMap::iterator it;
149 
150  for( it = pImpl->pChannelMap.begin(); it != pImpl->pChannelMap.end(); ++it )
151  delete it->second;
152 
153  pImpl->pChannelMap.clear();
154  return pImpl->pPoller->Finalize();
155  }

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 315 of file XrdClPostMaster.cc.

316  {
317  return ForceDisconnect(url, false);
318  }
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 323 of file XrdClPostMaster.cc.

324  {
325  XrdSysRWLockHelper scopedLock( pImpl->pDisconnectLock, false );
326  PostMasterImpl::ChannelMap::iterator it =
327  pImpl->pChannelMap.find( url.GetChannelId() );
328 
329  if( it == pImpl->pChannelMap.end() )
330  return Status( stError, errInvalidOp );
331 
332  it->second->ForceDisconnect( hush );
333  delete it->second;
334  pImpl->pChannelMap.erase( it );
335 
336  return Status();
337  }
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::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 339 of file XrdClPostMaster.cc.

340  {
341  XrdSysRWLockHelper scopedLock( pImpl->pDisconnectLock, false );
342  PostMasterImpl::ChannelMap::iterator it =
343  pImpl->pChannelMap.find( url.GetChannelId() );
344 
345  if( it == pImpl->pChannelMap.end() )
346  return Status( stError, errInvalidOp );
347 
348  it->second->ForceReconnect();
349  return Status();
350  }

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 307 of file XrdClPostMaster.cc.

308  {
309  return pImpl->pJobManager;
310  }

Referenced by XrdCl::FileStateHandler::Close(), XrdCl::LocalFileHandler::QueueTask(), 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 299 of file XrdClPostMaster.cc.

300  {
301  return pImpl->pTaskManager;
302  }

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 111 of file XrdClPostMaster.cc.

112  {
113  Env *env = DefaultEnv::GetEnv();
114  std::string pollerPref = DefaultPollerPreference;
115  env->GetString( "PollerPreference", pollerPref );
116 
117  pImpl->pPoller = PollerFactory::CreatePoller( pollerPref );
118 
119  if( !pImpl->pPoller )
120  return false;
121 
122  bool st = pImpl->pPoller->Initialize();
123 
124  if( !st )
125  {
126  delete pImpl->pPoller;
127  return false;
128  }
129 
130  pImpl->pJobManager->Initialize();
131  pImpl->pInitialized = true;
132  return true;
133  }
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 487 of file XrdClPostMaster.cc.

488  {
489  return pImpl->pRunning;
490  }

◆ NbConnectedStrm()

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

Get the number of connected data streams.

Definition at line 355 of file XrdClPostMaster.cc.

356  {
357  XrdSysRWLockHelper scopedLock( pImpl->pDisconnectLock );
358  Channel *channel = GetChannel( url );
359  if( !channel ) return 0;
360  return channel->NbConnectedStrm();
361  }

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 396 of file XrdClPostMaster.cc.

397  {
398  XrdSysMutexHelper lck( pImpl->pMtx );
399  if( pImpl->pOnConnJob )
400  {
401  URL *ptr = new URL( url );
402  pImpl->pJobManager->QueueJob( pImpl->pOnConnJob.get(), ptr );
403  }
404  }

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 409 of file XrdClPostMaster.cc.

410  {
411  XrdSysMutexHelper lck( pImpl->pMtx );
412  if( pImpl->pOnConnErrCB )
413  {
414  ConnErrJob *job = new ConnErrJob( url, status, pImpl->pOnConnErrCB );
415  pImpl->pJobManager->QueueJob( job, nullptr );
416  }
417  }

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 243 of file XrdClPostMaster.cc.

246  {
247  XrdSysRWLockHelper scopedLock( pImpl->pDisconnectLock );
248  Channel *channel = 0;
249  {
250  XrdSysMutexHelper scopedLock2( pImpl->pChannelMapMutex );
251  PostMasterImpl::ChannelMap::iterator it =
252  pImpl->pChannelMap.find( url.GetChannelId() );
253  if( it == pImpl->pChannelMap.end() )
254  return Status( stError, errInvalidOp );
255  channel = it->second;
256  }
257 
258  if( !channel )
259  return Status( stError, errNotSupported );
260 
261  return channel->QueryTransport( query, result );
262  }
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 229 of file XrdClPostMaster.cc.

232  {
233  RedirectorRegistry &registry = RedirectorRegistry::Instance();
234  VirtualRedirector *redirector = registry.Get( url );
235  if( !redirector )
236  return Status( stError, errInvalidOp );
237  return redirector->HandleRequest( msg, inHandler );
238  }
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 267 of file XrdClPostMaster.cc.

269  {
270  XrdSysRWLockHelper scopedLock( pImpl->pDisconnectLock );
271  Channel *channel = GetChannel( url );
272 
273  if( !channel )
274  return Status( stError, errNotSupported );
275 
276  channel->RegisterEventHandler( handler );
277  return Status();
278  }

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 206 of file XrdClPostMaster.cc.

207  {
208  return true;
209  }

◆ RemoveEventHandler()

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

Remove a channel event handler.

Definition at line 283 of file XrdClPostMaster.cc.

285  {
286  XrdSysRWLockHelper scopedLock( pImpl->pDisconnectLock );
287  Channel *channel = GetChannel( url );
288 
289  if( !channel )
290  return Status( stError, errNotSupported );
291 
292  channel->RemoveEventHandler( handler );
293  return Status();
294  }

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 214 of file XrdClPostMaster.cc.

219  {
220  XrdSysRWLockHelper scopedLock( pImpl->pDisconnectLock );
221  Channel *channel = GetChannel( url );
222 
223  if( !channel )
224  return XRootDStatus( stError, errNotSupported );
225 
226  return channel->Send( msg, handler, stateful, expires );
227  }

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 387 of file XrdClPostMaster.cc.

388  {
389  XrdSysMutexHelper lck( pImpl->pMtx );
390  pImpl->pOnConnErrCB = std::move( handler );
391  }

◆ 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 378 of file XrdClPostMaster.cc.

379  {
380  XrdSysMutexHelper lck( pImpl->pMtx );
381  pImpl->pOnConnJob = std::move( onConnJob );
382  }

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 366 of file XrdClPostMaster.cc.

368  {
369  XrdSysRWLockHelper scopedLock( pImpl->pDisconnectLock );
370  Channel *channel = GetChannel( url );
371  if( !channel ) return;
372  channel->SetOnDataConnectHandler( onConnJob );
373  }

References XrdCl::Channel::SetOnDataConnectHandler().

+ Here is the call graph for this function:

◆ Start()

bool XrdCl::PostMaster::Start ( )

Start the post master.

Definition at line 160 of file XrdClPostMaster.cc.

161  {
162  if( !pImpl->pInitialized )
163  return false;
164 
165  if( !pImpl->pPoller->Start() )
166  return false;
167 
168  if( !pImpl->pTaskManager->Start() )
169  {
170  pImpl->pPoller->Stop();
171  return false;
172  }
173 
174  if( !pImpl->pJobManager->Start() )
175  {
176  pImpl->pPoller->Stop();
177  pImpl->pTaskManager->Stop();
178  return false;
179  }
180 
181  pImpl->pRunning = true;
182  return true;
183  }

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 188 of file XrdClPostMaster.cc.

189  {
190  if( !pImpl->pInitialized || !pImpl->pRunning )
191  return true;
192 
193  if( !pImpl->pJobManager->Stop() )
194  return false;
195  if( !pImpl->pPoller->Stop() )
196  return false;
197  if( !pImpl->pTaskManager->Stop() )
198  return false;
199  pImpl->pRunning = false;
200  return true;
201  }

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: