Skip to content

Commit 6c17e7e

Browse files
committed
Removing client param from callbacks
1 parent bf78551 commit 6c17e7e

File tree

3 files changed

+21
-28
lines changed

3 files changed

+21
-28
lines changed

opamp-client/src/main/java/io/opentelemetry/opamp/client/internal/OpampClient.java

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ static OpampClientBuilder builder() {
2020
/**
2121
* Starts the client and begin attempts to connect to the Server. Once connection is established
2222
* the client will attempt to maintain it by reconnecting if the connection is lost. All failed
23-
* connection attempts will be reported via {@link Callbacks#onConnectFailed(OpampClient,
24-
* Throwable)} callback.
23+
* connection attempts will be reported via {@link Callbacks#onConnectFailed(Throwable)} callback.
2524
*
2625
* <p>This method does not wait until the connection to the Server is established and will likely
2726
* return before the connection attempts are even made.
@@ -45,7 +44,7 @@ static OpampClientBuilder builder() {
4544
* the Server. When called after {@link #start(Callbacks)}, the attributes will be included in the
4645
* next outgoing status report. This is typically used by Agents which allow their
4746
* AgentDescription to change dynamically while the OpAMPClient is started. May be also called
48-
* from {@link Callbacks#onMessage(OpampClient, MessageData)}.
47+
* from {@link Callbacks#onMessage(MessageData)}.
4948
*
5049
* @param agentDescription The new agent description.
5150
*/
@@ -64,31 +63,27 @@ interface Callbacks {
6463
* {@link #start(Callbacks)} is called and every time a connection is established to the Server.
6564
* For WebSocket clients this is called after the handshake is completed without any error. For
6665
* HTTP clients this is called for any request if the response status is OK.
67-
*
68-
* @param client The relevant {@link OpampClient} instance.
6966
*/
70-
void onConnect(OpampClient client);
67+
void onConnect();
7168

7269
/**
7370
* Called when the connection to the Server cannot be established. May be called after {@link
7471
* #start(Callbacks)} is called and tries to connect to the Server. May also be called if the
7572
* connection is lost and reconnection attempt fails.
7673
*
77-
* @param client The relevant {@link OpampClient} instance.
7874
* @param throwable The exception.
7975
*/
80-
void onConnectFailed(OpampClient client, @Nullable Throwable throwable);
76+
void onConnectFailed(@Nullable Throwable throwable);
8177

8278
/**
8379
* Called when the Server reports an error in response to some previously sent request. Useful
8480
* for logging purposes. The Agent should not attempt to process the error by reconnecting or
8581
* retrying previous operations. The client handles the ErrorResponse_UNAVAILABLE case
8682
* internally by performing retries as necessary.
8783
*
88-
* @param client The relevant {@link OpampClient} instance.
8984
* @param errorResponse The error returned by the Server.
9085
*/
91-
void onErrorResponse(OpampClient client, ServerErrorResponse errorResponse);
86+
void onErrorResponse(ServerErrorResponse errorResponse);
9287

9388
/**
9489
* Called when the Agent receives a message that needs processing. See {@link MessageData}
@@ -99,9 +94,8 @@ interface Callbacks {
9994
* onMessage returns. This is advisable if processing can take a long time. In that case
10095
* returning quickly is preferable to avoid blocking the {@link OpampClient}.
10196
*
102-
* @param client The relevant {@link OpampClient} instance.
10397
* @param messageData The server response data that needs processing.
10498
*/
105-
void onMessage(OpampClient client, MessageData messageData);
99+
void onMessage(MessageData messageData);
106100
}
107101
}

opamp-client/src/main/java/io/opentelemetry/opamp/client/internal/impl/OpampClientImpl.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,12 +154,12 @@ public void setRemoteConfigStatus(@Nonnull RemoteConfigStatus remoteConfigStatus
154154

155155
@Override
156156
public void onConnectionSuccess() {
157-
getCallbacks().onConnect(this);
157+
getCallbacks().onConnect();
158158
}
159159

160160
@Override
161161
public void onConnectionFailed(Throwable throwable) {
162-
getCallbacks().onConnectFailed(this, throwable);
162+
getCallbacks().onConnectFailed(throwable);
163163
}
164164

165165
@Override
@@ -176,7 +176,7 @@ public void onRequestFailed(Throwable throwable) {
176176
preserveFailedRequestRecipe();
177177
if (throwable instanceof OpampServerResponseException) {
178178
ServerErrorResponse errorResponse = ((OpampServerResponseException) throwable).errorResponse;
179-
getCallbacks().onErrorResponse(this, errorResponse);
179+
getCallbacks().onErrorResponse(errorResponse);
180180
}
181181
}
182182

@@ -203,7 +203,7 @@ private void handleResponsePayload(ServerToAgent response) {
203203
}
204204

205205
if (notifyOnMessage) {
206-
getCallbacks().onMessage(this, messageBuilder.build());
206+
getCallbacks().onMessage(messageBuilder.build());
207207
}
208208
}
209209

opamp-client/src/test/java/io/opentelemetry/opamp/client/internal/impl/OpampClientImplTest.java

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,7 @@ void onSuccess_withChangesToReport_notifyCallbackOnMessage() {
211211
// Await for onMessage call
212212
await().atMost(Duration.ofSeconds(1)).until(() -> callbacks.onMessageCalls.get() == 1);
213213

214-
verify(callbacks)
215-
.onMessage(client, MessageData.builder().setRemoteConfig(remoteConfig).build());
214+
verify(callbacks).onMessage(MessageData.builder().setRemoteConfig(remoteConfig).build());
216215
}
217216

218217
@Test
@@ -227,7 +226,7 @@ void onSuccess_withNoChangesToReport_doNotNotifyCallbackOnMessage() {
227226
// Giving some time for the callback to get called
228227
await().during(Duration.ofSeconds(1));
229228

230-
verify(callbacks, never()).onMessage(any(), any());
229+
verify(callbacks, never()).onMessage(any());
231230
}
232231

233232
@Test
@@ -270,8 +269,8 @@ void onConnectionSuccessful_notifyCallback() {
270269

271270
await().atMost(Duration.ofSeconds(1)).until(() -> callbacks.onConnectCalls.get() == 1);
272271

273-
verify(callbacks).onConnect(client);
274-
verify(callbacks, never()).onConnectFailed(any(), any());
272+
verify(callbacks).onConnect();
273+
verify(callbacks, never()).onConnectFailed(any());
275274
}
276275

277276
@Test
@@ -314,8 +313,8 @@ void onFailedResponse_withServerErrorData_notifyCallback() {
314313

315314
await().atMost(Duration.ofSeconds(1)).until(() -> callbacks.onErrorResponseCalls.get() == 1);
316315

317-
verify(callbacks).onErrorResponse(client, errorResponse);
318-
verify(callbacks, never()).onMessage(any(), any());
316+
verify(callbacks).onErrorResponse(errorResponse);
317+
verify(callbacks, never()).onMessage(any());
319318
}
320319

321320
@Test
@@ -325,7 +324,7 @@ void onConnectionFailed_notifyCallback() {
325324

326325
client.onConnectionFailed(throwable);
327326

328-
verify(callbacks).onConnectFailed(client, throwable);
327+
verify(callbacks).onConnectFailed(throwable);
329328
}
330329

331330
@Test
@@ -464,22 +463,22 @@ private static class TestCallbacks implements OpampClient.Callbacks {
464463
private final AtomicInteger onMessageCalls = new AtomicInteger();
465464

466465
@Override
467-
public void onConnect(OpampClient client) {
466+
public void onConnect() {
468467
onConnectCalls.incrementAndGet();
469468
}
470469

471470
@Override
472-
public void onConnectFailed(OpampClient client, @Nullable Throwable throwable) {
471+
public void onConnectFailed(@Nullable Throwable throwable) {
473472
onConnectFailedCalls.incrementAndGet();
474473
}
475474

476475
@Override
477-
public void onErrorResponse(OpampClient client, ServerErrorResponse errorResponse) {
476+
public void onErrorResponse(ServerErrorResponse errorResponse) {
478477
onErrorResponseCalls.incrementAndGet();
479478
}
480479

481480
@Override
482-
public void onMessage(OpampClient client, MessageData messageData) {
481+
public void onMessage(MessageData messageData) {
483482
onMessageCalls.incrementAndGet();
484483
}
485484
}

0 commit comments

Comments
 (0)