Class SyncClientImpl
- All Implemented Interfaces:
SyncClient,Closeable,AutoCloseable
SyncClient to access functionality,
this class may change without notice.-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionvoidApplies all pending Sync filter variable updates (fromSyncClient.putFilterVariable(java.lang.String, java.lang.String)andSyncClient.removeFilterVariable(java.lang.String)calls).booleanawaitFirstLogin(long millisToWait) Waits until the sync client receives a response to its first (connection and) login attempt or until the given time has expired.booleanAsks the server to pause sync updates.voidclose()Closes and cleans up all resources used by this sync client.protected voidfinalize()Users of this class should explicitly callclose()instead to avoid expensive finalization.longResponse code of last login attempt.longReturns the estimated roundtrip time in nanoseconds to the server and back.longReturns the estimated difference in nanoseconds between the server time and the local timestamp.longEstimates the current server timestamp in nanoseconds based on the last known server time.Gets the sync server URL this client is connected to.Gets the current state of this sync client.getUrls()Gets the sync server URLs this client may connect to.booleanFlag indicating if the sync client was started.booleanFlag indicating if the sync client was started.voidLets the sync client know that a working network connection is available.voidputFilterVariable(String name, String value) Adds or replaces a Sync filter variable value for the given name.voidRemoves all previously added Sync filter variable values.voidremoveFilterVariable(String name) Removes a previously added Sync filter variable value.booleanTemporary only, try not to use it.booleanTemporary only, try not to use it.booleanAsks the sync server to resume sync updates.booleanAsks the server to send sync updates until this sync client is up-to-date, then pauses sync updates again.voidsetLoginCredentials(SyncCredentials credentials) Sets credentials to authenticate the client with the server.voidsetLoginCredentials(SyncCredentials[] multipleCredentials) LikeSyncClient.setLoginCredentials(SyncCredentials), but accepts an array of credentials.voidsetLoginCredentials(List<SyncCredentials> credentials) LikeSyncClient.setLoginCredentials(SyncCredentials), but accepts a list of credentials.voidsetSyncChangeListener(SyncChangeListener changesListener) Sets aSyncChangeListener.voidSets a listener to observe Sync completed events.voidSets a listener to observe Sync connection events.voidsetSyncListener(SyncListener listener) Sets a listener to observe all Sync events.voidsetSyncLoginListener(SyncLoginListener listener) Sets a listener to observe login events.voidsetSyncTimeListener(SyncTimeListener timeListener) Sets aSyncTimeListener.voidstart()Starts the client.startObjectsMessage(long flags, String topic) Experimental.voidstop()Stops the client.
-
Method Details
-
getServerUrl
Description copied from interface:SyncClientGets the sync server URL this client is connected to.- Specified by:
getServerUrlin interfaceSyncClient
-
getUrls
Description copied from interface:SyncClientGets the sync server URLs this client may connect to.See
SyncBuilder.url(String)for notes on multiple URLs.- Specified by:
getUrlsin interfaceSyncClient
-
getLastLoginCode
public long getLastLoginCode()Description copied from interface:SyncClientResponse code of last login attempt. One ofSyncLoginCodes.- Specified by:
getLastLoginCodein interfaceSyncClient
-
isLoggedIn
public boolean isLoggedIn()Description copied from interface:SyncClientFlag indicating if the sync client was started. Logged in clients can sync with the sync destination to exchange data.- Specified by:
isLoggedInin interfaceSyncClient
-
getServerTimeNanos
public long getServerTimeNanos()Description copied from interface:SyncClientEstimates the current server timestamp in nanoseconds based on the last known server time.- Specified by:
getServerTimeNanosin interfaceSyncClient- Returns:
- unix timestamp in nanoseconds (since epoch); or 0 if there has not been a server contact yet and thus the server's time is unknown
-
getServerTimeDiffNanos
public long getServerTimeDiffNanos()Description copied from interface:SyncClientReturns the estimated difference in nanoseconds between the server time and the local timestamp. urns the difference in nanoseconds between the current local time of this client Equivalent to calculatingSyncClient.getServerTimeNanos()- "current time" (nanos since epoch), except for when the server time is unknown, then the result is zero.- Specified by:
getServerTimeDiffNanosin interfaceSyncClient- Returns:
- time difference in nanoseconds; e.g. positive if server time is ahead of local time; or 0 if there has not been a server contact yet and thus the server's time is unknown
-
getRoundtripTimeNanos
public long getRoundtripTimeNanos()Description copied from interface:SyncClientReturns the estimated roundtrip time in nanoseconds to the server and back. This is measured during login.- Specified by:
getRoundtripTimeNanosin interfaceSyncClient- Returns:
- roundtrip time in nanoseconds; or 0 if there has not been a server contact yet and thus the roundtrip time could not be estimated
-
getSyncState
Gets the current state of this sync client. Throws ifclose()was called. -
setSyncLoginListener
Description copied from interface:SyncClientSets a listener to observe login events. Replaces a previously set listener. Set tonullto remove the listener.- Specified by:
setSyncLoginListenerin interfaceSyncClient
-
setSyncCompletedListener
Description copied from interface:SyncClientSets a listener to observe Sync completed events. Replaces a previously set listener. Set tonullto remove the listener.- Specified by:
setSyncCompletedListenerin interfaceSyncClient
-
setSyncChangeListener
Description copied from interface:SyncClientSets aSyncChangeListener. Replaces a previously set listener. Set tonullto remove the listener.- Specified by:
setSyncChangeListenerin interfaceSyncClient
-
setSyncTimeListener
Description copied from interface:SyncClientSets aSyncTimeListener. Replaces a previously set listener. Set tonullto remove the listener.- Specified by:
setSyncTimeListenerin interfaceSyncClient
-
setSyncConnectionListener
Description copied from interface:SyncClientSets a listener to observe Sync connection events. Replaces a previously set listener. Set tonullto remove the listener.- Specified by:
setSyncConnectionListenerin interfaceSyncClient
-
setSyncListener
Description copied from interface:SyncClientSets a listener to observe all Sync events. Replaces all other previously set listeners, except aSyncChangeListener. Set tonullto remove the listener.- Specified by:
setSyncListenerin interfaceSyncClient
-
putFilterVariable
Description copied from interface:SyncClientAdds or replaces a Sync filter variable value for the given name.Note: If the client is already logged in, this change is not applied until
SyncClient.applyFilterVariables()is called. This allows to put or remove multiple variables before applying all changes. Filter variables set before login (before callingSyncClient.start()) are automatically applied.Eventually, existing values for the same name are replaced.
Sync client filter variables can be used in server-side Sync filters to filter out objects that do not match the filter.
- Specified by:
putFilterVariablein interfaceSyncClient- See Also:
-
removeFilterVariable
Description copied from interface:SyncClientRemoves a previously added Sync filter variable value.Note: If the client is already logged in, this change is not applied until
SyncClient.applyFilterVariables()is called. SeeSyncClient.putFilterVariable(java.lang.String, java.lang.String)for details.- Specified by:
removeFilterVariablein interfaceSyncClient- See Also:
-
removeAllFilterVariables
public void removeAllFilterVariables()Description copied from interface:SyncClientRemoves all previously added Sync filter variable values.Note: If the client is already logged in, this change is not applied until
SyncClient.applyFilterVariables()is called. SeeSyncClient.putFilterVariable(java.lang.String, java.lang.String)for details.- Specified by:
removeAllFilterVariablesin interfaceSyncClient- See Also:
-
applyFilterVariables
public void applyFilterVariables()Description copied from interface:SyncClientApplies all pending Sync filter variable updates (fromSyncClient.putFilterVariable(java.lang.String, java.lang.String)andSyncClient.removeFilterVariable(java.lang.String)calls).If the client is connected, sends the updated variables to the server. If the client is not connected, the updated variables will be included in the next login message.
- Specified by:
applyFilterVariablesin interfaceSyncClient- See Also:
-
setLoginCredentials
Description copied from interface:SyncClientLikeSyncClient.setLoginCredentials(SyncCredentials), but accepts a list of credentials.- Specified by:
setLoginCredentialsin interfaceSyncClient- Parameters:
credentials- a list of credentials where each element is created using aSyncCredentialsfactory method, for exampleSyncCredentials.jwtIdToken(idToken).
-
setLoginCredentials
Description copied from interface:SyncClientSets credentials to authenticate the client with the server.Any credentials that were set before are replaced.
Usually, credentials are passed via
SyncBuilder.credentials(SyncCredentials), but this can be used to update them later, such as when a token expires.The accepted credentials type depends on your Sync server configuration.
- Specified by:
setLoginCredentialsin interfaceSyncClient- Parameters:
credentials- credentials created using aSyncCredentialsfactory method, for exampleSyncCredentials.jwtIdToken(idToken).- See Also:
-
setLoginCredentials
Description copied from interface:SyncClientLikeSyncClient.setLoginCredentials(SyncCredentials), but accepts an array of credentials.- Specified by:
setLoginCredentialsin interfaceSyncClient- Parameters:
multipleCredentials- an array of credentials where each element is created using aSyncCredentialsfactory method, for exampleSyncCredentials.jwtIdToken(idToken).
-
awaitFirstLogin
public boolean awaitFirstLogin(long millisToWait) Description copied from interface:SyncClientWaits until the sync client receives a response to its first (connection and) login attempt or until the given time has expired. UseSyncClient.isLoggedIn()orSyncClient.getLastLoginCode()afterwards to determine if login was successful. Starts the sync if it is not already.- Specified by:
awaitFirstLoginin interfaceSyncClient- Returns:
- true if a response was received in the given time window.
-
start
public void start()Description copied from interface:SyncClientStarts the client. It will connect to the server, log in (authenticate) and start syncing.- Specified by:
startin interfaceSyncClient
-
isStarted
public boolean isStarted()Description copied from interface:SyncClientFlag indicating if the sync client was started. Started clients try to connect, login, and sync with the sync destination.- Specified by:
isStartedin interfaceSyncClient
-
stop
public void stop()Description copied from interface:SyncClientStops the client. Does nothing if the sync client is already stopped.- Specified by:
stopin interfaceSyncClient
-
close
public void close()Description copied from interface:SyncClientCloses and cleans up all resources used by this sync client. It can no longer be used afterwards, build a new sync client instead. Does nothing if this sync client has already been closed.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein interfaceSyncClient
-
finalize
Users of this class should explicitly callclose()instead to avoid expensive finalization. -
requestFullSync
Temporary only, try not to use it.- Specified by:
requestFullSyncin interfaceSyncClient- Returns:
- 'true' if the request was likely sent (e.g. the sync client is in "logged in" state) or 'false' if the request was not sent (and will not be sent in the future).
-
requestFullSyncAndUpdates
Temporary only, try not to use it. -
requestUpdates
public boolean requestUpdates()Description copied from interface:SyncClientAsks the sync server to resume sync updates. This is useful if sync updates were turned off withrequestUpdatesMode(MANUAL).- Specified by:
requestUpdatesin interfaceSyncClient- Returns:
- 'true' if the request was likely sent (e.g. the sync client is in "logged in" state) or 'false' if the request was not sent (and will not be sent in the future)
- See Also:
-
requestUpdatesOnce
public boolean requestUpdatesOnce()Description copied from interface:SyncClientAsks the server to send sync updates until this sync client is up-to-date, then pauses sync updates again. This is useful if sync updates were turned off withrequestUpdatesMode(MANUAL).- Specified by:
requestUpdatesOncein interfaceSyncClient- Returns:
- 'true' if the request was likely sent (e.g. the sync client is in "logged in" state) or 'false' if the request was not sent (and will not be sent in the future)
-
cancelUpdates
public boolean cancelUpdates()Description copied from interface:SyncClientAsks the server to pause sync updates.- Specified by:
cancelUpdatesin interfaceSyncClient- Returns:
- 'true' if the request was likely sent (e.g. the sync client is in "logged in" state) or 'false' if the request was not sent (and will not be sent in the future)
- See Also:
-
notifyConnectionAvailable
public void notifyConnectionAvailable()Description copied from interface:SyncClientLets the sync client know that a working network connection is available.This can help speed up reconnecting to the sync server.
- Specified by:
notifyConnectionAvailablein interfaceSyncClient
-
startObjectsMessage
Description copied from interface:SyncClientExperimental. This API might change or be removed in the future.Start building a message of Objects with optional flags (set to 0) and topic (set to null).
Use like
syncClient.startObjectsMessage(0, "some-topic") .addString(1, "Hello!") .addBytes(2, "Hello!".getBytes(StandardCharsets.UTF_8), false) .send();- Specified by:
startObjectsMessagein interfaceSyncClient
-