Queue all requests until the AS is fully setup

This commit is contained in:
Atlante45 2018-02-14 16:49:12 -08:00
parent ce93b9a1f4
commit 4482f9c83c
3 changed files with 47 additions and 8 deletions

View file

@ -257,12 +257,10 @@ AssetServer::AssetServer(ReceivedMessage& message) :
_transferTaskPool.setMaxThreadCount(TASK_POOL_THREAD_COUNT);
_bakingTaskPool.setMaxThreadCount(1);
// Queue all requests until the Asset Server is fully setup
auto& packetReceiver = DependencyManager::get<NodeList>()->getPacketReceiver();
packetReceiver.registerListener(PacketType::AssetGet, this, "handleAssetGet");
packetReceiver.registerListener(PacketType::AssetGetInfo, this, "handleAssetGetInfo");
packetReceiver.registerListener(PacketType::AssetUpload, this, "handleAssetUpload");
packetReceiver.registerListener(PacketType::AssetMappingOperation, this, "handleAssetMappingOperation");
packetReceiver.registerListenerForTypes({ PacketType::AssetGet, PacketType::AssetGetInfo, PacketType::AssetUpload, PacketType::AssetMappingOperation }, this, "queueRequests");
#ifdef Q_OS_WIN
updateConsumedCores();
QTimer* timer = new QTimer(this);
@ -417,6 +415,43 @@ void AssetServer::completeSetup() {
PathUtils::removeTemporaryApplicationDirs();
PathUtils::removeTemporaryApplicationDirs("Oven");
// We're fully setup, remove the request queueing and replay all requests
auto& packetReceiver = DependencyManager::get<NodeList>()->getPacketReceiver();
packetReceiver.unregisterListener(this);
packetReceiver.registerListener(PacketType::AssetGet, this, "handleAssetGet");
packetReceiver.registerListener(PacketType::AssetGetInfo, this, "handleAssetGetInfo");
packetReceiver.registerListener(PacketType::AssetUpload, this, "handleAssetUpload");
packetReceiver.registerListener(PacketType::AssetMappingOperation, this, "handleAssetMappingOperation");
replayRequests();
}
void AssetServer::queueRequests(QSharedPointer<ReceivedMessage> packet, SharedNodePointer senderNode) {
_queuedRequests.push_back({ packet, senderNode });
}
void AssetServer::replayRequests() {
for (const auto& request : _queuedRequests) {
switch (request.first->getType()) {
case PacketType::AssetGet:
handleAssetGet(request.first, request.second);
break;
case PacketType::AssetGetInfo:
handleAssetGetInfo(request.first, request.second);
break;
case PacketType::AssetUpload:
handleAssetUpload(request.first, request.second);
break;
case PacketType::AssetMappingOperation:
handleAssetMappingOperation(request.first, request.second);
break;
default:
qWarning() << "Unknown queued request type:" << request.first->getType();
break;
}
}
_queuedRequests.clear();
}
void AssetServer::cleanupUnmappedFiles() {

View file

@ -49,6 +49,7 @@ public slots:
private slots:
void completeSetup();
void queueRequests(QSharedPointer<ReceivedMessage> packet, SharedNodePointer senderNode);
void handleAssetGetInfo(QSharedPointer<ReceivedMessage> packet, SharedNodePointer senderNode);
void handleAssetGet(QSharedPointer<ReceivedMessage> packet, SharedNodePointer senderNode);
void handleAssetUpload(QSharedPointer<ReceivedMessage> packetList, SharedNodePointer senderNode);
@ -57,6 +58,8 @@ private slots:
void sendStatsPacket() override;
private:
void replayRequests();
void handleGetMappingOperation(ReceivedMessage& message, NLPacketList& replyPacket);
void handleGetAllMappingOperation(NLPacketList& replyPacket);
void handleSetMappingOperation(ReceivedMessage& message, bool hasWriteAccess, NLPacketList& replyPacket);
@ -120,6 +123,8 @@ private:
QHash<AssetUtils::AssetHash, std::shared_ptr<BakeAssetTask>> _pendingBakes;
QThreadPool _bakingTaskPool;
QVector<QPair<QSharedPointer<ReceivedMessage>, SharedNodePointer>> _queuedRequests;
bool _wasColorTextureCompressionEnabled { false };
bool _wasGrayscaleTextureCompressionEnabled { false };
bool _wasNormalTextureCompressionEnabled { false };

View file

@ -46,9 +46,8 @@ BackupSupervisor::BackupSupervisor(const QString& backupDirectory) :
auto nodeList = DependencyManager::get<LimitedNodeList>();
QObject::connect(nodeList.data(), &LimitedNodeList::nodeAdded, this, [this](SharedNodePointer node) {
if (node->getType() == NodeType::AssetServer) {
// Give the Asset Server some time to bootup.
static constexpr int ASSET_SERVER_BOOTUP_MARGIN = 1 * 1000;
_mappingsRefreshTimer.start(ASSET_SERVER_BOOTUP_MARGIN);
// run immediately for the first time.
_mappingsRefreshTimer.start(0);
}
});
}