|
| 1 | +package io.opentelemetry.opamp.client.internal; |
| 2 | + |
| 3 | +import io.opentelemetry.opamp.client.internal.response.MessageData; |
| 4 | +import opamp.proto.Opamp; |
| 5 | + |
| 6 | +public interface OpampClient { |
| 7 | + |
| 8 | + /** |
| 9 | + * Starts the client and begin attempts to connect to the Server. Once connection is established |
| 10 | + * the client will attempt to maintain it by reconnecting if the connection is lost. All failed |
| 11 | + * connection attempts will be reported via {@link Callback#onConnectFailed(OpampClient, |
| 12 | + * Throwable)} callback. |
| 13 | + * |
| 14 | + * <p>This method does not wait until the connection to the Server is established and will likely |
| 15 | + * return before the connection attempts are even made. |
| 16 | + * |
| 17 | + * <p>This method may be called only once. |
| 18 | + * |
| 19 | + * @param callback The Callback to which the Client will notify about any Server requests and |
| 20 | + * responses. |
| 21 | + */ |
| 22 | + void start(Callback callback); |
| 23 | + |
| 24 | + /** |
| 25 | + * Stops the client. May be called only after {@link #start(OpampClient.Callback)}. May be called |
| 26 | + * only once. After this call returns successfully it is guaranteed that no callbacks will be |
| 27 | + * called. Once stopped, the client cannot be started again. |
| 28 | + */ |
| 29 | + void stop(); |
| 30 | + |
| 31 | + /** |
| 32 | + * Sets the current remote config status which will be sent in the next agent to server request. |
| 33 | + * |
| 34 | + * @param remoteConfigStatus The new remote config status. |
| 35 | + */ |
| 36 | + void setRemoteConfigStatus(Opamp.RemoteConfigStatus remoteConfigStatus); |
| 37 | + |
| 38 | + /** |
| 39 | + * Sets the current effective config which will be sent in the next agent to server request. |
| 40 | + * |
| 41 | + * @param effectiveConfig The new effective config. |
| 42 | + */ |
| 43 | + void setEffectiveConfig(Opamp.EffectiveConfig effectiveConfig); |
| 44 | + |
| 45 | + interface Callback { |
| 46 | + /** |
| 47 | + * Called when the connection is successfully established to the Server. May be called after |
| 48 | + * {@link #start(OpampClient.Callback)} is called and every time a connection is established to |
| 49 | + * the Server. For WebSocket clients this is called after the handshake is completed without any |
| 50 | + * error. For HTTP clients this is called for any request if the response status is OK. |
| 51 | + * |
| 52 | + * @param client The relevant {@link OpampClient} instance. |
| 53 | + */ |
| 54 | + void onConnect(OpampClient client); |
| 55 | + |
| 56 | + /** |
| 57 | + * Called when the connection to the Server cannot be established. May be called after {@link |
| 58 | + * #start(OpampClient.Callback)} is called and tries to connect to the Server. May also be |
| 59 | + * called if the connection is lost and reconnection attempt fails. |
| 60 | + * |
| 61 | + * @param client The relevant {@link OpampClient} instance. |
| 62 | + * @param throwable The exception. |
| 63 | + */ |
| 64 | + void onConnectFailed(OpampClient client, Throwable throwable); |
| 65 | + |
| 66 | + /** |
| 67 | + * Called when the Server reports an error in response to some previously sent request. Useful |
| 68 | + * for logging purposes. The Agent should not attempt to process the error by reconnecting or |
| 69 | + * retrying previous operations. The client handles the ErrorResponse_UNAVAILABLE case |
| 70 | + * internally by performing retries as necessary. |
| 71 | + * |
| 72 | + * @param client The relevant {@link OpampClient} instance. |
| 73 | + * @param errorResponse The error returned by the Server. |
| 74 | + */ |
| 75 | + void onErrorResponse(OpampClient client, Opamp.ServerErrorResponse errorResponse); |
| 76 | + |
| 77 | + /** |
| 78 | + * Called when the Agent receives a message that needs processing. See {@link MessageData} |
| 79 | + * definition for the data that may be available for processing. During onMessage execution the |
| 80 | + * {@link OpampClient} functions that change the status of the client may be called, e.g. if |
| 81 | + * RemoteConfig is processed then {@link |
| 82 | + * #setRemoteConfigStatus(opamp.proto.Opamp.RemoteConfigStatus)} should be called to reflect the |
| 83 | + * processing result. These functions may also be called after onMessage returns. This is |
| 84 | + * advisable if processing can take a long time. In that case returning quickly is preferable to |
| 85 | + * avoid blocking the {@link OpampClient}. |
| 86 | + * |
| 87 | + * @param client The relevant {@link OpampClient} instance. |
| 88 | + * @param messageData The server response data that needs processing. |
| 89 | + */ |
| 90 | + void onMessage(OpampClient client, MessageData messageData); |
| 91 | + } |
| 92 | +} |
0 commit comments