| 1 |
/* |
| 2 |
* Copyright (C) 2013-2015, 2019 by the Konclude Developer Team. |
| 3 |
* |
| 4 |
* This file is part of the reasoning system Konclude. |
| 5 |
* For details and support, see <http://konclude.com/>. |
| 6 |
* |
| 7 |
* Konclude is free software: you can redistribute it and/or modify |
| 8 |
* it under the terms of version 3 of the GNU Lesser General Public |
| 9 |
* License (LGPLv3) as published by the Free Software Foundation. |
| 10 |
* |
| 11 |
* Konclude is distributed in the hope that it will be useful, |
| 12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 |
* GNU (Lesser) General Public License for more details. |
| 15 |
* |
| 16 |
* You should have received a copy of the GNU (Lesser) General Public |
| 17 |
* License along with Konclude. If not, see <http://www.gnu.org/licenses/>. |
| 18 |
* |
| 19 |
*/ |
| 20 |
|
| 21 |
#include "CSPARQLHttpConnectionHandlerProcessorFactory.h" |
| 22 |
|
| 23 |
|
| 24 |
namespace Konclude { |
| 25 |
|
| 26 |
namespace Control { |
| 27 |
|
| 28 |
namespace Interface { |
| 29 |
|
| 30 |
namespace SPARQL { |
| 31 |
|
| 32 |
|
| 33 |
CSPARQLHttpConnectionHandlerProcessorFactory::CSPARQLHttpConnectionHandlerProcessorFactory(CConfiguration* loaderConfig) { |
| 34 |
mLoaderConfig = loaderConfig; |
| 35 |
mHandlerReleased = false; |
| 36 |
} |
| 37 |
|
| 38 |
|
| 39 |
CSPARQLHttpConnectionHandlerProcessorFactory::~CSPARQLHttpConnectionHandlerProcessorFactory() { |
| 40 |
qDeleteAll(mContainerList); |
| 41 |
} |
| 42 |
|
| 43 |
CQtHttpConnectionHandler* CSPARQLHttpConnectionHandlerProcessorFactory::getConnectionHandler() { |
| 44 |
CSPARQLHttpConnectionHandlerProcessor* connHandler = nullptr; |
| 45 |
|
| 46 |
if (mHandlerReleased && mFreeHandlerList.isEmpty()) { |
| 47 |
for (QList<CSPARQLHttpConnectionHandlerProcessor*>::const_iterator it = mContainerList.constBegin(); it != mContainerList.constEnd(); ++it) { |
| 48 |
CSPARQLHttpConnectionHandlerProcessor* handler(*it); |
| 49 |
if (!handler->isHandlerBusy()) { |
| 50 |
if (!handler->isHandlerQueued()) { |
| 51 |
handler->setHandlerQueued(true); |
| 52 |
mFreeHandlerList.append(handler); |
| 53 |
} |
| 54 |
} |
| 55 |
} |
| 56 |
mHandlerReleased = false; |
| 57 |
} |
| 58 |
|
| 59 |
if (!connHandler && !mFreeHandlerList.isEmpty()) { |
| 60 |
connHandler = mFreeHandlerList.takeFirst(); |
| 61 |
connHandler->setHandlerQueued(false); |
| 62 |
} |
| 63 |
|
| 64 |
|
| 65 |
if (!connHandler) { |
| 66 |
connHandler = new CSPARQLHttpConnectionHandlerProcessor(mLoaderConfig,this); |
| 67 |
connHandler->waitSynchronization(); |
| 68 |
connHandler->setHandlerQueued(false); |
| 69 |
mContainerList.append(connHandler); |
| 70 |
} |
| 71 |
return connHandler; |
| 72 |
} |
| 73 |
|
| 74 |
|
| 75 |
CQtHttpConnectionHandlerReleaser* CSPARQLHttpConnectionHandlerProcessorFactory::releaseConnectionHandler(CQtHttpConnectionHandler* connectionHandler) { |
| 76 |
mHandlerReleased = true; |
| 77 |
return this; |
| 78 |
} |
| 79 |
|
| 80 |
|
| 81 |
}; // end namespace SPARQL |
| 82 |
|
| 83 |
}; // end namespace Interface |
| 84 |
|
| 85 |
}; // end namespace Control |
| 86 |
|
| 87 |
}; // end namespace Konclude |