Skip to content

Commit

Permalink
clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
lmolkova committed Nov 30, 2021
1 parent 3b744f5 commit c387fc0
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,21 +48,13 @@ public boolean isInitiatedByClient() {
return isInitiatedByClient;
}

public LoggingEventBuilder addContext(LoggingEventBuilder logBuilder) {
return logBuilder
.addKeyValue("isTransient", isTransient)
.addKeyValue("isInitiatedByClient", isInitiatedByClient)
.addKeyValue("shutdownMessage", message);
}

/**
* Returns String representing this {@code AmqpShutdownSignal} signal.
*
* <strong>To write logs, please use {@link AmqpShutdownSignal#addContext} instead.</strong>
* <strong>To write logs, please use {@link com.azure.core.amqp.implementation.AmqpLoggingUtils#addShutdownSignal(LoggingEventBuilder, AmqpShutdownSignal)}.</strong>
*/
@Override
public String toString() {
return String.format(Locale.US, "%s, isTransient[%s], initiatedByClient[%s]", message, isTransient,
isInitiatedByClient);
return message;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import com.azure.core.util.logging.ClientLogger;
import com.azure.core.util.logging.ClientLogger;

import static com.azure.core.amqp.implementation.AmqpLoggingUtils.addShutdownSignal;

/**
* Handles exceptions generated by AMQP connections, sessions, and/or links.
*/
Expand Down Expand Up @@ -34,7 +36,6 @@ void onConnectionError(Throwable exception) {
* @param shutdownSignal The shutdown signal that was received.
*/
void onConnectionShutdown(AmqpShutdownSignal shutdownSignal) {
shutdownSignal
.addContext(logger.atInfo()).log("Shutdown received");
addShutdownSignal(logger.atInfo(), shutdownSignal).log("Shutdown received");
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.azure.core.amqp.implementation;

import com.azure.core.amqp.AmqpShutdownSignal;
import com.azure.core.util.logging.LoggingEventBuilder;
import org.apache.qpid.proton.amqp.transport.ErrorCondition;
import reactor.core.publisher.SignalType;
Expand Down Expand Up @@ -29,5 +30,13 @@ public static LoggingEventBuilder addErrorCondition(LoggingEventBuilder logBuild
.addKeyValue(ERROR_CONDITION_KEY, errorCondition.getCondition())
.addKeyValue(ERROR_DESCRIPTION_KEY, errorCondition.getDescription());
}

public static LoggingEventBuilder addShutdownSignal(LoggingEventBuilder logBuilder, AmqpShutdownSignal shutdownSignal) {
return logBuilder
.addKeyValue("isTransient", shutdownSignal.isTransient())
.addKeyValue("isInitiatedByClient", shutdownSignal.isInitiatedByClient())
// will call toString() if logging is enabled
.addKeyValue("shutdownMessage", shutdownSignal);
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import java.util.concurrent.RejectedExecutionException;
import java.util.concurrent.atomic.AtomicBoolean;

import static com.azure.core.amqp.implementation.AmqpLoggingUtils.addShutdownSignal;
import static com.azure.core.amqp.implementation.AmqpLoggingUtils.addSignalTypeAndResult;
import static com.azure.core.amqp.implementation.ClientConstants.CONNECTION_ID_KEY;
import static com.azure.core.amqp.implementation.ClientConstants.EMIT_RESULT_KEY;
Expand Down Expand Up @@ -423,12 +424,12 @@ public Mono<Void> closeAsync() {
}

Mono<Void> closeAsync(AmqpShutdownSignal shutdownSignal) {
shutdownSignal.addContext(logger.atInfo()).log("Disposing of ReactorConnection.");
addShutdownSignal(logger.atInfo(), shutdownSignal).log("Disposing of ReactorConnection.");
final Sinks.EmitResult result = shutdownSignalSink.tryEmitValue(shutdownSignal);

if (result.isFailure()) {
// It's possible that another one was already emitted, so it's all good.
shutdownSignal.addContext(logger.atInfo())
addShutdownSignal(logger.atInfo(), shutdownSignal)
.addKeyValue(EMIT_RESULT_KEY, result)
.log("Unable to emit shutdown signal.");
}
Expand Down Expand Up @@ -618,7 +619,7 @@ public void onConnectionError(Throwable exception) {

@Override
void onConnectionShutdown(AmqpShutdownSignal shutdownSignal) {
shutdownSignal.addContext(logger.atInfo())
addShutdownSignal(logger.atInfo(), shutdownSignal)
.addKeyValue(FULLY_QUALIFIED_NAMESPACE_KEY, getFullyQualifiedNamespace())
.log("onConnectionShutdown. Shutting down.");

Expand Down

0 comments on commit c387fc0

Please sign in to comment.