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