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  */
4 
6 
7 #include <boost/bind/bind.hpp>
8 
9 #include "base/lifetime.h"
10 #include "base/task_annotations.h"
11 #include "xmpp/xmpp_session.h"
12 
13 using namespace boost::placeholders;
14 
15 //
16 // Constructor for XmppConnectionManager.
17 //
19  boost::asio::ssl::context::method m,
20  bool ssl_enabled, bool ssl_handshake_delayed)
21  : SslServer(evm, m, ssl_enabled, ssl_handshake_delayed),
22  session_queue_(TaskScheduler::GetInstance()->GetTaskId("bgp::Config"),
23  0, boost::bind(&XmppConnectionManager::DequeueSession, this, _1)) {
24 }
25 
26 //
27 // Shutdown the XmppConnectionManager.
28 //
29 // Register an exit callback to the session WorkQueue so that we can retry
30 // deletion when the WorkQueue becomes empty.
31 //
35  boost::bind(&XmppConnectionManager::WorkQueueExitCallback, this, _1));
37 }
38 
39 //
40 // Concurrency: called in the context of io thread.
41 //
42 // Add a XmppSession to the queue of write ready sessions.
43 // Take a reference to make sure that XmppSession doesn't get deleted before
44 // it's processed.
45 //
47  if (deleter()->IsDeleted())
48  return;
50 }
51 
52 //
53 // Concurrency: called in the context of bgp::Config task.
54 //
55 // Handler for XmppSessions that are dequeued from the session WorkQueue.
56 //
57 // The Xmpp[Client|Server] doesn't get destroyed if the WorkQueue is non-empty.
58 //
60  CHECK_CONCURRENCY("bgp::Config");
61  XmppSession *session = static_cast<XmppSession *>(tcp_session.get());
62  session->ProcessWriteReady();
63  return true;
64 }
65 
66 //
67 // Exit callback for the session WorkQueue.
68 //
70  CHECK_CONCURRENCY("bgp::Config");
71  if (!deleter()->IsDeleted())
72  return;
73  deleter()->RetryDelete();
74 }
75 
76 //
77 // Return size of WorkQueue of write ready XmppSessions.
78 //
80  CHECK_CONCURRENCY("bgp::Config");
81  return session_queue_.Length();
82 }
void RetryDelete()
Definition: lifetime.cc:73
The TaskScheduler keeps track of what tasks are currently schedulable. When a task is enqueued it is ...
Definition: task.h:304
void Shutdown()
Definition: tcp_server.cc:144
boost::intrusive_ptr< TcpSession > TcpSessionPtr
Definition: tcp_server.h:111
bool Enqueue(QueueEntryT entry)
Definition: queue_task.h:248
size_t Length() const
Definition: queue_task.h:356
void Shutdown(bool delete_entries=true)
Definition: queue_task.h:152
void SetExitCallback(TaskExitCallback on_exit)
Definition: queue_task.h:303
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:72
static EventManager evm
#define CHECK_CONCURRENCY(...)