Remoto - VFS: VFS_threadpool.cpp Source File
Remoto - VFS
VFS_threadpool.cpp
Go to the documentation of this file.
1 
2 #include "VFS_threadpool.h"
3 
4 #include <QCoreApplication>
5 
6 #include "VFS.h"
7 #include "VFS_creator.h"
8 #include "VFS_thread.h"
9 
35 const QStringList VFS_threadpool::modeStrings { "roundrobin", "available" };
36 
49 VFS_threadpool::VFS_threadpool(uint count, VFS_threadpool::mode mode, QDomElement nodeConfig, QVariantMap env, bool printConfig)
50 : VFS_node()
51 , _count(count)
52 , _index(0)
53 , _mode(mode)
54 {
55  VFS::LOG( QString(" -Creating thread pool '%1:%2'").arg(nodeConfig.tagName()).arg(nodeConfig.attribute("name")), 9 );
56 
57  QString nameTemplate = QString("%1:%2").arg(nodeConfig.attribute("name"));
58 
59  VFS_node *node;
60  QString name;
61 
62  for (uint i=0;i<_count;i++)
63  {
64  name = nameTemplate.arg(i);
65  nodeConfig.setAttribute("name",name);
66  node = new VFS_thread(nodeConfig, env, printConfig);
67  if (!append(name,node,false))
68  delete node;
69  }
70 }
71 
72 
78 {
79 }
80 
81 
88 {
89  return true;
90 }
91 
92 
104 {
105  QMutexLocker l(&_lock);
106 
107  QStringList keys = _children.keys();
108  VFS_node *n = nullptr;
109 
110  //printf("INDEX: %d\n",_index);
111 
112  switch (_mode)
113  {
115 
116 
118  n = _children[ keys[ _index ] ];
119  _index = (_index + 1) % _count; //round robin style
120  break;
121 
122  //default: break;
123  }
124 
125  if (n)
126  return n->find(r);
127  else
128  return nullptr;
129 }
130 
131 
141 {
142  Q_UNUSED(t)
143 
144  VFS::ERROR("threadpool::subtreeRequest should never be called. You have a bug in your code.");
145 }
146 
147 
157 {
158  Q_UNUSED(t)
159 
160  VFS::ERROR("threadpool::executeRequest should never be called. You have a bug in your code.");
161 }
162 
VFS_node is the base class from which all other VFS_node classes derive.
Definition: VFS_node.h:143
friend class VFS_thread
Definition: VFS_node.h:147
virtual VFS_node * append(QString name, VFS_node *node, bool containerCheck=true, QString user="server")
Append a VFS_node as a child of this node.
Definition: VFS_node.cpp:1566
VFS_children _children
This node's children.
Definition: VFS_node.h:179
VFS_node * find(QString path)
Find a node by string path.
Definition: VFS_node.cpp:1100
QMutex _lock
A recursive mutex that is local to this node.
Definition: VFS_node.h:178
The base class for all requests between nodes.
Definition: VFS_node.h:54
virtual void subtreeRequest(VFS_request *t) override
A dummy entry to override VFS_node::subtreeRequest()
Q_INVOKABLE VFS_threadpool(uint count, VFS_threadpool::mode mode, QDomElement nodeConfig, QVariantMap env, bool printConfig=false)
VFS_threadpool constructor.
VFS_threadpool::mode _mode
The distribution mode.
static const QStringList modeStrings
string names of each mode for the config file
mode
A pool will distribute requests based on a mode.
@ available
available mode will use the child with the fewest outstanding requests
@ roundrobin
roundrobin mode will cycle through children
uint _index
The current index for roundrobin requests.
virtual VFS_node * find(VFS_request *r) override
Distribute requests to children based on _mode.
virtual void executeRequest(VFS_request *t) override
A dummy entry to override VFS_node::executeRequest()
virtual bool isContainer() override
A threadpool is always a container.
virtual ~VFS_threadpool() override
VFS_threadpool destructor.
uint _count
The replication count.
static void LOG(QString message, int level=0, QString user="server")
Send a message to the VFS::_messages VFS_stream.
Definition: VFS.cpp:209
static void ERROR(QString message, int level=0, QString user="server")
Send a message to the VFS::_errors VFS_stream.
Definition: VFS.cpp:307