Class Ditto
java.lang.Object
com.ditto.java.Ditto
- All Implemented Interfaces:
DittoResource
Ditto is the entrypoint for accessing Ditto-related functionality in the Java SDK.
To construct an instance of Ditto, use DittoFactory.create(DittoConfig).
Ditto provides access to:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceFunctional interface for updating transport configuration. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Shuts down Ditto and releases all resources.boolean@NonNull StringThe absolute path to the persistence directory used by Ditto to persist data.@Nullable DittoAuthenticatorgetAuth()Provides access to authentication information and methods for logging on to Ditto Cloud.@Nullable DittoTransportConditionChangedCallbackReturns the current transport condition changed callback.@NonNull DittoConfigReturns the configuration used to initialize this Ditto instance.@NonNull StringReturns the custom identifier used for this peer.@NonNull DittoDiskUsageProvides access to the SDK's disk usage monitoring.@NonNull DittoPresenceProvides access to the SDK's presence functionality.@NonNull StringReturns a string of version metadata for the Ditto SDK.@NonNull DittoStoregetStore()Provides access to store-related functionality.@NonNull DittoSyncgetSync()Provides access to sync-related functionality.@NonNull DittoTransportConfigReturns the current transport configuration.@NonNull DittoTransportDiagnosticsRequests bulk status information about the transports.inthashCode()booleanReturns a flag indicating whether the SDK has been activated with a valid license token.booleanReturns a flag indicating whether sync is active.voidProvides a hint to Ditto that app permissions may have changed.voidsetCallback(@NonNull DittoTransportConditionChangedCallback callback) Sets an optional callback that will be called with lifecycle events relating to the SDK.voidsetDeviceName(@NonNull String deviceName) Configure a custom identifier for this peer.voidsetOfflineOnlyLicenseToken(@NonNull String licenseToken) Activates an offlineDittoinstance by setting a license token.voidsetTransportConfig(@NonNull DittoTransportConfig transportConfig) Assigns a new transports configuration.voidStarts the network transports.voidstopSync()Stops all network transports.toString()voidupdateTransportConfig(@NonNull Ditto.UpdateTransportConfig configure) Convenience method to update the current transport config of the receiver.
-
Method Details
-
getAbsolutePersistenceDirectory
The absolute path to the persistence directory used by Ditto to persist data. This property returns the final, resolved absolute file path where Ditto stores its data. The value depends on what was provided in
DittoConfig.Builder.persistenceDirectory(String):- If an absolute path was provided, it returns that path unchanged
- If a relative path was provided, it returns the path resolved relative to the default root directory
- If null was provided, it returns the default path This property always returns a consistent value throughout the lifetime of the Ditto instance and represents the actual directory being used for persistence. Note: It is not recommended to directly read from or write to this directory as its structure and contents are managed by Ditto and may change in future versions.
- Returns:
- the absolute path to the persistence directory.
-
getDeviceName
Returns the custom identifier used for this peer.- Returns:
- Custom identifier used for this peer.
- See Also:
-
setDeviceName
Configure a custom identifier for this peer. When usingDittoPresence, each remote peer is represented by a short UTF-8 "device name". By default, this will be the name of the hardware model (Android) or the network hostname (Java). Changes to this property afterstartSync()was called will only take effect after the next restart of sync. The value does not need to be unique among peers. Device names longer than 24 bytes will be truncated oncestartSync()is called.- Parameters:
deviceName- the custom identifier for this peer.- See Also:
-
getPresence
Provides access to the SDK's presence functionality.- Returns:
- a
DittoPresenceinstance for managing presence operations.
-
getCallback
Returns the current transport condition changed callback.- Returns:
- the
DittoTransportConditionChangedCallbackif set,nullotherwise. - See Also:
-
setCallback
Sets an optional callback that will be called with lifecycle events relating to the SDK.- Parameters:
callback- the callback to be notified of transport condition changes.- See Also:
-
isActivated
public boolean isActivated()Returns a flag indicating whether the SDK has been activated with a valid license token.- Returns:
- true if the SDK has been activated, false otherwise.
- See Also:
-
isSyncActive
public boolean isSyncActive()Returns a flag indicating whether sync is active. UsestartSync()to activate andstopSync()to deactivate sync.- Returns:
- true if sync is active, false otherwise.
-
getTransportConfig
Returns the current transport configuration.- Returns:
- the current
DittoTransportConfiginstance. - See Also:
-
getConfig
Returns the configuration used to initialize this Ditto instance. Note: Sensitive data such as passphrases and private keys are redacted from the returned configuration and replaced with the string "[REDACTED]".- Returns:
- the
DittoConfiginstance used to create this Ditto object.
-
setTransportConfig
Assigns a new transports configuration. By default peer-to-peer transports (Bluetooth and WiFi) are enabled. You may use this method to alter the configuration at any time. Sync will not begin untilstartSync()is called.- Parameters:
transportConfig- the new transport configuration to apply.- See Also:
-
getAuth
Provides access to authentication information and methods for logging on to Ditto Cloud.- Returns:
- a
DittoAuthenticatorinstance if authentication is configured, null otherwise.
-
getDiskUsage
Provides access to the SDK's disk usage monitoring.- Returns:
- a
DittoDiskUsageinstance for monitoring disk usage.
-
getSdkVersion
Returns a string of version metadata for the Ditto SDK.- Returns:
- a string containing version metadata. Example: "And4.4.3_73d36"
-
startSync
Starts the network transports. Ditto will connect to other devices. By default, Ditto will enable all peer-to-peer transport types available. The default network configuration can be modified via thesetTransportConfig(DittoTransportConfig)method. Performance of initial sync when bootstrapping a new peer can be improved by callingdisableSyncWithV3()before callingstartSync(). Only do this when all peers in the mesh are known to be running Ditto v4 or higher.- Throws:
DittoException- Thrown if the Ditto instance hasn't been activated by a successful call tosetOfflineOnlyLicenseToken(String).- See Also:
-
stopSync
public void stopSync()Stops all network transports. You may continue to use the Ditto store locally, but no data will sync to or from other devices.- See Also:
-
setOfflineOnlyLicenseToken
Activates an offlineDittoinstance by setting a license token. You cannot sync withDittobefore you have activated it. The offline license token is only valid for manual, offlinePlayground, and sharedKey identities.- Parameters:
licenseToken- the license token to activate theDittoinstance with, which you can find on the Ditto portal (https://portal.ditto.live).- Throws:
DittoException- thrown if the provided licenseToken is expired or invalid.- See Also:
-
getTransportDiagnostics
Requests bulk status information about the transports. This is mostly intended for statistical or debugging purposes.- Returns:
- an instance of
DittoTransportDiagnosticsthat represents the current state of the network transports that the SDK is using.
-
getStore
Provides access to store-related functionality.- Returns:
- a
DittoStoreinstance for managing documents and collections.
-
getSync
-
refreshPermissions
public void refreshPermissions()Provides a hint to Ditto that app permissions may have changed. If your Activity requests a permission that is relevant to Ditto, such as location access, it is recommended to call this method fromonRequestPermissionsResultCallback(). This allows Ditto to detect the new permissions sooner and begin syncing. -
updateTransportConfig
Convenience method to update the current transport config of the receiver. Invokes the lambda expression with a copy of the current transport config which you can alter to your liking. The updated transport config is then set upon the receiver. You may use this method to alter the configuration at any time. Sync will not begin untilstartSync()is invoked.- Parameters:
configure- a functional interface that receives aDittoTransportConfig.Builderto modify the transport configuration.- See Also:
-
close
public void close()Shuts down Ditto and releases all resources. Must be called before recreating a Ditto instance that uses the same persistence directory.- Specified by:
closein interfaceDittoResource
-
toString
-
equals
-
hashCode
-