public class Subscription extends RealmObject
They are created automatically when using RealmQuery.findAllAsync()
or RealmQuery.findAllAsync(String)
on those Realms, but can also be created manually using RealmQuery.subscribe()
and RealmQuery.subscribe(String)
.
As long as any subscription exist that include an object, that object will be present on the device. If an object is not covered by an active subscription it will be removed from the device, but not the server.
Subscriptions are Realm objects, so deleting them e.g. by calling RealmObject.deleteFromRealm()
,
is the same as calling unsubscribe()
.
Warning: Instances of this class should never be created directly through
Realm.createObject(Class)
but only by using RealmQuery.subscribe()
or
RealmQuery.subscribe(String)
.
Modifier and Type | Class and Description |
---|---|
static class |
Subscription.State
The different states a Subscription can be in.
|
Constructor and Description |
---|
Subscription() |
Subscription(String name,
RealmQuery<?> query)
Creates a unmanaged named subscription from a
RealmQuery . |
Modifier and Type | Method and Description |
---|---|
Date |
getCreatedAt()
Returns when this subscription was initially created.
|
String |
getErrorMessage()
Returns the error message if
getState() returned Subscription.State.ERROR , otherwise
the empty string is returned. |
Date |
getExpiresAt()
Returns the point in time from which Realm can safely delete this subscription.
|
String |
getName()
Returns the name of the subscription.
|
String |
getQueryClassName()
Returns the internal name of the Class being queried.
|
String |
getQueryDescription()
Returns a textual description of the query that created this subscription.
|
Subscription.State |
getState()
Returns the state of the subscription
|
long |
getTimeToLive()
Returns for how long the subscription must be kept alive after last being used.
|
Date |
getUpdatedAt()
Returns when this subscription was last used or updated.
|
void |
setQuery(RealmQuery query)
Replaces the current query controlled by this subscription with a new query.
|
void |
setTimeToLive(long timeToLive,
TimeUnit timeUnit)
Sets the time-to-live in milliseconds for this subscription.
|
String |
toString() |
void |
unsubscribe()
Cancels the subscription.
|
addChangeListener, addChangeListener, addChangeListener, addChangeListener, asChangesetObservable, asChangesetObservable, asFlowable, asFlowable, deleteFromRealm, deleteFromRealm, freeze, freeze, getRealm, getRealm, isFrozen, isFrozen, isLoaded, isLoaded, isManaged, isManaged, isValid, isValid, load, load, removeAllChangeListeners, removeAllChangeListeners, removeChangeListener, removeChangeListener, removeChangeListener, removeChangeListener
public Subscription()
public Subscription(String name, RealmQuery<?> query)
RealmQuery
.
This will not take effect until it has been added to the Realm.name
- name of the query.query
- the query to turn into a subscription.public String getName()
public Date getCreatedAt()
new Date(0)
is returned,
it is unknown when the subscription was created.public Date getUpdatedAt()
"Used" in this context means that someone resubscribed to the subscription.
"Updated" means that someone updated the query
or some other field part of this class.
This field is NOT updated whenever the results of the query changes.
This field plus timeToLive
defines expiresAt
.
public Date getExpiresAt()
Realm will attempt to cleanup expired subscriptions when the app is started or whenever any subscription is modified, there is no guarantee it will happen immediately after it expires.
public long getTimeToLive()
public void setTimeToLive(long timeToLive, TimeUnit timeUnit)
timeToLive
- for how long Realm must keep the subscription after last being used.timeUnit
- time unit for timeToLive
.IllegalArgumentException
- if a negative time-to-live or null timeUnit is provided.public String getQueryDescription()
public void setQuery(RealmQuery query)
query
- the query which should replace the current one.public String getQueryClassName()
public Subscription.State getState()
Subscription.State
public String getErrorMessage()
getState()
returned Subscription.State.ERROR
, otherwise
the empty string is returned.public void unsubscribe()
The effect of unsubscribing is not immediate. The local Realm must coordinate with the Realm Object Server before it can happen. When it happens, any objects removed will trigger a standard change notification, and from the perspective of the device it will look like they where deleted.
Calling this method is the equivalent of calling RealmObject.deleteFromRealm()
.
IllegalStateException
- if the Realm is not in a write transaction.