RLMSyncManager.h 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. ////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright 2016 Realm Inc.
  4. //
  5. // Licensed under the Apache License, Version 2.0 (the "License");
  6. // you may not use this file except in compliance with the License.
  7. // You may obtain a copy of the License at
  8. //
  9. // http://www.apache.org/licenses/LICENSE-2.0
  10. //
  11. // Unless required by applicable law or agreed to in writing, software
  12. // distributed under the License is distributed on an "AS IS" BASIS,
  13. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. // See the License for the specific language governing permissions and
  15. // limitations under the License.
  16. //
  17. ////////////////////////////////////////////////////////////////////////////
  18. #import <Realm/RLMConstants.h>
  19. @class RLMSyncSession, RLMSyncTimeoutOptions, RLMAppConfiguration;
  20. RLM_HEADER_AUDIT_BEGIN(nullability, sendability)
  21. // NEXT-MAJOR: This enum needs to be removed when access to the logger is removed
  22. // from the sync manager.
  23. /// An enum representing different levels of sync-related logging that can be configured.
  24. typedef RLM_CLOSED_ENUM(NSUInteger, RLMSyncLogLevel) {
  25. /// Nothing will ever be logged.
  26. RLMSyncLogLevelOff,
  27. /// Only fatal errors will be logged.
  28. RLMSyncLogLevelFatal,
  29. /// Only errors will be logged.
  30. RLMSyncLogLevelError,
  31. /// Warnings and errors will be logged.
  32. RLMSyncLogLevelWarn,
  33. /// Information about sync events will be logged. Fewer events will be logged in order to avoid overhead.
  34. RLMSyncLogLevelInfo,
  35. /// Information about sync events will be logged. More events will be logged than with `RLMSyncLogLevelInfo`.
  36. RLMSyncLogLevelDetail,
  37. /// Log information that can aid in debugging.
  38. ///
  39. /// - warning: Will incur a measurable performance impact.
  40. RLMSyncLogLevelDebug,
  41. /// Log information that can aid in debugging. More events will be logged than with `RLMSyncLogLevelDebug`.
  42. ///
  43. /// - warning: Will incur a measurable performance impact.
  44. RLMSyncLogLevelTrace,
  45. /// Log information that can aid in debugging. More events will be logged than with `RLMSyncLogLevelTrace`.
  46. ///
  47. /// - warning: Will incur a measurable performance impact.
  48. RLMSyncLogLevelAll
  49. };
  50. #pragma clang diagnostic push
  51. #pragma clang diagnostic ignored "-Wdeprecated-declarations"
  52. /// A log callback function which can be set on RLMSyncManager.
  53. ///
  54. /// The log function may be called from multiple threads simultaneously, and is
  55. /// responsible for performing its own synchronization if any is required.
  56. RLM_SWIFT_SENDABLE // invoked on a background thread
  57. typedef void (^RLMSyncLogFunction)(RLMSyncLogLevel level, NSString *message);
  58. #pragma clang diagnostic pop
  59. /// A block type representing a block which can be used to report a sync-related error to the application. If the error
  60. /// pertains to a specific session, that session will also be passed into the block.
  61. RLM_SWIFT_SENDABLE // invoked on a background thread
  62. typedef void(^RLMSyncErrorReportingBlock)(NSError *, RLMSyncSession * _Nullable);
  63. /**
  64. A manager which serves as a central point for sync-related configuration.
  65. */
  66. RLM_SWIFT_SENDABLE RLM_FINAL // is internally thread-safe
  67. @interface RLMSyncManager : NSObject
  68. /**
  69. A block which can optionally be set to report sync-related errors to your application.
  70. Any error reported through this block will be of the `RLMSyncError` type, and marked
  71. with the `RLMSyncErrorDomain` domain.
  72. Errors reported through this mechanism are fatal, with several exceptions. Please consult
  73. `RLMSyncError` for information about the types of errors that can be reported through
  74. the block, and for for suggestions on handling recoverable error codes.
  75. @see `RLMSyncError`
  76. */
  77. @property (nullable, atomic, copy) RLMSyncErrorReportingBlock errorHandler;
  78. /// :nodoc:
  79. @property (nonatomic, copy) NSString *appID
  80. __attribute__((deprecated("This property is not used for anything")));
  81. /**
  82. A string identifying this application which is included in the User-Agent
  83. header of sync connections. By default, this will be the application's bundle
  84. identifier.
  85. This property must be set prior to opening a synchronized Realm for the first
  86. time. Any modifications made after opening a Realm will be ignored.
  87. */
  88. @property (atomic, copy) NSString *userAgent;
  89. /**
  90. The logging threshold which newly opened synced Realms will use. Defaults to
  91. `RLMSyncLogLevelInfo`.
  92. By default logging strings are output to Apple System Logger. Set `logger` to
  93. perform custom logging logic instead.
  94. @warning This property must be set before any synced Realms are opened. Setting it after
  95. opening any synced Realm will do nothing.
  96. */
  97. @property (atomic) RLMSyncLogLevel logLevel
  98. __attribute__((deprecated("Use `RLMLogger.default.level`/`Logger.shared.level` to set/get the default logger threshold level.")));
  99. /**
  100. The function which will be invoked whenever the sync client has a log message.
  101. If nil, log strings are output to Apple System Logger instead.
  102. @warning This property must be set before any synced Realms are opened. Setting
  103. it after opening any synced Realm will do nothing.
  104. */
  105. @property (atomic, nullable) RLMSyncLogFunction logger
  106. __attribute__((deprecated("Use `RLMLogger.default`/`Logger.shared` to set/get the default logger.")));
  107. /**
  108. The name of the HTTP header to send authorization data in when making requests to Atlas App Services which has
  109. been configured to expect a custom authorization header.
  110. */
  111. @property (nullable, atomic, copy) NSString *authorizationHeaderName;
  112. /**
  113. Extra HTTP headers to append to every request to Atlas App Services.
  114. Modifying this property while sync sessions are active will result in all
  115. sessions disconnecting and reconnecting using the new headers.
  116. */
  117. @property (nullable, atomic, copy) NSDictionary<NSString *, NSString *> *customRequestHeaders;
  118. /**
  119. Options for the assorted types of connection timeouts for sync connections.
  120. If nil default values for all timeouts are used instead.
  121. @warning This property must be set before any synced Realms are opened. Setting
  122. it after opening any synced Realm will do nothing.
  123. */
  124. @property (nullable, atomic, copy) RLMSyncTimeoutOptions *timeoutOptions;
  125. /// :nodoc:
  126. - (instancetype)init __attribute__((unavailable("RLMSyncManager cannot be created directly")));
  127. /// :nodoc:
  128. + (instancetype)new __attribute__((unavailable("RLMSyncManager cannot be created directly")));
  129. @end
  130. /**
  131. Options for configuring timeouts and intervals in the sync client.
  132. */
  133. @interface RLMSyncTimeoutOptions : NSObject
  134. /// The maximum number of milliseconds to allow for a connection to
  135. /// become fully established. This includes the time to resolve the
  136. /// network address, the TCP connect operation, the SSL handshake, and
  137. /// the WebSocket handshake.
  138. ///
  139. /// Defaults to 2 minutes.
  140. @property (nonatomic) NSUInteger connectTimeout;
  141. /// The number of milliseconds to keep a connection open after all
  142. /// sessions have been abandoned.
  143. ///
  144. /// After all synchronized Realms have been closed for a given server, the
  145. /// connection is kept open until the linger time has expired to avoid the
  146. /// overhead of reestablishing the connection when Realms are being closed and
  147. /// reopened.
  148. ///
  149. /// Defaults to 30 seconds.
  150. @property (nonatomic) NSUInteger connectionLingerTime;
  151. /// The number of milliseconds between each heartbeat ping message.
  152. ///
  153. /// The client periodically sends ping messages to the server to check if the
  154. /// connection is still alive. Shorter periods make connection state change
  155. /// notifications more responsive at the cost of battery life (as the antenna
  156. /// will have to wake up more often).
  157. ///
  158. /// Defaults to 1 minute.
  159. @property (nonatomic) NSUInteger pingKeepalivePeriod;
  160. /// How long in milliseconds to wait for a reponse to a heartbeat ping before
  161. /// concluding that the connection has dropped.
  162. ///
  163. /// Shorter values will make connection state change notifications more
  164. /// responsive as it will only change to `disconnected` after this much time has
  165. /// elapsed, but overly short values may result in spurious disconnection
  166. /// notifications when the server is simply taking a long time to respond.
  167. ///
  168. /// Defaults to 2 minutes.
  169. @property (nonatomic) NSUInteger pongKeepaliveTimeout;
  170. /// The maximum amount of time, in milliseconds, since the loss of a
  171. /// prior connection, for a new connection to be considered a "fast
  172. /// reconnect".
  173. ///
  174. /// When a client first connects to the server, it defers uploading any local
  175. /// changes until it has downloaded all changesets from the server. This
  176. /// typically reduces the total amount of merging that has to be done, and is
  177. /// particularly beneficial the first time that a specific client ever connects
  178. /// to the server.
  179. ///
  180. /// When an existing client disconnects and then reconnects within the "fact
  181. /// reconnect" time this is skipped and any local changes are uploaded
  182. /// immediately without waiting for downloads, just as if the client was online
  183. /// the whole time.
  184. ///
  185. /// Defaults to 1 minute.
  186. @property (nonatomic) NSUInteger fastReconnectLimit;
  187. @end
  188. RLM_HEADER_AUDIT_END(nullability, sendability)