Skip to content

Commit

Permalink
Improved TransportException implementation
Browse files Browse the repository at this point in the history
Signed-off-by: Alberto Codutti <alberto.codutti@eurotech.com>
  • Loading branch information
Coduz committed Aug 2, 2023
1 parent 2f7bf35 commit 0f8bd91
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
public class TransportClientGetException extends TransportException {

private final String serverIp;
private final String causeMessage;

/**
* Constructor.
Expand All @@ -33,6 +34,7 @@ public TransportClientGetException(@NotNull String serverIp) {
super(TransportErrorCodes.CLIENT_GET, serverIp);

this.serverIp = serverIp;
this.causeMessage = null;
}

/**
Expand All @@ -43,17 +45,31 @@ public TransportClientGetException(@NotNull String serverIp) {
* @since 1.2.0
*/
public TransportClientGetException(@NotNull Throwable cause, @NotNull String serverIp) {
super(TransportErrorCodes.CLIENT_GET, cause, serverIp);
super(TransportErrorCodes.CLIENT_GET_WITH_CAUSE, cause, serverIp, cause.getMessage());

this.serverIp = serverIp;
this.causeMessage = cause.getMessage();
}

/**
* Gets the IP to which we wanted unsuccessfully to connect.
*
* @return The IP to which we wanted unsuccessfully to connect.
* @since 1.2.0
* @deprecated Since 2.0.0. It was not renamed after copy-pasting from another class. Please make use of {@link #getServerIp()}.
*/
@Deprecated
public String getRequestMessage() {
return getServerIp();
}

/**
* Gets the IP to which we wanted unsuccessfully to connect.
*
* @return The IP to which we wanted unsuccessfully to connect.
* @since 2.0.0
*/
public String getServerIp() {
return serverIp;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public TransportClientPoolExhaustedException(@NotNull Throwable cause, @NotNull
* @return The IP to which we wanted unsuccessfully to connect.
* @since 2.0.0
*/
public String getRequestMessage() {
public String getServerIp() {
return serverIp;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ public enum TransportErrorCodes implements KapuaErrorCode {
*/
SEND_ERROR,

/**
* @see TransportSendException
* @since 2.0.0
*/
SEND_ERROR_WITH_CAUSE,

/**
* @see TransportTimeoutException
* @since 1.1.0
Expand All @@ -39,6 +45,12 @@ public enum TransportErrorCodes implements KapuaErrorCode {
*/
CLIENT_GET,

/**
* @see TransportClientGetException
* @since 2.0.0
*/
CLIENT_GET_WITH_CAUSE,

/**
* @see TransportClientPoolExhaustedException
* @since 2.0.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,20 @@
*/
public class TransportSendException extends TransportException {

private final TransportMessage requestMessage;
private final TransportMessage<?, ?> requestMessage;
private final String causeMessage;

/**
* Constructor.
*
* @param requestMessage The {@link TransportMessage} that we tried to send.
* @since 1.1.0
*/
public TransportSendException(@NotNull TransportMessage requestMessage) {
this(null, requestMessage);
public TransportSendException(@NotNull TransportMessage<?, ?> requestMessage) {
super(TransportErrorCodes.SEND_ERROR, requestMessage);

this.requestMessage = requestMessage;
this.causeMessage = null;
}

/**
Expand All @@ -42,10 +46,11 @@ public TransportSendException(@NotNull TransportMessage requestMessage) {
* @param requestMessage The {@link TransportMessage} that we tried to send.
* @since 1.1.0
*/
public TransportSendException(@NotNull Throwable cause, @NotNull TransportMessage requestMessage) {
super(TransportErrorCodes.SEND_ERROR, cause, requestMessage);
public TransportSendException(@NotNull Throwable cause, @NotNull TransportMessage<?, ?> requestMessage) {
super(TransportErrorCodes.SEND_ERROR_WITH_CAUSE, cause, requestMessage, cause.getMessage());

this.requestMessage = requestMessage;
this.causeMessage = cause.getMessage();
}

/**
Expand All @@ -54,7 +59,7 @@ public TransportSendException(@NotNull Throwable cause, @NotNull TransportMessag
* @return The {@link TransportMessage} that we tried to send.
* @since 1.1.0
*/
public TransportMessage getRequestMessage() {
public TransportMessage<?, ?> getRequestMessage() {
return requestMessage;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
# Eurotech - initial API and implementation
#
###############################################################################
CLIENT_GET=Cannot get an instance of the transport client to connect to host: {0}
CLIENT_POOL_EXHAUSTED=Cannot get an instance of the transport client to connect to host {0} within the configured timeout of {1}. This means that the pool is currently exhausted.
CLIENT_GET=Cannot get an instance of the TransportClient to connect to host: {0}
CLIENT_GET_WITH_CAUSE=Cannot get an instance of the TransportClient to connect to host: {0}. Caused by: {1}
CLIENT_POOL_EXHAUSTED=Cannot get an instance of the TransportClient to connect to host {0} within the configured timeout of {1}ms
SEND_ERROR=An error occurred when sending the message: {0}
SEND_ERROR_WITH_CAUSE=An error occurred when sending the message: {0}. Caused by: {1}
TIMEOUT=The request has not received a response within the timeout of: {0}ms

0 comments on commit 0f8bd91

Please sign in to comment.