Ejemplo n.º 1
0
		void PrioNotificationBasedRunnable::run() {
			threadDebug();

			LOG_STREAM_DEBUG << thread.name() << ": bg thread started" << LE;
			try {
				Poco::Notification::Ptr pNf(queue.waitDequeueNotification());

				while (pNf) {

					Poco::Timestamp t;
					LOG_NAMED_STREAM_INFO(LOG_THREAD) << thread.name() << "(>): Accept notification '" << pNf->name() << "'" << LE;

					//quit notification
					QuitNotification::Ptr pQuitNf = pNf.cast<QuitNotification>();
					if (pQuitNf) {
						LOG_NAMED_STREAM_INFO(LOG_THREAD) << thread.name() << "(>): Quit" << LE;
						break;
					}

					this->processNotification(pNf);

				LOG_NAMED_STREAM_INFO(LOG_THREAD) << thread.name() << "(>): Process notification '" << pNf->name() << "' finished in " << t.elapsed() / 1000 << "ms" << LE;
				pNf = queue.waitDequeueNotification();
				LOG_NAMED_STREAM_INFO(LOG_THREAD) << thread.name() << "(>): After waitDequeueNotification, ptr: " << (long int) pNf.get() << LE;
				if (!pNf.isNull()) {
					LOG_NAMED_STREAM_INFO(LOG_THREAD) << thread.name() << "(>): After waitDequeueNotification, name: '" << pNf->name() << LE;
				}
			}
			LOG_NAMED_STREAM_INFO(LOG_THREAD) << thread.name() << "(>): Out from while cycle; ptr: " << (long int) pNf.get() << LE;
		} catch (Poco::Exception & e) {
			LOG_NAMED_STREAM_FATAL(LOG_THREAD) << thread.name() << ": Worker thread finished with exception " << e.displayText() << LE;
		} catch (std::runtime_error & e) {
			LOG_NAMED_STREAM_FATAL(LOG_THREAD) << thread.name() << ": Worker thread finished with std runtime exception " << e.what() << LE;
		} catch (std::exception & e) {
			LOG_NAMED_STREAM_FATAL(LOG_THREAD) << thread.name() << ": Worker thread finished with std exception " << e.what() << LE;
		} catch (...) {
			LOG_NAMED_STREAM_FATAL(LOG_THREAD) << thread.name() << ": Worker thread finished with unknown exception" << LE;
		}
		LOG_STREAM_DEBUG << thread.name() << ": bg thread finished" << LE;
	}
Ejemplo n.º 2
0
void SenderTask::runTask()
{
	_logger.debug("Starting SenderTask...");

	while(!isCancelled())
	{
		Poco::Notification::Ptr pNf(queue.waitDequeueNotification());
		if (pNf)
		{
			RedirectNotification::Ptr pRedirectNf = pNf.cast<RedirectNotification>();
			if (pRedirectNf)
			{
				if(pRedirectNf->is_rst())
					sender->SendRST(pRedirectNf->user_port(), pRedirectNf->dst_port(),pRedirectNf->user_ip(),pRedirectNf->dst_ip(), pRedirectNf->acknum(), pRedirectNf->seqnum(), pRedirectNf->f_psh());
				else
					sender->Redirect(pRedirectNf->user_port(), pRedirectNf->dst_port(),pRedirectNf->user_ip(),pRedirectNf->dst_ip(), pRedirectNf->acknum(), pRedirectNf->seqnum(), pRedirectNf->f_psh(), pRedirectNf->additional_param());
			}
		}
	}

	_logger.debug("Stopping SenderTask...");
}
Ejemplo n.º 3
0
void PktAnalyzer::run()
{
	_logger.debug("Starting thread...");
	for (;;)
	{
		Poco::Notification::Ptr pNf(_queue.waitDequeueNotification(_idleTime));
		if (pNf)
		{
			PktNotification::Ptr pPktNf = pNf.cast<PktNotification>();
			if (pPktNf)
			{
				analyzer(pPktNf->pkt());
			}
		}
		Poco::FastMutex::ScopedLock lock(_mutex);
		if(_stopped)
		{
			break;
		}
	}
	_logger.debug("Stopping thread...");
}
//----------------------------------------
//	main
//----------------------------------------
int main(int /*argc*/, char** /*argv*/)
{
	PrepareConsoleLogger logger(Poco::Logger::ROOT, Poco::Message::PRIO_INFORMATION);

	ScopedLogMessage msg("TimedNotificationQueueTest ", "start", "end");

	Poco::TimedNotificationQueue queue;

	Child child1("Child 1", queue, msg);
	Child child2("Child 2", queue, msg);
	Child child3("Child 3", queue, msg);

	Poco::ThreadPool::defaultPool().start(child1);
	Poco::ThreadPool::defaultPool().start(child2);
	Poco::ThreadPool::defaultPool().start(child3);

	int numDequeued = 0;
	while(numDequeued < Child::NumEnqueued())
	{
		Poco::Notification::Ptr pNf(queue.waitDequeueNotification());
		if(pNf)
		{
			Child::ChildNotificationPtr pChildNf = pNf.cast<ChildNotification>();
			if(pChildNf)
			{
				msg.Message(Poco::format("    got child notification #%d from %s (%s)"
											, pChildNf->data()
											, pChildNf->name()
											, pChildNf->datetime()));
				++numDequeued;
				Poco::Thread::sleep(kSleepTime);
			}
		}
		else break;
	}

	return 0;
}
Ejemplo n.º 5
0
void SyslogParser::run()
{
	poco_assert (_stopped);
	_stopped = false;
	while (!_stopped)
	{
		try
		{
			Poco::AutoPtr<Poco::Notification> pNf(_queue.waitDequeueNotification(WAITTIME_MILLISEC));
			if (pNf)
			{
				Poco::AutoPtr<MessageNotification> pMsgNf = pNf.cast<MessageNotification>();
				parse(pMsgNf->message());
			}
		}
		catch (Poco::Exception&)
		{
			// parsing exception, what should we do?
		}
		catch (...)
		{
		}
	}
}