Skip to content

Commit

Permalink
Widened interface of ConnectionMonitor to accept Throwable instea…
Browse files Browse the repository at this point in the history
…d of `Exception`. This change does not affect functionality of `ConnectionMonitor` at all, but it makes it easier to use without superfluous `instanceof` checks.

Signed-off-by: Juergen Fickel <juergen.fickel@bosch.io>
  • Loading branch information
Juergen Fickel committed Apr 14, 2022
1 parent 8e4fd81 commit 737459c
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 21 deletions.
Expand Up @@ -206,11 +206,10 @@ default void failure(final ExternalMessage externalMessage, final String message

/**
* Record an exception event.
*
* @param signal that was processed during the exception.
* @param signal that was processed during the exception.
* @param exception the exception.
*/
default void exception(final Signal<?> signal, final Exception exception) {
default void exception(final Signal<?> signal, final Throwable exception) {
exception(InfoProviderFactory.forSignal(signal), exception);
}

Expand All @@ -219,27 +218,25 @@ default void exception(final Signal<?> signal, final Exception exception) {
*
* @param exception the exception.
*/
default void exception(final Exception exception) {
default void exception(final Throwable exception) {
exception(InfoProviderFactory.empty(), exception);
}

/**
* Record an exception event.
*
* @param headers that were processed during the exception.
* @param headers that were processed during the exception.
* @param exception the exception.
*/
default void exception(final Map<String, String> headers, final Exception exception) {
default void exception(final Map<String, String> headers, final Throwable exception) {
exception(InfoProviderFactory.forHeaders(headers), exception);
}

/**
* Record an exception event.
*
* @param externalMessage that was processed during the success event.
* @param externalMessage that was processed during the success event.
* @param exception the exception that caused the failure.
*/
default void exception(final ExternalMessage externalMessage, final Exception exception) {
default void exception(final ExternalMessage externalMessage, final Throwable exception) {
exception(InfoProviderFactory.forExternalMessage(externalMessage), exception);
}

Expand All @@ -256,11 +253,10 @@ default void exception(final String message, final Object... messageArguments) {

/**
* Record an exception event.
*
* @param infoProvider that provides useful information for the success event.
* @param infoProvider that provides useful information for the success event.
* @param exception the exception that caused the failure.
*/
default void exception(final InfoProvider infoProvider, final Exception exception) {
default void exception(final InfoProvider infoProvider, final Throwable exception) {
getLogger().exception(infoProvider, exception);
getCounter().recordFailure();
}
Expand All @@ -273,8 +269,7 @@ default void exception(final InfoProvider infoProvider, final Exception exceptio
* @param messageArguments additional message arguments that are part of {@code message}.
* {@link java.text.MessageFormat#format(String, Object...)} is used for applying message arguments to {@code message}.
*/
default void exception(final Map<String, String> headers, final String message,
final Object... messageArguments) {
default void exception(final Map<String, String> headers, final String message, final Object... messageArguments) {
getLogger().exception(InfoProviderFactory.forHeaders(headers), message, messageArguments);
getCounter().recordFailure();
}
Expand All @@ -287,8 +282,10 @@ default void exception(final Map<String, String> headers, final String message,
* @param messageArguments additional message arguments that are part of {@code message}.
* {@link java.text.MessageFormat#format(String, Object...)} is used for applying message arguments to {@code message}.
*/
default void exception(final ExternalMessage externalMessage, final String message,
default void exception(final ExternalMessage externalMessage,
final String message,
final Object... messageArguments) {

getLogger().exception(InfoProviderFactory.forExternalMessage(externalMessage), message, messageArguments);
getCounter().recordFailure();
}
Expand Down
Expand Up @@ -84,7 +84,7 @@ public void failure(final ConnectionMonitor.InfoProvider infoProvider,
}

@Override
public void exception(final ConnectionMonitor.InfoProvider infoProvider, @Nullable final Exception exception) {
public void exception(final ConnectionMonitor.InfoProvider infoProvider, @Nullable final Throwable exception) {
if (null != exception) {
exception(infoProvider, defaultExceptionMessage, type.getType(), exception.getMessage());
} else {
Expand Down
Expand Up @@ -67,7 +67,7 @@ public void failure(final ConnectionMonitor.InfoProvider infoProvider, final Str
}

@Override
public void exception(final ConnectionMonitor.InfoProvider infoProvider, @Nullable final Exception exception) {
public void exception(final ConnectionMonitor.InfoProvider infoProvider, @Nullable final Throwable exception) {
connectionLoggers.forEach(logger -> logger.exception(infoProvider, exception));
}

Expand Down
Expand Up @@ -89,7 +89,7 @@ static ConnectionLogger getInstance(final ConnectionId connectionId, final Monit
* @param infoProvider containing additional information on the event.
* @param exception the exception that caused a failure. Its message is used in the log entry.
*/
void exception(ConnectionMonitor.InfoProvider infoProvider, @Nullable Exception exception);
void exception(ConnectionMonitor.InfoProvider infoProvider, @Nullable Throwable exception);

/**
* Log an exception event.
Expand Down
Expand Up @@ -125,7 +125,7 @@ public void failure(final ConnectionMonitor.InfoProvider infoProvider, final Str
}

@Override
public void exception(final ConnectionMonitor.InfoProvider infoProvider, @Nullable final Exception exception) {
public void exception(final ConnectionMonitor.InfoProvider infoProvider, @Nullable final Throwable exception) {
if (isMuted()) {
logTraceWithCorrelationId(infoProvider.getCorrelationId(), "Not logging exception since logger is muted.");
} else {
Expand Down
Expand Up @@ -93,7 +93,7 @@ public void failure(final ConnectionMonitor.InfoProvider infoProvider, final Str
}

@Override
public void exception(final ConnectionMonitor.InfoProvider infoProvider, @Nullable final Exception exception) {
public void exception(final ConnectionMonitor.InfoProvider infoProvider, @Nullable final Throwable exception) {
logTraceWithCorrelationId(infoProvider.getCorrelationId(),
"Not logging exception <{}> since logger is exceptional.",
exception);
Expand Down

0 comments on commit 737459c

Please sign in to comment.