highlighter application  1.1
HCE project utils : highlighter
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
ComponentManagerPool.cpp
Go to the documentation of this file.
1 #include <Poco/ScopedLock.h>
2 
5 
6 namespace HCE
7 {
8  using namespace HCE::exception;
9  namespace component
10  {
11  void ComponentManagerPool::addManager(ComponentType componentType, Poco::SharedPtr<ComponentManager> cManagerPtr, bool _useCommonPool)
12  {
13  Poco::ScopedLock<Poco::FastMutex> sLock(globalComponentMutex);
14  ManagerIterator it = tManagerMap.find(componentType);
15  if(it != tManagerMap.end())
16  {
17  // exception - manager already exist
18  }
19  Poco::SharedPtr<Poco::ThreadPool> _threadPoolPtr;
20  if(!_useCommonPool)
21  {
22  _threadPoolPtr = Poco::SharedPtr<Poco::ThreadPool>(new Poco::ThreadPool());
23  cManagerPtr->setThreadPool(_threadPoolPtr);
24  }
25  Poco::ThreadPool &localPool = (_useCommonPool ? thPool : (*_threadPoolPtr));
26  cManagerPtr->setTaskManager(Poco::SharedPtr<Poco::TaskManager> (new Poco::TaskManager(localPool)));
27  tManagerMap[componentType] = cManagerPtr;
28  }
29 
30  Poco::SharedPtr<TaskWaitObject> ComponentManagerPool::addInData(Poco::SharedPtr<DataBase> inData)
31  {
32  Poco::ScopedLock<Poco::FastMutex> sLock(globalComponentMutex);
33  Poco::SharedPtr<TaskWaitObject> task = Poco::SharedPtr<TaskWaitObject>(new TaskWaitObject(inData));
34  ManagerIterator it = tManagerMap.find(inData->getType());
35  if(it == tManagerMap.end())
36  {
37  task->setOutData(NULL, HCECTE_EXP2, NULL);
38  }
39  else
40  {
41  (*it).second->addTask(task);
42  }
43  return task;
44  }
45 
47  {
48  Poco::ScopedLock<Poco::FastMutex> sLock(globalComponentMutex);
49  ManagerIterator it = tManagerMap.find(componentType);
50  if(it == tManagerMap.end())
51  {
52  throw ComponentNotFoundException("ComponentNotFound");
53  }
54  else
55  {
56  (*it).second->clearTaskQueue();
57  }
58  }
59 
60 
62  {
63  for(ManagerIterator it = tManagerMap.begin(); it != tManagerMap.end(); it++)
64  {
65  if((*it).second)
66  {
67  if(((*it).second)->isRunning())
68  {
69  ((*it).second)->stop();
70  ((*it).second)->join();
71  }
72  }
73  }
74  }
75  }
76 }