The ObjectBox Sync Server to run within your application (embedded server). Note that you need a special sync edition, which includes the server components. Check https://objectbox.io/sync/. More...
#include <objectbox-sync.hpp>
Public Member Functions | |
SyncServer (Options &storeOptions, const std::string &url) | |
Prepares an ObjectBox Sync Server to run within your application (embedded server) at the given URI. This call opens a store with the given options (as Store() does). Get it via store(). The server's store is tied to the server itself and is closed when the server is closed. Before actually starting the server via start(), you can configure: More... | |
SyncServer (Options &&storeOptions, const std::string &url) | |
Rvalue variant of SyncServer(Options& storeOptions, const std::string& url) that works equivalently. More... | |
SyncServer (Options &storeOptions, const void *flatOptions, size_t flatOptionsSize) | |
SyncServer (Options &&storeOptions, const void *flatOptions, size_t flatOptionsSize) | |
Rvalue variant of SyncServer(Options& storeOptions, const void* flatOptions, size_t flatOptionsSize) that works equivalently. More... | |
SyncServer (SyncServer &&source) noexcept | |
SyncServer (const SyncServer &)=delete | |
Can't be copied, single owner of C resources is required (to avoid double-free during destruction) More... | |
~SyncServer () override | |
Store & | store () |
The store that is associated with this server. More... | |
void | close () final |
Closes and cleans up all resources used by this sync server. Does nothing if already closed. It can no longer be used afterwards, make a new sync server instead. More... | |
bool | isClosed () override |
Returns if this sync server is closed and can no longer be used. More... | |
void | setCertificatePath (const std::string &path) |
Sets SSL certificate for the server to use. Use before start(). More... | |
void | setCredentials (const SyncCredentials &creds) |
Sets credentials for the server to accept. Use before start(). More... | |
void | enableAuthenticationType (OBXSyncCredentialsType type) |
Sets credentials for the server to accept. Use before start(). More... | |
void | setWorkerThreads (int threadCount) |
Sets the number of worker threads. Calll before start(). More... | |
void | setHistoryMaxSizeKb (uint64_t maxSizeKb, uint64_t targetSizeKb=0) |
Sets a maximum size for sync history entries to limit storage: old entries are removed to stay below this limit. Deleting older history entries may require clients to do a full sync if they have not contacted the server for a certain time. More... | |
void | start () |
Once the sync server is configured, you can "start" it to start accepting client connections. This method triggers communication in the background and will return immediately. More... | |
void | stop () |
Stops this sync server. Does nothing if it is already stopped. More... | |
bool | isRunning () |
Returns if this sync server is running. More... | |
std::string | url () |
Returns a URL this server is listening on, including the bound port (see port(). More... | |
uint16_t | port () |
Returns a port this server listens on. This is especially useful if the bindUri given to the constructor specified "0" port (i.e. automatic assignment). More... | |
uint64_t | connections () |
Returns the number of clients connected to this server. More... | |
std::string | statsString (bool includeZeroValues=true) |
Get server runtime statistics. More... | |
uint64_t | statsValueU64 (OBXSyncServerStats counterType) |
Get u64 value for sync server statistics. More... | |
double | statsValueF64 (OBXSyncServerStats counterType) |
Get double value for sync server statistics. More... | |
void | setChangeListener (std::shared_ptr< SyncChangeListener > listener) |
void | setObjectsMessageListener (std::shared_ptr< SyncObjectsMessageListener > listener) |
void | send (SyncObjectsMessageBuilder &&message) |
Broadcast the given 'objects message' from the server to all currently connected (and logged-in) clients. More... | |
OBX_sync_server * | cPtr () const |
Public Member Functions inherited from obx::Closable | |
virtual | ~Closable ()=default |
Static Public Member Functions | |
static bool | isAvailable () |
The ObjectBox Sync Server to run within your application (embedded server). Note that you need a special sync edition, which includes the server components. Check https://objectbox.io/sync/.
|
inlineexplicit |
Prepares an ObjectBox Sync Server to run within your application (embedded server) at the given URI. This call opens a store with the given options (as Store() does). Get it via store(). The server's store is tied to the server itself and is closed when the server is closed. Before actually starting the server via start(), you can configure:
storeOptions | Options for the server's store. Will be "consumed"; do not use the Options object again. |
url | The URL (following the pattern protocol:://IP:port) the server should listen on. Supported protocols are "ws" (WebSockets) and "wss" (secure WebSockets). To use the latter ("wss"), you must also call obx_sync_server_certificate_path(). To bind to all available interfaces, including those that are available from the "outside", use 0.0.0.0 as the IP. On the other hand, "127.0.0.1" is typically (may be OS dependent) only available on the same device. If you do not require a fixed port, use 0 (zero) as a port to tell the server to pick an arbitrary port that is available. The port can be queried via obx_sync_server_port() once the server was started. Examples: "ws://0.0.0.0:9999" could be used during development (no certificate config needed), while in a production system, you may want to use wss and a specific IP for security reasons. |
|
inlineexplicit |
Rvalue variant of SyncServer(Options& storeOptions, const std::string& url) that works equivalently.
|
inlineexplicit |
|
inlineexplicit |
Rvalue variant of SyncServer(Options& storeOptions, const void* flatOptions, size_t flatOptionsSize) that works equivalently.
|
inlinenoexcept |
|
delete |
Can't be copied, single owner of C resources is required (to avoid double-free during destruction)
|
inlineoverride |
|
inlinefinalvirtual |
Closes and cleans up all resources used by this sync server. Does nothing if already closed. It can no longer be used afterwards, make a new sync server instead.
Implements obx::Closable.
|
inline |
Returns the number of clients connected to this server.
|
inline |
|
inline |
Sets credentials for the server to accept. Use before start().
data | may be NULL in combination with OBXSyncCredentialsType_NONE |
|
inlinestatic |
|
inlineoverridevirtual |
Returns if this sync server is closed and can no longer be used.
Implements obx::Closable.
|
inline |
Returns if this sync server is running.
|
inline |
Returns a port this server listens on. This is especially useful if the bindUri given to the constructor specified "0" port (i.e. automatic assignment).
|
inline |
Broadcast the given 'objects message' from the server to all currently connected (and logged-in) clients.
|
inline |
Sets SSL certificate for the server to use. Use before start().
|
inline |
|
inline |
Sets credentials for the server to accept. Use before start().
data | may be NULL in combination with OBXSyncCredentialsType_NONE |
|
inline |
Sets a maximum size for sync history entries to limit storage: old entries are removed to stay below this limit. Deleting older history entries may require clients to do a full sync if they have not contacted the server for a certain time.
maxSizeKb | Once this maximum size is reached, old history entries are deleted (default 0: no limit). |
targetSizeKb | If this value is non-zero, the deletion of old history entries is extended until reaching this target (lower than the maximum) allowing deletion "batching", which may be more efficient. If zero, the deletion stops already stops when reaching the max size (or lower). |
|
inline |
|
inline |
Sets the number of worker threads. Calll before start().
thread_count | The default is "0" which is hardware dependent, e.g. a multiple of CPU "cores". |
|
inline |
Once the sync server is configured, you can "start" it to start accepting client connections. This method triggers communication in the background and will return immediately.
|
inline |
Get server runtime statistics.
|
inline |
Get double value for sync server statistics.
|
inline |
Get u64 value for sync server statistics.
|
inline |
Stops this sync server. Does nothing if it is already stopped.
|
inline |
The store that is associated with this server.
|
inline |
Returns a URL this server is listening on, including the bound port (see port().
std::shared_ptr<SyncChangeListener> obx::SyncServer::change |
std::mutex obx::SyncServer::mutex |
std::shared_ptr<SyncObjectsMessageListener> obx::SyncServer::object |