Add the ability to override the server that's used by a given sync session
This is for internal use by ROS as part of its support for failover. If the session is active, we ask it to disconnect then reconnect to the new server. We also stash away the overridden server's details so it can be used again we later disconnect and reconnect. If the session is not yet active, we simply stash away the details to be used when establishing the connection.
This commit is contained in:
parent
00c0bc33d0
commit
c36c58ec81
|
@ -16,7 +16,7 @@
|
||||||
* Upgrading to Realm Object Server 2.0.0-rc.4.
|
* Upgrading to Realm Object Server 2.0.0-rc.4.
|
||||||
* OpenSSL for Android is distributed in a separate package, and the build system needed updates to accommendate this.
|
* OpenSSL for Android is distributed in a separate package, and the build system needed updates to accommendate this.
|
||||||
* Added `-fvisibility=hidden` to Android builds (reduces size of `.so` file).
|
* Added `-fvisibility=hidden` to Android builds (reduces size of `.so` file).
|
||||||
|
* Add `Session._overrideServer` to force an existing session to connect to a different server.
|
||||||
|
|
||||||
2.0.0-rc19 Release notes (2017-10-7)
|
2.0.0-rc19 Release notes (2017-10-7)
|
||||||
=============================================================
|
=============================================================
|
||||||
|
|
|
@ -179,6 +179,7 @@ class SessionClass : public ClassDefinition<T, WeakSession> {
|
||||||
using Object = js::Object<T>;
|
using Object = js::Object<T>;
|
||||||
using Value = js::Value<T>;
|
using Value = js::Value<T>;
|
||||||
using ReturnValue = js::ReturnValue<T>;
|
using ReturnValue = js::ReturnValue<T>;
|
||||||
|
using Arguments = js::Arguments<T>;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
std::string const name = "Session";
|
std::string const name = "Session";
|
||||||
|
@ -196,6 +197,8 @@ public:
|
||||||
static void add_progress_notification(ContextType ctx, FunctionType, ObjectType this_object, size_t argc, const ValueType arguments[], ReturnValue &);
|
static void add_progress_notification(ContextType ctx, FunctionType, ObjectType this_object, size_t argc, const ValueType arguments[], ReturnValue &);
|
||||||
static void remove_progress_notification(ContextType ctx, FunctionType, ObjectType this_object, size_t argc, const ValueType arguments[], ReturnValue &);
|
static void remove_progress_notification(ContextType ctx, FunctionType, ObjectType this_object, size_t argc, const ValueType arguments[], ReturnValue &);
|
||||||
|
|
||||||
|
static void override_server(ContextType ctx, ObjectType this_object, Arguments args, ReturnValue&);
|
||||||
|
|
||||||
PropertyMap<T> const properties = {
|
PropertyMap<T> const properties = {
|
||||||
{"config", {wrap<get_config>, nullptr}},
|
{"config", {wrap<get_config>, nullptr}},
|
||||||
{"user", {wrap<get_user>, nullptr}},
|
{"user", {wrap<get_user>, nullptr}},
|
||||||
|
@ -206,6 +209,7 @@ public:
|
||||||
MethodMap<T> const methods = {
|
MethodMap<T> const methods = {
|
||||||
{"_simulateError", wrap<simulate_error>},
|
{"_simulateError", wrap<simulate_error>},
|
||||||
{"_refreshAccessToken", wrap<refresh_access_token>},
|
{"_refreshAccessToken", wrap<refresh_access_token>},
|
||||||
|
{"_overrideServer", wrap<override_server>},
|
||||||
{"addProgressNotification", wrap<add_progress_notification>},
|
{"addProgressNotification", wrap<add_progress_notification>},
|
||||||
{"removeProgressNotification", wrap<remove_progress_notification>},
|
{"removeProgressNotification", wrap<remove_progress_notification>},
|
||||||
};
|
};
|
||||||
|
@ -511,6 +515,23 @@ void SessionClass<T>::remove_progress_notification(ContextType ctx, FunctionType
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
void SessionClass<T>::override_server(ContextType ctx, ObjectType this_object, Arguments args, ReturnValue&) {
|
||||||
|
args.validate_count(2);
|
||||||
|
|
||||||
|
std::string address = Value::validated_to_string(ctx, args[0], "address");
|
||||||
|
double port = Value::validated_to_number(ctx, args[1], "port");
|
||||||
|
if (port < 1 || port > 65535 || uint16_t(port) != port) {
|
||||||
|
std::ostringstream message;
|
||||||
|
message << "Invalid port number. Expected an integer in the range 1-65,535, got '" << port << "'";
|
||||||
|
throw std::invalid_argument(message.str());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (auto session = get_internal<T, SessionClass<T>>(this_object)->lock()) {
|
||||||
|
session->override_server(std::move(address), uint16_t(port));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
class SyncClass : public ClassDefinition<T, void*> {
|
class SyncClass : public ClassDefinition<T, void*> {
|
||||||
using GlobalContextType = typename T::GlobalContext;
|
using GlobalContextType = typename T::GlobalContext;
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit 0b1a2ad7bc1269d4399785240a525e587cd9ddda
|
Subproject commit 77deff579c0ab8cf4f42aa44617ad1cc16482a74
|
Loading…
Reference in New Issue