XRootD
Loading...
Searching...
No Matches
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.
 
virtual ~PostMaster ()
 Destructor.
 
void CollapseRedirect (const URL &oldurl, const URL &newURL)
 Collapse channel URL - replace the URL of the channel.
 
void DecFileInstCnt (const URL &url)
 Decrement file object instance count bound to this channel.
 
bool Finalize ()
 Finalizer.
 
Status ForceDisconnect (const URL &url)
 Shut down a channel.
 
Status ForceReconnect (const URL &url)
 Reconnect the channel.
 
JobManagerGetJobManager ()
 Get the job manager object user by the post master.
 
TaskManagerGetTaskManager ()
 Get the task manager object user by the post master.
 
bool Initialize ()
 Initializer.
 
bool IsRunning ()
 
uint16_t NbConnectedStrm (const URL &url)
 Get the number of connected data streams.
 
void NotifyConnectHandler (const URL &url)
 Notify the global on-connect handler.
 
void NotifyConnErrHandler (const URL &url, const XRootDStatus &status)
 Notify the global error connection handler.
 
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.
 
bool Reinitialize ()
 Reinitialize after fork.
 
Status RemoveEventHandler (const URL &url, ChannelEventHandler *handler)
 Remove a channel event handler.
 
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.
 
void SetOnConnectHandler (std::unique_ptr< Job > onConnJob)
 Set the global connection error handler.
 
void SetOnDataConnectHandler (const URL &url, std::shared_ptr< Job > onConnJob)
 Set the on-connect handler for data streams.
 
bool Start ()
 Start the post master.
 
bool Stop ()
 Stop the postmaster.
 

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

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

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

467 {
468 XrdSysRWLockHelper scopedLock( pImpl->pDisconnectLock );
469 Channel *channel = GetChannel( url );
470
471 if( !channel ) return;
472
473 return channel->DecFileInstCnt();
474 }

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()

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

Shut down a channel.

Definition at line 315 of file XrdClPostMaster.cc.

316 {
317 XrdSysRWLockHelper scopedLock( pImpl->pDisconnectLock, false );
318 PostMasterImpl::ChannelMap::iterator it =
319 pImpl->pChannelMap.find( url.GetChannelId() );
320
321 if( it == pImpl->pChannelMap.end() )
322 return Status( stError, errInvalidOp );
323
324 it->second->ForceDisconnect();
325 delete it->second;
326 pImpl->pChannelMap.erase( it );
327
328 return Status();
329 }
const uint16_t stError
An error occurred that could potentially be retried.
const uint16_t errInvalidOp

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

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

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

◆ ForceReconnect()

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

Reconnect the channel.

Definition at line 331 of file XrdClPostMaster.cc.

332 {
333 XrdSysRWLockHelper scopedLock( pImpl->pDisconnectLock, false );
334 PostMasterImpl::ChannelMap::iterator it =
335 pImpl->pChannelMap.find( url.GetChannelId() );
336
337 if( it == pImpl->pChannelMap.end() )
338 return Status( stError, errInvalidOp );
339
340 it->second->ForceReconnect();
341 return Status();
342 }

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(), 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 479 of file XrdClPostMaster.cc.

480 {
481 return pImpl->pRunning;
482 }

◆ NbConnectedStrm()

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

Get the number of connected data streams.

Definition at line 347 of file XrdClPostMaster.cc.

348 {
349 XrdSysRWLockHelper scopedLock( pImpl->pDisconnectLock );
350 Channel *channel = GetChannel( url );
351 if( !channel ) return 0;
352 return channel->NbConnectedStrm();
353 }

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

389 {
390 XrdSysMutexHelper lck( pImpl->pMtx );
391 if( pImpl->pOnConnJob )
392 {
393 URL *ptr = new URL( url );
394 pImpl->pJobManager->QueueJob( pImpl->pOnConnJob.get(), ptr );
395 }
396 }

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

402 {
403 XrdSysMutexHelper lck( pImpl->pMtx );
404 if( pImpl->pOnConnErrCB )
405 {
406 ConnErrJob *job = new ConnErrJob( url, status, pImpl->pOnConnErrCB );
407 pImpl->pJobManager->QueueJob( job, nullptr );
408 }
409 }

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

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

380 {
381 XrdSysMutexHelper lck( pImpl->pMtx );
382 pImpl->pOnConnErrCB = std::move( handler );
383 }

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

371 {
372 XrdSysMutexHelper lck( pImpl->pMtx );
373 pImpl->pOnConnJob = std::move( onConnJob );
374 }

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

360 {
361 XrdSysRWLockHelper scopedLock( pImpl->pDisconnectLock );
362 Channel *channel = GetChannel( url );
363 if( !channel ) return;
364 channel->SetOnDataConnectHandler( onConnJob );
365 }

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: