Class AblyBase
- All Implemented Interfaces:
AutoCloseable
- Direct Known Subclasses:
AblyRest
AutoCloseable so you can use it in
try-with-resources constructs and have the JDK close it for you.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceA collection of Channels associated with an Ably instance. -
Field Summary
FieldsModifier and TypeFieldDescriptionfinal AuthAnAuthobject.final AblyBase.ChannelsAnAblyBase.Channelsobject.final Httpfinal HttpCorefinal ClientOptionsfinal Platformprotected final PlatformAgentProviderfinal PushAnPushobject. -
Constructor Summary
ConstructorsConstructorDescriptionAblyBase(ClientOptions options, PlatformAgentProvider platformAgentProvider) Construct a client object using an AblyClientOptionsobject.AblyBase(String key, PlatformAgentProvider platformAgentProvider) Constructs a client object using an Ably API key or token string. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Causes the connection to close, entering the [ConnectionState.closingstate.protected voidonAuthError(ErrorInfo errorInfo) Authentication error occurredprotected voidonAuthUpdated(String token, boolean waitForResponse) Override this method in AblyRealtime and pass updated token to ConnectionManagerprotected voidonAuthUpdatedAsync(String token, Auth.AuthUpdateResult authUpdateResult) Override this method in AblyRealtime and pass updated token to ConnectionManagerprotected voidonClientIdSet(String clientId) clientId set by late initialisationpublishBatch(Message.Batch[] pubSpecs, ChannelOptions channelOptions) Publish an array ofMessage.Batchobjects to one or more channels, up to a maximum of 100 channels.publishBatch(Message.Batch[] pubSpecs, ChannelOptions channelOptions, Param[] params) Publish an array ofMessage.Batchobjects to one or more channels, up to a maximum of 100 channels.voidpublishBatchAsync(Message.Batch[] pubSpecs, ChannelOptions channelOptions, Callback<PublishResponse[]> callback) Asynchronously publish an array ofMessage.Batchobjects to one or more channels, up to a maximum of 100 channels.voidpublishBatchAsync(Message.Batch[] pubSpecs, ChannelOptions channelOptions, Param[] params, Callback<PublishResponse[]> callback) Asynchronously publish an array ofMessage.Batchobjects to one or more channels, up to a maximum of 100 channels.Makes a REST request to a provided path.voidrequestAsync(String method, String path, Param[] params, HttpCore.RequestBody body, Param[] headers, AsyncHttpPaginatedResponse.Callback callback) Makes a async REST request to a provided path.Queries the REST /stats API and retrieves your application's usage statistics.voidstatsAsync(Param[] params, Callback<AsyncPaginatedResult<Stats>> callback) Asynchronously queries the REST /stats API and retrieves your application's usage statistics.longtime()Retrieves the time from the Ably service as milliseconds since the Unix epoch.voidAsynchronously retrieves the time from the Ably service as milliseconds since the Unix epoch.
-
Field Details
-
options
-
http
-
httpCore
-
auth
AnAuthobject.Spec: RSC5
-
channels
AnAblyBase.Channelsobject.Spec: RSN1
-
platform
-
push
AnPushobject.Spec: RSH7
-
platformAgentProvider
-
-
Constructor Details
-
AblyBase
Constructs a client object using an Ably API key or token string.Spec: RSC1
- Parameters:
-
key- The Ably API key or token string used to validate the client. -
platformAgentProvider- provides platform agent for the agent header. - Throws:
AblyException
-
AblyBase
public AblyBase(ClientOptions options, PlatformAgentProvider platformAgentProvider) throws AblyException Construct a client object using an AblyClientOptionsobject.Spec: RSC1
- Parameters:
-
options- AClientOptionsobject to configure the client connection to Ably. -
platformAgentProvider- provides platform agent for the agent header. - Throws:
AblyException
-
-
Method Details
-
close
Causes the connection to close, entering the [ConnectionState.closingstate. Once closed, the library does not attempt to re-establish the connection without an explicit call toConnection.connect().Spec: RTN12
- Specified by:
-
closein interfaceAutoCloseable - Throws:
Exception
-
time
Retrieves the time from the Ably service as milliseconds since the Unix epoch. Clients that do not have access to a sufficiently well maintained time source and wish to issue AblyAuth.TokenRequestwith a more accurate timestamp should use theAuth.AuthOptions.queryTimeproperty instead of this method.Spec: RSC16
- Returns:
- The time as milliseconds since the Unix epoch.
- Throws:
AblyException
-
timeAsync
Asynchronously retrieves the time from the Ably service as milliseconds since the Unix epoch. Clients that do not have access to a sufficiently well maintained time source and wish to issue AblyAuth.TokenRequestwith a more accurate timestamp should use theAuth.AuthOptions.queryTimeproperty instead of this method.Spec: RSC16
- Parameters:
-
callback- Listener with the time as milliseconds since the Unix epoch.This callback is invoked on a background thread
-
stats
Queries the REST /stats API and retrieves your application's usage statistics.- Parameters:
-
params- query options:start (RSC6b1) - The time from which stats are retrieved, specified as milliseconds since the Unix epoch.
end (RSC6b1) - The time until stats are retrieved, specified as milliseconds since the Unix epoch.
direction (RSC6b2) - The order for which stats are returned in. Valid values are backwards which orders stats from most recent to oldest, or forwards which orders stats from oldest to most recent. The default is backwards.
limit (RSC6b3) - An upper limit on the number of stats returned. The default is 100, and the maximum is 1000.
unit (RSC6b4) - minute, hour, day or month. Based on the unit selected, the given start or end times are rounded down to the start of the relevant interval depending on the unit granularity of the query.)
Spec: RSC6a
- Returns:
- A
PaginatedResultobject containing an array ofStatsobjects. - Throws:
AblyException
-
statsAsync
Asynchronously queries the REST /stats API and retrieves your application's usage statistics.- Parameters:
-
params- query options:start (RSC6b1) - The time from which stats are retrieved, specified as milliseconds since the Unix epoch.
end (RSC6b1) - The time until stats are retrieved, specified as milliseconds since the Unix epoch.
direction (RSC6b2) - The order for which stats are returned in. Valid values are backwards which orders stats from most recent to oldest, or forwards which orders stats from oldest to most recent. The default is backwards.
limit (RSC6b3) - An upper limit on the number of stats returned. The default is 100, and the maximum is 1000.
unit (RSC6b4) - minute, hour, day or month. Based on the unit selected, the given start or end times are rounded down to the start of the relevant interval depending on the unit granularity of the query.)
Spec: RSC6a
-
callback- Listener which returns aAsyncPaginatedResultobject containing an array ofStatsobjects.This callback is invoked on a background thread
-
request
public HttpPaginatedResponse request(String method, String path, Param[] params, HttpCore.RequestBody body, Param[] headers) throws AblyException Makes a REST request to a provided path. This is provided as a convenience for developers who wish to use REST API functionality that is either not documented or is not yet included in the public API, without having to directly handle features such as authentication, paging, fallback hosts, MsgPack and JSON support.Spec: RSC19
- Parameters:
-
method- The request method to use, such as GET, POST. -
path- The request path. -
params- The parameters to include in the URL query of the request. The parameters depend on the endpoint being queried. See the REST API reference for the available parameters of each endpoint. -
body- The RequestBody of the request. -
headers- Additional HTTP headers to include in the request. - Returns:
- An
HttpPaginatedResponseobject returned by the HTTP request, containing an empty or JSON-encodable object. - Throws:
-
AblyException- if it was not possible to complete the request, or an error response was received
-
requestAsync
public void requestAsync(String method, String path, Param[] params, HttpCore.RequestBody body, Param[] headers, AsyncHttpPaginatedResponse.Callback callback) Makes a async REST request to a provided path. This is provided as a convenience for developers who wish to use REST API functionality that is either not documented or is not yet included in the public API, without having to directly handle features such as authentication, paging, fallback hosts, MsgPack and JSON support.Spec: RSC19
- Parameters:
-
method- The request method to use, such as GET, POST. -
path- The request path. -
params- The parameters to include in the URL query of the request. The parameters depend on the endpoint being queried. See the REST API reference for the available parameters of each endpoint. -
body- The RequestBody of the request. -
headers- Additional HTTP headers to include in the request. -
callback- called with the asynchronous result, returns anAsyncHttpPaginatedResponseobject returned by the HTTP request, containing an empty or JSON-encodable object.This callback is invoked on a background thread
-
publishBatch
@Experimental public PublishResponse[] publishBatch(Message.Batch[] pubSpecs, ChannelOptions channelOptions) throws AblyException Publish an array ofMessage.Batchobjects to one or more channels, up to a maximum of 100 channels. EachMessage.Batchobject can contain a single message or an array of messages. Returns an array ofPublishResponseobject.Spec: BO2a
- Parameters:
-
pubSpecs- An array ofMessage.Batchobjects. -
channelOptions- AClientOptionsobject to configure the client connection to Ably. - Returns:
- A
PublishResponseobject. - Throws:
AblyException
-
publishBatch
@Experimental public PublishResponse[] publishBatch(Message.Batch[] pubSpecs, ChannelOptions channelOptions, Param[] params) throws AblyException Publish an array ofMessage.Batchobjects to one or more channels, up to a maximum of 100 channels. EachMessage.Batchobject can contain a single message or an array of messages. Returns an array ofPublishResponseobject.Spec: BO2a
- Parameters:
-
pubSpecs- An array ofMessage.Batchobjects. -
channelOptions- AClientOptionsobject to configure the client connection to Ably. -
params- params to pass into the initial query - Returns:
- A
PublishResponseobject. - Throws:
AblyException
-
publishBatchAsync
@Experimental public void publishBatchAsync(Message.Batch[] pubSpecs, ChannelOptions channelOptions, Callback<PublishResponse[]> callback) throws AblyException Asynchronously publish an array ofMessage.Batchobjects to one or more channels, up to a maximum of 100 channels. EachMessage.Batchobject can contain a single message or an array of messages. Returns an array ofPublishResponseobject.Spec: BO2a
- Parameters:
-
pubSpecs- An array ofMessage.Batchobjects. -
channelOptions- AClientOptionsobject to configure the client connection to Ably. -
callback- callback A callback withPublishResponseobject.This callback is invoked on a background thread
- Throws:
AblyException
-
publishBatchAsync
@Experimental public void publishBatchAsync(Message.Batch[] pubSpecs, ChannelOptions channelOptions, Param[] params, Callback<PublishResponse[]> callback) throws AblyException Asynchronously publish an array ofMessage.Batchobjects to one or more channels, up to a maximum of 100 channels. EachMessage.Batchobject can contain a single message or an array of messages. Returns an array ofPublishResponseobject.Spec: BO2a
- Parameters:
-
pubSpecs- An array ofMessage.Batchobjects. -
channelOptions- AClientOptionsobject to configure the client connection to Ably. -
params- params to pass into the initial query -
callback- A callback withPublishResponseobject.This callback is invoked on a background thread
- Throws:
AblyException
-
onAuthUpdated
Override this method in AblyRealtime and pass updated token to ConnectionManager- Parameters:
-
token- new token -
waitForResponse- wait for server response before returning from method - Throws:
AblyException
-
onAuthUpdatedAsync
Override this method in AblyRealtime and pass updated token to ConnectionManager- Parameters:
-
token- new token -
authUpdateResult- Callback result
-
onAuthError
Authentication error occurred -
onClientIdSet
clientId set by late initialisation
-