Exemplo n.º 1
0
void ClearHistory::Stop()
{


	if (!_stopped) {

		_rdbmsClearHis->stop();

		_stopped = true;
		Poco::DateTime dataTime;
		dataTime +=	10;
		ClearQueue.enqueueNotification(new ClearNotofication(0 ),dataTime.timestamp());
		_thread.join();
		ClearQueue.clear();
		g_pClearHistory = NULL;
	}
}
Exemplo n.º 2
0
void ClearHistory::initialize(Poco::Util::Application & self)
{
	// TODO subscribe the data process from the rdbms
	//self.config().getString("");
	//redis连接设置
	_rtdbms_redis_ip = self.config().getString("RedisDB.Base.IPAddr","127.0.0.1");
	_rtdbms_redis_port = self.config().getInt("RedisDB.Base.Port", 6379);
	_rdbmsClearHis = new CRtDbMs(_rtdbms_redis_ip, _rtdbms_redis_port);
	ClearQueue.clear();

}
Exemplo n.º 3
0
void TimedNotificationQueueTest::testDequeue()
{
	TimedNotificationQueue queue;
	assert (queue.empty());
	assert (queue.size() == 0);
	Notification* pNf = queue.dequeueNotification();
	assertNullPtr(pNf);
	queue.enqueueNotification(new Notification, Timestamp());
	assert (!queue.empty());
	assert (queue.size() == 1);
	pNf = queue.dequeueNotification();
	assertNotNullPtr(pNf);
	assert (queue.empty());
	assert (queue.size() == 0);
	pNf->release();
	
	Poco::Timestamp ts1;
	ts1 += 100000;
	Poco::Timestamp ts2;
	ts2 += 200000;
	Poco::Timestamp ts3;
	ts3 += 300000;
	Poco::Timestamp ts4;
	ts4 += 400000;
	
	queue.enqueueNotification(new QTestNotification("first"), ts1);
	queue.enqueueNotification(new QTestNotification("fourth"), ts4);
	queue.enqueueNotification(new QTestNotification("third"), ts3);
	queue.enqueueNotification(new QTestNotification("second"), ts2);
	assert (!queue.empty());
	assert (queue.size() == 4);
	QTestNotification* pTNf = 0;
	while (!pTNf) 
	{
		pTNf = dynamic_cast<QTestNotification*>(queue.dequeueNotification());
	}
	assertNotNullPtr(pTNf);
	assert (pTNf->data() == "first");
	pTNf->release();
	assert (ts1.elapsed() >= 0);
	assert (!queue.empty());
	assert (queue.size() == 3);
	
	pTNf = 0;
	while (!pTNf) 
	{
		pTNf = dynamic_cast<QTestNotification*>(queue.dequeueNotification());
	}
	assertNotNullPtr(pTNf);
	assert (pTNf->data() == "second");
	pTNf->release();
	assert (ts2.elapsed() >= 0);
	assert (!queue.empty());
	assert (queue.size() == 2);
	
	pTNf = 0;
	while (!pTNf) 
	{
		pTNf = dynamic_cast<QTestNotification*>(queue.dequeueNotification());
	}
	assertNotNullPtr(pTNf);
	assert (pTNf->data() == "third");
	pTNf->release();
	assert (ts3.elapsed() >= 0);
	assert (!queue.empty());
	assert (queue.size() == 1);
	
	pTNf = 0;
	while (!pTNf) 
	{
		pTNf = dynamic_cast<QTestNotification*>(queue.dequeueNotification());
	}
	assertNotNullPtr(pTNf);
	assert (pTNf->data() == "fourth");
	pTNf->release();
	assert (ts4.elapsed() >= 0);
	assert (queue.empty());
	assert (queue.size() == 0);

	pNf = queue.dequeueNotification();
	assertNullPtr(pNf);
}
Exemplo n.º 4
0
void TimedNotificationQueueTest::testWaitDequeueTimeout()
{
	TimedNotificationQueue queue;
	
	Poco::Timestamp ts1;
	ts1 += 200000;
	Poco::Timestamp ts2;
	ts2 += 400000;
	Poco::Timestamp ts3;
	ts3 += 600000;
	Poco::Timestamp ts4;
	ts4 += 800000;
	
	queue.enqueueNotification(new QTestNotification("first"), ts1);
	queue.enqueueNotification(new QTestNotification("fourth"), ts4);
	queue.enqueueNotification(new QTestNotification("third"), ts3);
	queue.enqueueNotification(new QTestNotification("second"), ts2);
	assert (!queue.empty());
	assert (queue.size() == 4);
	QTestNotification* pTNf = dynamic_cast<QTestNotification*>(queue.waitDequeueNotification(10));
	assertNullPtr(pTNf);
	pTNf = dynamic_cast<QTestNotification*>(queue.waitDequeueNotification(20));
	assertNullPtr(pTNf);
	pTNf = dynamic_cast<QTestNotification*>(queue.waitDequeueNotification(200));
	assertNotNullPtr(pTNf);
	assert (pTNf->data() == "first");
	pTNf->release();
	assert (ts1.elapsed() >= 0);
	assert (!queue.empty());
	assert (queue.size() == 3);
	
	pTNf = dynamic_cast<QTestNotification*>(queue.waitDequeueNotification(220));
	assertNotNullPtr(pTNf);
	assert (pTNf->data() == "second");
	pTNf->release();
	assert (ts2.elapsed() >= 0);
	assert (!queue.empty());
	assert (queue.size() == 2);
	
	pTNf = dynamic_cast<QTestNotification*>(queue.waitDequeueNotification(220));
	assertNotNullPtr(pTNf);
	assert (pTNf->data() == "third");
	pTNf->release();
	assert (ts3.elapsed() >= 0);
	assert (!queue.empty());
	assert (queue.size() == 1);
	
	pTNf = dynamic_cast<QTestNotification*>(queue.waitDequeueNotification(220));
	assertNotNullPtr(pTNf);
	assert (pTNf->data() == "fourth");
	pTNf->release();
	assert (ts1.elapsed() >= 0);
	assert (queue.empty());
	assert (queue.size() == 0);
}
Exemplo n.º 5
0
void ClearHistory::run()
{
	UarcRmemdServer::GetLogger().information("ClearHistory Process is running!");
	//1.获取当前时间
	time_t thistime;
	thistime = time(NULL);
	std::string TimeChar = "";
	g_pClearHistory->TimeToChar(thistime, TimeChar);
	UarcRmemdServer::GetLogger().information("首次执行,当前时间为:%s", TimeChar);


	//2.计算下次清除时间
	int nClearTime = g_pClearHistory->nextClearTime(thistime);

	long int timedeff = 0;
	timedeff = nClearTime - (long int) thistime;
	Poco::DateTime dataTime;
	dataTime += timedeff*1000000;

	//加入清除队列
	g_pClearHistory->TimeToChar(nClearTime,TimeChar);
	ClearQueue.enqueueNotification(new ClearNotofication(nClearTime),dataTime.timestamp());
	UarcRmemdServer::GetLogger().information("首次执行,设置下次清除数据时间为:%s", TimeChar);
	printf("首次执行,设置下次清除数据时间为:%s\n", TimeChar.c_str());
	while (!_stopped)
	{

		//1.等待清除任务时刻的到来
		Poco::Notification::Ptr pNf(ClearQueue.waitDequeueNotification());
		if (_stopped)
		{
			return ;
		}
		if(pNf)
		{
			//ClearNotofication* pSNf = pNf.cast<ClearNotofication> ();
			//2先设置下次清除时间
			time_t thistime;
			thistime = time(NULL);
			std::string TimeChar = "";
			g_pClearHistory->TimeToChar(thistime, TimeChar);

			UarcRmemdServer::GetLogger().information("清除%s 时刻的定时任务",TimeChar);


			//3.计算下次清除时间
			int nClearTime = g_pClearHistory->nextClearTime(thistime);
			long int timedeff = 0;
			timedeff = nClearTime - (long int) thistime;
			Poco::DateTime dataTime;
			dataTime += timedeff*1000000;
			//4再加入清除队列
			g_pClearHistory->TimeToChar(nClearTime,TimeChar);
			ClearQueue.enqueueNotification(new ClearNotofication(nClearTime ),dataTime.timestamp());

			UarcRmemdServer::GetLogger().information("设置下次清除数据时间为:%s", TimeChar);
			//5此时执行清除处理
			Clearstwch.restart();
			bool bCleard = false;
			bCleard = _rdbmsClearHis->clearHisData();
			Clearstwch.stop();
			if (bCleard == true)
			{
			 UarcRmemdServer::GetLogger().information("清除历史数据成功,用时%d 秒",(int)Clearstwch.elapsedSeconds());
			}
			else
			{
				UarcRmemdServer::GetLogger().information("清除历史数据失败,用时%d 秒",(int)Clearstwch.elapsedSeconds());
				UarcRmemdServer::GetLogger().information("再次调用清除命令");
				bCleard = _rdbmsClearHis->clearHisData();
				if (bCleard == true)
				{
					UarcRmemdServer::GetLogger().information("再次清除历史数据并且成功被清除");
				}
				else
				{
					UarcRmemdServer::GetLogger().information("连续两次清除历史均失败");
				}
			}

		}
	}
	UarcRmemdServer::GetLogger().information("ClearHistory Process quit!", __FILE__,	__LINE__);
}