9#include <tt/util/BlockingQueue.h>
10#include <tt/util/ThreadPool.h>
11#include <tt/util/CompletionEvent.h>
13#ifndef CLIENTFACTORY_H
14#define CLIENTFACTORY_H
68 virtual std::string
toString()
const;
209 explicit Operation(std::function<
void()> function,
ClientFactory& factory)
210 : function_(std::move(function)), factory_(factory)
221 uncaught_ = std::current_exception();
229 std::function<void()> function_;
230 std::exception_ptr uncaught_;
235 BlockingQueue<std::unique_ptr<Operation>> queue;
238 std::deque<client_ptr> waiting;
241 std::deque<client_ptr> running;
244 ThreadPool<Operation> tp;
250 std::exception_ptr uncaught =
nullptr;
253 std::mutex uncaughtMutex;
260 void captureException(
const char* stage);
266 CompletionEvent completion;
275 void createNewClient();
283 void onStop(
const Client* client);
286 std::atomic<bool> closeRequested_{
false};
A client factory continuously creates clients to connect to a server and is useful for deploying auto...
Definition ClientFactory.h:46
virtual client_ptr create() const =0
This method creates and returns a new client of the type produced by this factory.
ClientFactory()
Creates a new client factory with no upper limit on the number of clients that may run simultaneously...
Definition ClientFactory.cpp:16
virtual void onClose() const
This method is called once after this factory stops creating new clients and has begun shutting down.
Definition ClientFactory.h:179
void close()
Causes the factory to shut down gracefully, closing any waiting clients and waiting for any running c...
Definition ClientFactory.cpp:83
void execute()
This method starts the client factory, creates the first client, periodically creates new clients as ...
Definition ClientFactory.cpp:29
virtual void onStop() const
This method is called once at the end of this factory's shutdown process after all clients have stopp...
Definition ClientFactory.h:195
virtual std::string toString() const
Gives a string representation of this client factory.
Definition ClientFactory.cpp:21
friend std::ostream & operator<<(std::ostream &os, const ClientFactory &a)
Override stream insertion operator to allow printing the ClientFactory class.
virtual void onStart() const
This method is called once when this factory begins running.
Definition ClientFactory.h:152
ClientFactory(int maxClients)
Creates a new client factory with an upper limit on the number of clients that it will create simulta...
Definition ClientFactory.cpp:7
const int maxClients
The maximum number of clients that this factory will create to run simultaneously.
Definition ClientFactory.h:139
A client connects to a server to find a partner and play a role in a storytelling session.
Definition Client.h:51
Tandem Tales is a platform that enables short, paired storytelling exercises between two agents over ...
Definition Client.h:22
std::unique_ptr< Client > client_ptr
Alias for a pointer to a client to clean up code.
Definition ClientFactory.h:21
std::ostream & operator<<(std::ostream &os, const Client &a)
Override stream insertion operator to allow printing the Client class.
Definition Client.cpp:556