From 579c51f6d44ddabafecfe57dccf83c8bbcaf56fb Mon Sep 17 00:00:00 2001 From: Julien Dubois Date: Thu, 22 Aug 2019 19:16:12 +0200 Subject: [PATCH 1/2] Reduce the logging output for "Backoff has been reset" As mentioned in #894 this message floods the console during development. I don't think it should be totally removed (anyway it shouldn't be commented out!), as it can be interesting to know everything went well, when you are debugging. Fix #894 --- .../internal/channel/common/TransmissionPolicyManager.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/com/microsoft/applicationinsights/internal/channel/common/TransmissionPolicyManager.java b/core/src/main/java/com/microsoft/applicationinsights/internal/channel/common/TransmissionPolicyManager.java index c074b48d553..d27210e44ba 100644 --- a/core/src/main/java/com/microsoft/applicationinsights/internal/channel/common/TransmissionPolicyManager.java +++ b/core/src/main/java/com/microsoft/applicationinsights/internal/channel/common/TransmissionPolicyManager.java @@ -129,7 +129,7 @@ public void backoff() { public void clearBackoff() { policyState.setCurrentState(TransmissionPolicy.UNBLOCKED); backoffManager.onDoneSending(); -// InternalLogger.INSTANCE.info("Backoff has been reset."); + InternalLogger.INSTANCE.trace("Backoff has been reset."); } /** From b71aca6811e64ea969216ae25d2401fe014bafe9 Mon Sep 17 00:00:00 2001 From: littleaj <1690572+littleaj@users.noreply.github.com> Date: Fri, 23 Aug 2019 14:33:54 -0700 Subject: [PATCH 2/2] update TransmissionPolicyState to signal if state changed. only log if state changes from BLOCKED->UNBLOCKED. use AtomicReference instead of volatile. --- .../channel/common/TransmissionPolicyManager.java | 5 +++-- .../channel/common/TransmissionPolicyState.java | 10 ++++++---- .../channel/common/TransmissionPolicyStateSetter.java | 7 ++++++- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/core/src/main/java/com/microsoft/applicationinsights/internal/channel/common/TransmissionPolicyManager.java b/core/src/main/java/com/microsoft/applicationinsights/internal/channel/common/TransmissionPolicyManager.java index d27210e44ba..1dd935a2423 100644 --- a/core/src/main/java/com/microsoft/applicationinsights/internal/channel/common/TransmissionPolicyManager.java +++ b/core/src/main/java/com/microsoft/applicationinsights/internal/channel/common/TransmissionPolicyManager.java @@ -127,9 +127,10 @@ public void backoff() { * Clear the current thread state and and reset the back off counter. */ public void clearBackoff() { - policyState.setCurrentState(TransmissionPolicy.UNBLOCKED); + if (policyState.setCurrentState(TransmissionPolicy.UNBLOCKED)) { + InternalLogger.INSTANCE.trace("Backoff has been reset."); + } backoffManager.onDoneSending(); - InternalLogger.INSTANCE.trace("Backoff has been reset."); } /** diff --git a/core/src/main/java/com/microsoft/applicationinsights/internal/channel/common/TransmissionPolicyState.java b/core/src/main/java/com/microsoft/applicationinsights/internal/channel/common/TransmissionPolicyState.java index 14506e520db..218db192536 100644 --- a/core/src/main/java/com/microsoft/applicationinsights/internal/channel/common/TransmissionPolicyState.java +++ b/core/src/main/java/com/microsoft/applicationinsights/internal/channel/common/TransmissionPolicyState.java @@ -21,19 +21,21 @@ package com.microsoft.applicationinsights.internal.channel.common; +import java.util.concurrent.atomic.AtomicReference; + /** * Created by gupele on 6/29/2015. */ final class TransmissionPolicyState implements TransmissionPolicyStateFetcher, TransmissionPolicyStateSetter { - private volatile TransmissionPolicy currentState = TransmissionPolicy.UNBLOCKED; + private AtomicReference currentState = new AtomicReference<>(TransmissionPolicy.UNBLOCKED); @Override public TransmissionPolicy getCurrentState() { - return currentState; + return currentState.get(); } @Override - public void setCurrentState(TransmissionPolicy currentState) { - this.currentState = currentState; + public boolean setCurrentState(TransmissionPolicy newState) { + return this.currentState.getAndSet(newState) != newState; } } diff --git a/core/src/main/java/com/microsoft/applicationinsights/internal/channel/common/TransmissionPolicyStateSetter.java b/core/src/main/java/com/microsoft/applicationinsights/internal/channel/common/TransmissionPolicyStateSetter.java index 423e8d27264..00b62e13ac3 100644 --- a/core/src/main/java/com/microsoft/applicationinsights/internal/channel/common/TransmissionPolicyStateSetter.java +++ b/core/src/main/java/com/microsoft/applicationinsights/internal/channel/common/TransmissionPolicyStateSetter.java @@ -25,5 +25,10 @@ * Created by gupele on 6/29/2015. */ interface TransmissionPolicyStateSetter { - void setCurrentState(TransmissionPolicy currentState); + /** + * Sets the current TransmissionPolicy state. + * @param newState The new value for current state + * @return true if the state changed (newState != currentState); false otherwise. + */ + boolean setCurrentState(TransmissionPolicy newState); }