OpenSDN source code
xmpp_connection_manager.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
3  * Copyright Contributors to the OpenSDN project
4  */
5 
7 
8 #include <boost/bind/bind.hpp>
9 
10 #include "base/lifetime.h"
11 #include "base/task_annotations.h"
12 #include "xmpp/xmpp_session.h"
13 
14 using namespace boost::placeholders;
15 
16 //
17 // Constructor for XmppConnectionManager.
18 //
20  boost::asio::ssl::context::method m,
21  bool ssl_enabled, bool ssl_handshake_delayed)
22  : SslServer(evm, m, ssl_enabled, ssl_handshake_delayed),
23  session_queue_(TaskScheduler::GetInstance()->GetTaskId("bgp::Config"),
24  0, boost::bind(&XmppConnectionManager::DequeueSession, this, _1)) {
25 }
26 
27 //
28 // Shutdown the XmppConnectionManager.
29 //
30 // Register an exit callback to the session WorkQueue so that we can retry
31 // deletion when the WorkQueue becomes empty.
32 //
36  boost::bind(&XmppConnectionManager::WorkQueueExitCallback, this, _1));
38 }
39 
40 //
41 // Concurrency: called in the context of io thread.
42 //
43 // Add a XmppSession to the queue of write ready sessions.
44 // Take a reference to make sure that XmppSession doesn't get deleted before
45 // it's processed.
46 //
48  if (deleter()->IsDeleted())
49  return;
51 }
52 
53 //
54 // Concurrency: called in the context of bgp::Config task.
55 //
56 // Handler for XmppSessions that are dequeued from the session WorkQueue.
57 //
58 // The Xmpp[Client|Server] doesn't get destroyed if the WorkQueue is non-empty.
59 //
61  CHECK_CONCURRENCY("bgp::Config");
62  XmppSession *session = static_cast<XmppSession *>(tcp_session.get());
63  session->ProcessWriteReady();
64  return true;
65 }
66 
67 //
68 // Exit callback for the session WorkQueue.
69 //
71  CHECK_CONCURRENCY("bgp::Config");
72  if (!deleter()->IsDeleted())
73  return;
74  deleter()->RetryDelete();
75 }
76 
77 //
78 // Return size of WorkQueue of write ready XmppSessions.
79 //
81  CHECK_CONCURRENCY("bgp::Config");
82  return session_queue_.Length();
83 }
void RetryDelete()
Definition: lifetime.cc:74
The TaskScheduler keeps track of what tasks are currently schedulable. When a task is enqueued it is ...
Definition: task.h:307
void Shutdown()
Definition: tcp_server.cc:145
boost::intrusive_ptr< TcpSession > TcpSessionPtr
Definition: tcp_server.h:112
bool Enqueue(QueueEntryT entry)
Definition: queue_task.h:249
size_t Length() const
Definition: queue_task.h:357
void Shutdown(bool delete_entries=true)
Definition: queue_task.h:153
void SetExitCallback(TaskExitCallback on_exit)
Definition: queue_task.h:304
bool DequeueSession(TcpSessionPtr tcp_session)
XmppConnectionManager(EventManager *evm, boost::asio::ssl::context::method m, bool ssl_enabled, bool ssl_handshake_delayed)
WorkQueue< TcpSessionPtr > session_queue_
void WorkQueueExitCallback(bool done)
void EnqueueSession(XmppSession *session)
virtual LifetimeActor * deleter()=0
void ProcessWriteReady()
Definition: xmpp_session.cc:73
static EventManager evm
#define CHECK_CONCURRENCY(...)