Skip to content

Commit 86027f5

Browse files
committed
[CHAT-5063] refactor: make implicit calls overrides instead of patching client
1 parent 122a729 commit 86027f5

File tree

10 files changed

+248
-158
lines changed

10 files changed

+248
-158
lines changed

android/src/main/java/io/ably/lib/rest/AblyRest.java

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package io.ably.lib.rest;
22

33
import android.content.Context;
4-
import io.ably.lib.http.Http;
5-
import io.ably.lib.http.HttpCore;
64
import io.ably.lib.push.LocalDevice;
75
import io.ably.lib.types.AblyException;
86
import io.ably.lib.types.ClientOptions;
@@ -38,24 +36,6 @@ public AblyRest(ClientOptions options) throws AblyException {
3836
super(options, new AndroidPlatformAgentProvider());
3937
}
4038

41-
/**
42-
* Constructor implementation to be able to have shallow copy of the client,
43-
* allowing us to modify certain fields while implementing a proxy for the Realtime/Rest SDK wrapper
44-
*/
45-
protected AblyRest(AblyRest underlyingClient, HttpCore httpCore, Http http) {
46-
super(underlyingClient, httpCore, http);
47-
}
48-
49-
/**
50-
* [Internal Method]
51-
* <p/>
52-
* We use this method to create a shallow copy of the client, allowing us to modify certain fields
53-
* while implementing a proxy for the Realtime/Rest SDK wrapper
54-
*/
55-
public AblyRest createShallowCopy(HttpCore httpCore, Http http) {
56-
return new AblyRest(this, httpCore, http);
57-
}
58-
5939
/**
6040
* Retrieves a {@link LocalDevice} object that represents the current state of the device as a target for push notifications.
6141
* <p>

java/src/main/java/io/ably/lib/rest/AblyRest.java

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package io.ably.lib.rest;
22

3-
import io.ably.lib.http.Http;
4-
import io.ably.lib.http.HttpCore;
53
import io.ably.lib.types.AblyException;
64
import io.ably.lib.types.ClientOptions;
75
import io.ably.lib.util.JavaPlatformAgentProvider;
@@ -34,22 +32,4 @@ public AblyRest(String key) throws AblyException {
3432
public AblyRest(ClientOptions options) throws AblyException {
3533
super(options, new JavaPlatformAgentProvider());
3634
}
37-
38-
/**
39-
* Constructor implementation to be able to have shallow copy of the client,
40-
* allowing us to modify certain fields while implementing a proxy for the Realtime/Rest SDK wrapper
41-
*/
42-
protected AblyRest(AblyRest underlyingClient, HttpCore httpCore, Http http) {
43-
super(underlyingClient, httpCore, http);
44-
}
45-
46-
/**
47-
* [Internal Method]
48-
* <p/>
49-
* We use this method to create a shallow copy of the client, allowing us to modify certain fields
50-
* while implementing a proxy for the Realtime/Rest SDK wrapper
51-
*/
52-
public AblyRest createShallowCopy(HttpCore httpCore, Http http) {
53-
return new AblyRest(this, httpCore, http);
54-
}
5535
}

lib/src/main/java/io/ably/lib/realtime/AblyRealtime.java

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
import java.util.List;
66
import java.util.Map;
77

8-
import io.ably.lib.http.Http;
9-
import io.ably.lib.http.HttpCore;
108
import io.ably.lib.rest.AblyRest;
119
import io.ably.lib.rest.Auth;
1210
import io.ably.lib.transport.ConnectionManager;
@@ -85,16 +83,6 @@ public void onConnectionStateChanged(ConnectionStateListener.ConnectionStateChan
8583
if(options.autoConnect) connection.connect();
8684
}
8785

88-
/**
89-
* Constructor implementation to be able to have shallow copy of the client,
90-
* allowing us to modify certain fields while implementing a proxy for the Realtime/Rest SDK wrapper
91-
*/
92-
AblyRealtime(AblyRealtime underlyingClient, HttpCore httpCore, Http http) {
93-
super(underlyingClient, httpCore, http);
94-
this.channels = underlyingClient.channels;
95-
this.connection = underlyingClient.connection;
96-
}
97-
9886
/**
9987
* Calls {@link Connection#connect} and causes the connection to open,
10088
* entering the connecting state. Explicitly calling connect() is unnecessary
@@ -130,16 +118,6 @@ public void close() {
130118
connection.close();
131119
}
132120

133-
/**
134-
* [Internal Method]
135-
* <p/>
136-
* We use this method to create a shallow copy of the client, allowing us to modify certain fields
137-
* while implementing a proxy for the Realtime/Rest SDK wrapper
138-
*/
139-
public AblyRealtime createShallowCopy(HttpCore httpCore, Http http) {
140-
return new AblyRealtime(this, httpCore, http);
141-
}
142-
143121
/**
144122
* Authentication token has changed.
145123
*/

lib/src/main/java/io/ably/lib/rest/AblyBase.java

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -114,20 +114,6 @@ public AblyBase(ClientOptions options, PlatformAgentProvider platformAgentProvid
114114
push = new Push(this);
115115
}
116116

117-
/**
118-
* We use empty constructor to be able to create proxy implementation of Realtime and Rest client
119-
*/
120-
protected AblyBase(AblyBase underlyingClient, HttpCore httpCore, Http http) {
121-
this.options = underlyingClient.options;
122-
this.auth = underlyingClient.auth;
123-
this.httpCore = httpCore;
124-
this.http = http;
125-
this.platform = underlyingClient.platform;
126-
this.push = underlyingClient.push;
127-
this.channels = underlyingClient.channels;
128-
this.platformAgentProvider = underlyingClient.platformAgentProvider;
129-
}
130-
131117
/**
132118
* Causes the connection to close, entering the [{@link io.ably.lib.realtime.ConnectionState#closing} state.
133119
* Once closed, the library does not attempt to re-establish the connection without an explicit call to
@@ -193,7 +179,11 @@ public void release(String channelName) {
193179
* @throws AblyException
194180
*/
195181
public long time() throws AblyException {
196-
return timeImpl().sync().longValue();
182+
return time(http);
183+
}
184+
185+
long time(Http http) throws AblyException {
186+
return timeImpl(http).sync();
197187
}
198188

199189
/**
@@ -210,10 +200,14 @@ public long time() throws AblyException {
210200
* This callback is invoked on a background thread
211201
*/
212202
public void timeAsync(Callback<Long> callback) {
213-
timeImpl().async(callback);
203+
timeAsync(http, callback);
204+
}
205+
206+
void timeAsync(Http http, Callback<Long> callback) {
207+
timeImpl(http).async(callback);
214208
}
215209

216-
private Http.Request<Long> timeImpl() {
210+
private Http.Request<Long> timeImpl(Http http) {
217211
final Param[] params = this.options.addRequestIds ? Param.array(Crypto.generateRandomRequestId()) : null; // RSC7c
218212
return http.request(new Http.Execute<Long>() {
219213
@Override
@@ -251,7 +245,11 @@ public Long handleResponse(HttpCore.Response response, ErrorInfo error) throws A
251245
* @throws AblyException
252246
*/
253247
public PaginatedResult<Stats> stats(Param[] params) throws AblyException {
254-
return new PaginatedQuery<Stats>(http, "/stats", HttpUtils.defaultAcceptHeaders(false), params, StatsReader.statsResponseHandler).get();
248+
return stats(http, params);
249+
}
250+
251+
PaginatedResult<Stats> stats(Http http, Param[] params) throws AblyException {
252+
return new PaginatedQuery<>(http, "/stats", HttpUtils.defaultAcceptHeaders(false), params, StatsReader.statsResponseHandler).get();
255253
}
256254

257255
/**
@@ -275,6 +273,10 @@ public PaginatedResult<Stats> stats(Param[] params) throws AblyException {
275273
* This callback is invoked on a background thread
276274
*/
277275
public void statsAsync(Param[] params, Callback<AsyncPaginatedResult<Stats>> callback) {
276+
statsAsync(http, params, callback);
277+
}
278+
279+
void statsAsync(Http http, Param[] params, Callback<AsyncPaginatedResult<Stats>> callback) {
278280
(new AsyncPaginatedQuery<Stats>(http, "/stats", HttpUtils.defaultAcceptHeaders(false), params, StatsReader.statsResponseHandler)).get(callback);
279281
}
280282

@@ -298,6 +300,10 @@ public void statsAsync(Param[] params, Callback<AsyncPaginatedResult<Stats>> cal
298300
* @throws AblyException if it was not possible to complete the request, or an error response was received
299301
*/
300302
public HttpPaginatedResponse request(String method, String path, Param[] params, HttpCore.RequestBody body, Param[] headers) throws AblyException {
303+
return request(http, method, path, params, body, headers);
304+
}
305+
306+
HttpPaginatedResponse request(Http http, String method, String path, Param[] params, HttpCore.RequestBody body, Param[] headers) throws AblyException {
301307
headers = HttpUtils.mergeHeaders(HttpUtils.defaultAcceptHeaders(false), headers);
302308
return new HttpPaginatedQuery(http, method, path, headers, params, body).exec();
303309
}
@@ -325,6 +331,10 @@ public HttpPaginatedResponse request(String method, String path, Param[] params,
325331
* This callback is invoked on a background thread
326332
*/
327333
public void requestAsync(String method, String path, Param[] params, HttpCore.RequestBody body, Param[] headers, final AsyncHttpPaginatedResponse.Callback callback) {
334+
requestAsync(http, method, path, params, body, headers, callback);
335+
}
336+
337+
void requestAsync(Http http, String method, String path, Param[] params, HttpCore.RequestBody body, Param[] headers, final AsyncHttpPaginatedResponse.Callback callback) {
328338
headers = HttpUtils.mergeHeaders(HttpUtils.defaultAcceptHeaders(false), headers);
329339
(new AsyncHttpPaginatedQuery(http, method, path, headers, params, body)).exec(callback);
330340
}

lib/src/main/java/io/ably/lib/rest/ChannelBase.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ public void execute(HttpScheduler http, final Callback<Void> callback) throws Ab
149149
* @throws AblyException
150150
*/
151151
public PaginatedResult<Message> history(Param[] params) throws AblyException {
152-
return historyImpl(ably.http, params).sync();
152+
return history(ably.http, params);
153153
}
154154

155155
PaginatedResult<Message> history(Http http, Param[] params) throws AblyException {

pubsub-adapter/src/main/kotlin/io/ably/lib/realtime/RealtimeClientAdapter.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ internal class RealtimeClientAdapter(private val javaClient: AblyRealtime) : Rea
7070
override fun createWrapperSdkProxy(options: WrapperSdkProxyOptions): RealtimeClient {
7171
val httpCoreWithAgents = javaClient.httpCore.injectDynamicAgents(options.agents)
7272
val httpModule = javaClient.http.exchangeHttpCore(httpCoreWithAgents)
73-
val javaClientWithInjectedAgents = javaClient.createShallowCopy(httpCoreWithAgents, httpModule)
74-
return WrapperRealtimeClient(javaClientWithInjectedAgents, httpModule, options.agents)
73+
return WrapperRealtimeClient(javaClient, this, httpModule, options.agents)
7574
}
7675
}

0 commit comments

Comments
 (0)