XRootD
Loading...
Searching...
No Matches
XrdClOutQueue.cc
Go to the documentation of this file.
1//------------------------------------------------------------------------------
2// Copyright (c) 2011-2012 by European Organization for Nuclear Research (CERN)
3// Author: Lukasz Janyst <ljanyst@cern.ch>
4//------------------------------------------------------------------------------
5// XRootD is free software: you can redistribute it and/or modify
6// it under the terms of the GNU Lesser General Public License as published by
7// the Free Software Foundation, either version 3 of the License, or
8// (at your option) any later version.
9//
10// XRootD is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
14//
15// You should have received a copy of the GNU Lesser General Public License
16// along with XRootD. If not, see <http://www.gnu.org/licenses/>.
17//------------------------------------------------------------------------------
18
21
22namespace XrdCl
23{
24 //----------------------------------------------------------------------------
25 // Add a message to the back of the queue
26 //----------------------------------------------------------------------------
28 MsgHandler *handler,
29 time_t expires,
30 bool stateful )
31 {
32 pMessages.push_back( MsgHelper( msg, handler, expires, stateful ) );
33 }
34
35 //----------------------------------------------------------------------------
36 // Add a message to the front the queue
37 //----------------------------------------------------------------------------
39 MsgHandler *handler,
40 time_t expires,
41 bool stateful )
42 {
43 pMessages.push_front( MsgHelper( msg, handler, expires, stateful ) );
44 }
45
46 //----------------------------------------------------------------------------
48 //----------------------------------------------------------------------------
50 time_t &expires,
51 bool &stateful )
52 {
53 if( pMessages.empty() )
54 return 0;
55
56 MsgHelper m = pMessages.front();
57 handler = m.handler;
58 expires = m.expires;
59 stateful = m.stateful;
60 pMessages.pop_front();
61 return m.msg;
62 }
63
64 //----------------------------------------------------------------------------
65 // Remove a message from the front
66 //----------------------------------------------------------------------------
68 {
69 pMessages.pop_front();
70 }
71
72 //----------------------------------------------------------------------------
73 // Report status to all handlers
74 //----------------------------------------------------------------------------
76 {
77 MessageList::iterator it;
78 for( it = pMessages.begin(); it != pMessages.end(); ++it )
79 it->handler->OnStatusReady( it->msg, status );
80 }
81
82 //------------------------------------------------------------------------
83 // Return the size of the queue counting only the stateless messages
84 //------------------------------------------------------------------------
86 {
87 uint64_t size = 0;
88 MessageList::const_iterator it;
89 for( it = pMessages.begin(); it != pMessages.end(); ++it )
90 if( !it->stateful )
91 ++size;
92 return size;
93 }
94
95 //----------------------------------------------------------------------------
96 // Remove all the expired messages from the queue and put them in
97 // this one
98 //----------------------------------------------------------------------------
99 void OutQueue::GrabExpired( OutQueue &queue, time_t exp )
100 {
101 MessageList::iterator it;
102 for( it = queue.pMessages.begin(); it != queue.pMessages.end(); )
103 {
104 if( it->expires > exp )
105 {
106 ++it;
107 continue;
108 }
109 pMessages.push_back( *it );
110 it = queue.pMessages.erase( it );
111 }
112 }
113
114 //----------------------------------------------------------------------------
115 // Remove all the stateful messages from the queue and put them in this
116 // one
117 //----------------------------------------------------------------------------
119 {
120 MessageList::iterator it;
121 for( it = queue.pMessages.begin(); it != queue.pMessages.end(); )
122 {
123 if( !it->stateful )
124 {
125 ++it;
126 continue;
127 }
128 pMessages.push_back( *it );
129 it = queue.pMessages.erase( it );
130 }
131 }
132
133 //----------------------------------------------------------------------------
134 // Take all the items from the queue and put them in this one
135 //----------------------------------------------------------------------------
137 {
138 MessageList::iterator it;
139 for( it = queue.pMessages.begin(); it != queue.pMessages.end(); ++it )
140 pMessages.push_back( *it );
141 queue.pMessages.clear();
142 }
143}
144
The message representation used throughout the system.
A synchronized queue for the outgoing data.
void PushFront(Message *msg, MsgHandler *handler, time_t expires, bool stateful)
void GrabStateful(OutQueue &queue)
void PopFront()
Remove a message from the front.
void GrabExpired(OutQueue &queue, time_t exp=0)
void GrabItems(OutQueue &queue)
Message * PopMessage(MsgHandler *&handler, time_t &expires, bool &stateful)
Get a message from the front of the queue.
void PushBack(Message *msg, MsgHandler *handler, time_t expires, bool stateful)
void Report(XRootDStatus status)
Report status to all the handlers.
uint64_t GetSizeStateless() const
Return the size of the queue counting only the stateless messages.