XRootD
XrdCl::Channel Class Reference

#include <XrdClChannel.hh>

+ Collaboration diagram for XrdCl::Channel:

Public Member Functions

 Channel (const URL &url, Poller *poller, TransportHandler *transport, TaskManager *taskManager, JobManager *jobManager, const URL &prefurl=URL())
 
 ~Channel ()
 Destructor. More...
 
bool CanCollapse (const URL &url)
 
void DecFileInstCnt ()
 Decrement file object instance count bound to this channel. More...
 
void Finalize ()
 
Status ForceDisconnect ()
 Force disconnect of all streams. More...
 
Status ForceDisconnect (bool hush)
 Force disconnect of all streams. More...
 
Status ForceDisconnect (std::shared_ptr< Channel > self, const uint64_t sess)
 
Status ForceReconnect ()
 Force reconnect. More...
 
const URLGetURL () const
 Get the URL. More...
 
uint16_t NbConnectedStrm ()
 Get the number of connected data streams. More...
 
Status QueryTransport (uint16_t query, AnyObject &result)
 
void RegisterEventHandler (ChannelEventHandler *handler)
 Register channel event handler. More...
 
void RemoveEventHandler (ChannelEventHandler *handler)
 Remove a channel event handler. More...
 
XRootDStatus Send (Message *msg, MsgHandler *handler, bool stateful, time_t expires)
 
void SetOnDataConnectHandler (std::shared_ptr< Job > &onConnJob)
 Set the on-connect handler for data streams. More...
 
void SetSelf (std::shared_ptr< Channel > &self)
 Gives us access to the shared pointer that the postmaster holds for us. More...
 
void Tick (time_t now)
 Handle a time event. More...
 

Detailed Description

A communication channel between the client and the server

Notes on ownership. The Channel is owned via shared_ptr usually held by at least PostMaster. Channels replaced during a RedirectCollapse may no longer be held by PostMaster. Channel has a weak_ptr to its shared_ptr (pSelf). Channel owns a Stream, which also holds a weak_ptr for its owning Channel. The Stream owns a number of AsyncSocketHandler (one for each substream). After Connect() the SocketHandler will hold a shared_ptr for Channel until the SocketHandler is Closed. Thus lifetime of Channel ends when PostMaster gives up holding the Channel and all AsyncSocketHandler Close connections. PostMaster also maintains a set of non-owning Channel* for live Channel objects, for PostMaster::Finalize() to use to issue Finalize() on any live Channels.

Definition at line 61 of file XrdClChannel.hh.

Constructor & Destructor Documentation

◆ Channel()

XrdCl::Channel::Channel ( const URL url,
Poller poller,
TransportHandler transport,
TaskManager taskManager,
JobManager jobManager,
const URL prefurl = URL() 
)

Constructor

Parameters
urladdress of the server to connect to
pollerpoller object to be used for non-blocking IO
transportprotocol specific transport handler
taskManagerasync task handler to be used by the channel
jobManagerworker thread handler to be used by the channel

Definition at line 84 of file XrdClChannel.cc.

89  :
90  pUrl( url.GetHostId() ),
91  pPoller( poller ),
92  pTransport( transport ),
93  pTaskManager( taskManager ),
94  pTickGenerator( 0 ),
95  pJobManager( jobManager )
96  {
97  Env *env = DefaultEnv::GetEnv();
98  Log *log = DefaultEnv::GetLog();
99 
100  int timeoutResolution = DefaultTimeoutResolution;
101  env->GetInt( "TimeoutResolution", timeoutResolution );
102 
103  pTransport->InitializeChannel( url, pChannelData );
104  log->Debug( PostMasterMsg, "Creating new channel to: %s",
105  url.GetChannelId().c_str() );
106 
107  pUrl.SetParams( url.GetParams() );
108  pUrl.SetProtocol( url.GetProtocol() );
109 
110  //--------------------------------------------------------------------------
111  // Create the stream
112  //--------------------------------------------------------------------------
113  pStream = std::make_unique<Stream>( &pUrl, prefurl );
114  pStream->SetTransport( transport );
115  pStream->SetPoller( poller );
116  pStream->SetIncomingQueue( &pIncoming );
117  pStream->SetTaskManager( taskManager );
118  pStream->SetJobManager( jobManager );
119  pStream->SetChannelData( &pChannelData );
120  pStream->Initialize();
121 
122  //--------------------------------------------------------------------------
123  // Register the task generating timeout events
124  //--------------------------------------------------------------------------
125  pTickGenerator = new TickGeneratorTask( this, pUrl.GetChannelId() );
126  pTaskManager->RegisterTask( pTickGenerator, ::time(0)+timeoutResolution );
127  }
static Log * GetLog()
Get default log.
static Env * GetEnv()
Get default client environment.
bool GetInt(const std::string &key, int &value)
Definition: XrdClEnv.cc:89
Handle diagnostics.
Definition: XrdClLog.hh:101
void Debug(uint64_t topic, const char *format,...)
Print a debug message.
Definition: XrdClLog.cc:282
void RegisterTask(Task *task, time_t time, bool own=true)
virtual void InitializeChannel(const URL &url, AnyObject &channelData)=0
Initialize channel.
std::string GetChannelId() const
Definition: XrdClURL.cc:512
std::string GetHostId() const
Get the host part of the URL (user:password@host:port)
Definition: XrdClURL.hh:99
const std::string & GetProtocol() const
Get the protocol.
Definition: XrdClURL.hh:118
void SetParams(const std::string &params)
Set params.
Definition: XrdClURL.cc:402
const ParamsMap & GetParams() const
Get the URL params.
Definition: XrdClURL.hh:244
void SetProtocol(const std::string &protocol)
Set protocol.
Definition: XrdClURL.hh:126
const uint64_t PostMasterMsg
const int DefaultTimeoutResolution

References XrdCl::Log::Debug(), XrdCl::DefaultTimeoutResolution, XrdCl::URL::GetChannelId(), XrdCl::DefaultEnv::GetEnv(), XrdCl::Env::GetInt(), XrdCl::DefaultEnv::GetLog(), XrdCl::URL::GetParams(), XrdCl::URL::GetProtocol(), XrdCl::TransportHandler::InitializeChannel(), XrdCl::PostMasterMsg, XrdCl::TaskManager::RegisterTask(), XrdCl::URL::SetParams(), and XrdCl::URL::SetProtocol().

+ Here is the call graph for this function:

◆ ~Channel()

XrdCl::Channel::~Channel ( )

Destructor.

Definition at line 132 of file XrdClChannel.cc.

133  {
134  pTickGenerator->Invalidate();
135  pStream.reset();
136  pTransport->FinalizeChannel( pChannelData );
137  }
virtual void FinalizeChannel(AnyObject &channelData)=0
Finalize channel.

References XrdCl::TransportHandler::FinalizeChannel(), and XrdCl::TickGeneratorTask::Invalidate().

+ Here is the call graph for this function:

Member Function Documentation

◆ CanCollapse()

bool XrdCl::Channel::CanCollapse ( const URL url)
Returns
: true if this channel can be collapsed using this URL, false otherwise

Definition at line 230 of file XrdClChannel.cc.

231  {
232  return pStream->CanCollapse( url );
233  }

◆ DecFileInstCnt()

void XrdCl::Channel::DecFileInstCnt ( )

Decrement file object instance count bound to this channel.

Definition at line 238 of file XrdClChannel.cc.

239  {
240  pTransport->DecFileInstCnt( pChannelData );
241  }
virtual void DecFileInstCnt(AnyObject &channelData)=0
Decrement file object instance count bound to this channel.

References XrdCl::TransportHandler::DecFileInstCnt().

+ Here is the call graph for this function:

◆ Finalize()

void XrdCl::Channel::Finalize ( )

Used by the PostMaster to indicate the Channel should release all resources. It should be assumed that the jobmanager has already been stopped & finalized and the poller and taskmanager have been stopped.

Definition at line 162 of file XrdClChannel.cc.

163  {
164  pStream->Finalize();
165  }

◆ ForceDisconnect() [1/3]

Status XrdCl::Channel::ForceDisconnect ( )

Force disconnect of all streams.

Definition at line 170 of file XrdClChannel.cc.

171  {
172  return ForceDisconnect(false);
173  }
Status ForceDisconnect()
Force disconnect of all streams.

◆ ForceDisconnect() [2/3]

Status XrdCl::Channel::ForceDisconnect ( bool  hush)

Force disconnect of all streams.

Definition at line 178 of file XrdClChannel.cc.

179  {
180  //--------------------------------------------------------------------------
181  // Disconnect the stream and all substreams
182  //--------------------------------------------------------------------------
183  pStream->ForceError( Status( stError, errOperationInterrupted ), hush, 0);
184 
185  return Status();
186  }
const uint16_t stError
An error occurred that could potentially be retried.
Definition: XrdClStatus.hh:32
const uint16_t errOperationInterrupted
Definition: XrdClStatus.hh:91
Procedure execution status.
Definition: XrdClStatus.hh:115

References XrdCl::errOperationInterrupted, and XrdCl::stError.

◆ ForceDisconnect() [3/3]

Status XrdCl::Channel::ForceDisconnect ( std::shared_ptr< Channel self,
const uint64_t  sess 
)

Force disconnect of all streams. This was triggered internally, e.g. by one of our Streams.

Definition at line 191 of file XrdClChannel.cc.

193  {
194  //--------------------------------------------------------------------------
195  // Disconnect the stream and all substreams
196  //--------------------------------------------------------------------------
197  pStream->ForceError( Status( stError, errOperationInterrupted ), false, sess );
198 
199  return Status();
200  }

References XrdCl::errOperationInterrupted, and XrdCl::stError.

◆ ForceReconnect()

Status XrdCl::Channel::ForceReconnect ( )

Force reconnect.

Definition at line 205 of file XrdClChannel.cc.

206  {
207  pStream->ForceConnect();
208  return Status();
209  }

◆ GetURL()

const URL& XrdCl::Channel::GetURL ( ) const
inline

Get the URL.

Definition at line 88 of file XrdClChannel.hh.

89  {
90  return pUrl;
91  }

◆ NbConnectedStrm()

uint16_t XrdCl::Channel::NbConnectedStrm ( )

Get the number of connected data streams.

Definition at line 214 of file XrdClChannel.cc.

215  {
216  return XRootDTransport::NbConnectedStrm( pChannelData );
217  }
static uint16_t NbConnectedStrm(AnyObject &channelData)
Number of currently connected data streams.

References XrdCl::XRootDTransport::NbConnectedStrm().

+ Here is the call graph for this function:

◆ QueryTransport()

Status XrdCl::Channel::QueryTransport ( uint16_t  query,
AnyObject result 
)

Query the transport handler

Parameters
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 246 of file XrdClChannel.cc.

247  {
248  if( query < 2000 )
249  return pTransport->Query( query, result, pChannelData );
250  return pStream->Query( query, result );
251  }
virtual Status Query(uint16_t query, AnyObject &result, AnyObject &channelData)=0
Query the channel.

References XrdCl::TransportHandler::Query().

+ Here is the call graph for this function:

◆ RegisterEventHandler()

void XrdCl::Channel::RegisterEventHandler ( ChannelEventHandler handler)

Register channel event handler.

Definition at line 256 of file XrdClChannel.cc.

257  {
258  pStream->RegisterEventHandler( handler );
259  }

◆ RemoveEventHandler()

void XrdCl::Channel::RemoveEventHandler ( ChannelEventHandler handler)

Remove a channel event handler.

Definition at line 264 of file XrdClChannel.cc.

265  {
266  pStream->RemoveEventHandler( handler );
267  }

◆ Send()

XRootDStatus XrdCl::Channel::Send ( 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 successfully pushed through the wire or when the timeout elapses

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

Definition at line 142 of file XrdClChannel.cc.

147  {
148  return pStream->Send( msg, handler, stateful, expires );
149  }

◆ SetOnDataConnectHandler()

void XrdCl::Channel::SetOnDataConnectHandler ( std::shared_ptr< Job > &  onConnJob)

Set the on-connect handler for data streams.

Definition at line 222 of file XrdClChannel.cc.

223  {
224  pStream->SetOnDataConnectHandler( onConnJob );
225  }

◆ SetSelf()

void XrdCl::Channel::SetSelf ( std::shared_ptr< Channel > &  self)

Gives us access to the shared pointer that the postmaster holds for us.

Definition at line 269 of file XrdClChannel.cc.

270  {
271  pSelf = self;
272  if( pStream ) pStream->SetChannel( pSelf );
273  }

◆ Tick()

void XrdCl::Channel::Tick ( time_t  now)

Handle a time event.

Definition at line 154 of file XrdClChannel.cc.

155  {
156  pStream->Tick( now );
157  }

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