19 using std::unique_ptr;
34 threadPool(threadPool),
35 startUpBarrier(startUpBarrier) {
43 Console::println(
"ServerWorkerThread[" + to_string(
id) +
"]::run(): start");
52 if (request ==
nullptr)
break;
54 auto requestType = request->getRequestType();
61 client =
static_cast<ServerClient*
>(request->getObject());
62 auto packet = unique_ptr<const UDPPacket>(request->getMessagePacket());
63 auto messageId = request->getMessageId();
64 auto retries = request->getMessageRetries();
68 client->
onRequest(packet.get(), messageId, retries);
71 "ServerWorkerThread[" +
73 "]::run(): client: request: " +
74 (RTTI::demangle(
typeid(exception).
name())) +
87 client =
static_cast<ServerClient*
>(request->getObject());
93 "ServerWorkerThread[" +
95 "]::run(): client: init: " +
96 (RTTI::demangle(
typeid(exception).
name())) +
104 client =
static_cast<ServerClient*
>(request->getObject());
110 "ServerWorkerThread[" +
112 "]::run(): client: close: " +
113 (RTTI::demangle(
typeid(exception).
name())) +
121 client =
static_cast<ServerClient*
>(request->getObject());
124 client->
onCustom(request->getCustomEvent());
127 "ServerWorkerThread[" +
129 "]::run(): client: custom: " +
130 (RTTI::demangle(
typeid(exception).
name())) +
144 "ServerWorkerThread[" +
146 "]::run(): group: init: " +
147 (RTTI::demangle(
typeid(exception).
name())) +
161 "ServerWorkerThread[" +
163 "]::run(): group: close: " +
164 (RTTI::demangle(
typeid(exception).
name())) +
178 "ServerWorkerThread[" +
180 "]::run(): group: custom: " +
181 (RTTI::demangle(
typeid(exception).
name())) +
196 Console::println(
"ServerWorkerThread[" + to_string(
id) +
"]::run(): done");
Base class for network server clients.
virtual void shutdown()=0
Shuts down this network client.
virtual void onRequest(const UDPPacket *packet, const uint32_t messageId, const uint8_t retries)=0
To be overwritten with a request handler, will be called from worker.
virtual void onCustom(const string &type)=0
Base class for network server group.
virtual void onCustomEvent(const string &type)=0
Base class for network server groups.
@ REQUESTTYPE_GROUP_CUSTOM
@ REQUESTTYPE_GROUP_CLOSE
@ REQUESTTYPE_CLIENT_INIT
@ REQUESTTYPE_CLIENT_CUSTOM
@ REQUESTTYPE_CLIENT_CLOSE
@ REQUESTTYPE_CLIENT_REQUEST
Simple server worker thread pool class.
void run()
Thread run method.
ServerWorkerThreadPool * threadPool
virtual ~ServerWorkerThread()
Public destructor.
bool wait()
Waits on barrier.
T * getElement()
Gets an element from this queue, if no element exists yet the calling thread will be blocked until an...
Run time type information utility class.
virtual void releaseReference()
Releases a reference, thus decrementing the counter and delete it if reference counter is zero.
std::exception Exception
Exception base class.