merge JSON-170 into default Release_2.1.0-RC14
authorRoker <roker@pep-project.org>
Mon, 26 Oct 2020 10:21:27 +0100
changeset 10835023c057076d
parent 1078 ce63fabab98e
parent 1082 7754d9ce8a54
child 1084 117d4353aca5
merge JSON-170 into default
     1.1 --- a/server/json-adapter.cc	Thu Oct 15 09:25:42 2020 +0200
     1.2 +++ b/server/json-adapter.cc	Mon Oct 26 10:21:27 2020 +0100
     1.3 @@ -70,7 +70,7 @@
     1.4  
     1.5  struct EventListenerValue
     1.6  {
     1.7 -	utility::locked_queue<js::Object> Q;
     1.8 +	std::shared_ptr<utility::locked_queue<js::Object>> Q = std::make_shared<utility::locked_queue<js::Object>>();;
     1.9  };
    1.10  
    1.11  static std::hash<std::thread::id> hash_tid;
    1.12 @@ -144,8 +144,8 @@
    1.13  		
    1.14  		for(auto& e : eventListener)
    1.15  		{
    1.16 -			Log << Logger::Debug << " ~~~ " << to_log(e.first)  << " has " << e.second.Q.size() << " old events waiting.";
    1.17 -			e.second.Q.push_back(request);
    1.18 +			Log << Logger::Debug << " ~~~ " << to_log(e.first)  << " has " << e.second.Q->size() << " old events waiting.";
    1.19 +			e.second.Q->push_back(request);
    1.20  		}
    1.21  	}
    1.22  	
    1.23 @@ -305,13 +305,15 @@
    1.24  void JsonAdapter::connection_close_cb()
    1.25  {
    1.26  	Lock L{_mtx};
    1.27 -	auto q = i->eventListener.find( std::this_thread::get_id() );
    1.28 -	Log() << "Connection Close Callback: " << (q==i->eventListener.end() ? "NO" : "1") << " entry in eventListener map";
    1.29 +	const auto tid = std::this_thread::get_id();
    1.30 +	auto q = i->eventListener.find( tid );
    1.31 +	i->Log << Logger::Debug << "Connection Close Callback: " << (q==i->eventListener.end() ? "NO" : "1") << " entry in eventListener map for Thread " << tid << ".";
    1.32  	if(q != i->eventListener.end())
    1.33  	{
    1.34 -		while(q->second.Q.waiting() > 0)
    1.35 +		i->Log.debug("%d listener(s) waiting on event queue", q->second.Q->waiting());
    1.36 +		while(q->second.Q->waiting() > 0)
    1.37  		{
    1.38 -			q->second.Q.push_back(queue_close_event);
    1.39 +			q->second.Q->push_back(queue_close_event);
    1.40  			std::this_thread::sleep_for( std::chrono::milliseconds(333) );
    1.41  		}
    1.42  		i->eventListener.erase(q);
    1.43 @@ -323,12 +325,13 @@
    1.44  {
    1.45  	Lock L{_mtx};
    1.46  	auto q = i->eventListener.find( session_id );
    1.47 -	Log() << "Close session \"" << session_id << "\": " << (q==i->eventListener.end() ? "NO" : "1") << " entry in eventListener map";
    1.48 +	i->Log << Logger::Debug << "Close session \"" << session_id << "\": " << (q==i->eventListener.end() ? "NO" : "1") << " entry in eventListener map for session_id \"" << session_id << "\".";
    1.49  	if(q != i->eventListener.end())
    1.50  	{
    1.51 -		while(q->second.Q.waiting() > 0)
    1.52 +		i->Log.debug("%d listener(s) waiting on event queue", q->second.Q->waiting());
    1.53 +		while(q->second.Q->waiting() > 0)
    1.54  		{
    1.55 -			q->second.Q.push_back(queue_close_event);
    1.56 +			q->second.Q->push_back(queue_close_event);
    1.57  			std::this_thread::sleep_for( std::chrono::milliseconds(333) );
    1.58  		}
    1.59  		i->eventListener.erase(q);
    1.60 @@ -389,17 +392,17 @@
    1.61  	Logger L("JAI:poll");
    1.62  
    1.63  	Lock LCK{_mtx};
    1.64 -	EventListenerValue& el = eventListener[key];  // adds an entry, if not already there. :-)
    1.65 +	auto elQ = eventListener[key].Q;  // adds an entry, if not already there. :-)
    1.66  	LCK.unlock();
    1.67  	
    1.68 -	const size_t size = el.Q.size();
    1.69 +	const size_t size = elQ->size();
    1.70  	if(size)
    1.71  	{
    1.72  		L << Logger::Debug << size << " events in queue for key " << to_log(key) << ":";
    1.73  		// fetch all elements from queue
    1.74  		for(size_t i=0; i<size; ++i)
    1.75  		{
    1.76 -			js::Object obj{ el.Q.pop_front() };
    1.77 +			js::Object obj{ elQ->pop_front() };
    1.78  			const std::string obj_s = js::write( obj );
    1.79  			L << Logger::Debug << "\t#" << i << ": " << obj_s;
    1.80  			
    1.81 @@ -409,7 +412,7 @@
    1.82  		// block until there is at least one element or timeout
    1.83  		L << Logger::Debug << "Queue for key " << to_log(key) << " is empty. I'll block for " << timeout_seconds << " seconds.";
    1.84  		js::Object event;
    1.85 -		const bool success = el.Q.try_pop_front( event, std::chrono::seconds(timeout_seconds) );
    1.86 +		const bool success = elQ->try_pop_front( event, std::chrono::seconds(timeout_seconds) );
    1.87  		if(success)
    1.88  		{
    1.89  			const std::string event_s = js::write(event);