5252 */
5353public final class TransmissionPolicyManager implements Stoppable , TransmissionHandlerObserver {
5454
55- private int INSTANT_RETRY_AMOUNT = 3 ; // Should always be set by the creator of this class
56- private int INSTANT_RETRY_MAX = 10 ; // Stops us from getting into an endless loop
57-
58- // Current thread backoff manager
59- private SenderThreadsBackOffManager backoffManager ;
60-
61- // List of transmission policies implemented as handlers
62- private List <TransmissionHandler > transmissionHandlers ;
63-
55+ private int instantRetryAmount = 3 ; // Should always be set by the creator of this class
56+ private final int INSTANT_RETRY_MAX = 10 ; // Stops us from getting into an endless loop
57+
58+ // Current thread backoff manager
59+ private SenderThreadsBackOffManager backoffManager ;
60+
61+ // List of transmission policies implemented as handlers
62+ private List <TransmissionHandler > transmissionHandlers ;
63+
6464 // The future date the the transmission is blocked
6565 private Date suspensionDate ;
6666
@@ -95,7 +95,7 @@ public void run() {
9595
9696 /**
9797 * Create the {@link TransmissionPolicyManager} and set the ability to throttle.
98- * @param throttlingIsEnabled Set whether the {@link TransmissionPolicyManager} can be throttled.
98+ * @param throttlingIsEnabled Set whether the {@link TransmissionPolicyManager} can be throttled.
9999 */
100100 public TransmissionPolicyManager (boolean throttlingIsEnabled ) {
101101 suspensionDate = null ;
@@ -104,32 +104,32 @@ public TransmissionPolicyManager(boolean throttlingIsEnabled) {
104104 this .backoffManager = new SenderThreadsBackOffManager (new ExponentialBackOffTimesPolicy ());
105105 }
106106
107- /**
107+ /**
108108 * Suspend the transmission thread according to the current back off policy.
109109 */
110110 public void backoff () {
111- policyState .setCurrentState (TransmissionPolicy .BACKOFF );
112- long backOffMillis = backoffManager .backOffCurrentSenderThreadValue ();
113- if (backOffMillis > 0 )
111+ policyState .setCurrentState (TransmissionPolicy .BACKOFF );
112+ long backOffMillis = backoffManager .backOffCurrentSenderThreadValue ();
113+ if (backOffMillis > 0 )
114114 {
115115 long backOffSeconds = backOffMillis / 1000 ;
116116 InternalLogger .INSTANCE .info ("App is throttled, telemetry will be blocked for %s seconds." , backOffSeconds );
117117 this .suspendInSeconds (TransmissionPolicy .BACKOFF , backOffSeconds );
118- }
118+ }
119119 }
120-
120+
121121 /**
122122 * Clear the current thread state and and reset the back off counter.
123123 */
124124 public void clearBackoff () {
125- policyState .setCurrentState (TransmissionPolicy .UNBLOCKED );
125+ policyState .setCurrentState (TransmissionPolicy .UNBLOCKED );
126126 backoffManager .onDoneSending ();
127127 InternalLogger .INSTANCE .info ("Backoff has been reset." );
128128 }
129-
129+
130130 /**
131131 * Suspend this transmission thread using the specified policy
132- * @param policy The {@link TransmissionPolicy} to use for suspension
132+ * @param policy The {@link TransmissionPolicy} to use for suspension
133133 * @param suspendInSeconds The number of seconds to suspend.
134134 */
135135 public void suspendInSeconds (TransmissionPolicy policy , long suspendInSeconds ) {
@@ -162,12 +162,12 @@ public TransmissionPolicyStateFetcher getTransmissionPolicyState() {
162162
163163 private synchronized void doSuspend (TransmissionPolicy policy , long suspendInSeconds ) {
164164 try {
165- if (policy == TransmissionPolicy .UNBLOCKED ) {
165+ if (policy == TransmissionPolicy .UNBLOCKED ) {
166166 return ;
167167 }
168-
168+
169169 Date date = Calendar .getInstance ().getTime ();
170- date .setTime (date .getTime () + 1000 * suspendInSeconds );
170+ date .setTime (date .getTime () + ( 1000 * suspendInSeconds ) );
171171 if (this .suspensionDate != null ) {
172172 long diff = date .getTime () - suspensionDate .getTime ();
173173 if (diff <= 0 ) {
@@ -214,36 +214,36 @@ public Thread newThread(Runnable r) {
214214
215215 SDKShutdownActivity .INSTANCE .register (this );
216216 }
217-
218- @ Override
219- public void onTransmissionSent (TransmissionHandlerArgs transmissionArgs ) {
220- for (TransmissionHandler handler : this .transmissionHandlers ) {
221- handler .onTransmissionSent (transmissionArgs );
222- }
223- }
224-
225- @ Override
226- public void addTransmissionHandler (TransmissionHandler handler ) {
227- if (handler != null ) {
228- this .transmissionHandlers .add (handler );
229- }
230- }
231-
232- /**
233- * Set the number of retries before performing a back off operation.
234- * @param maxInstantRetries Number of retries
235- */
236- public void setMaxInstantRetries (int maxInstantRetries ) {
237- if (maxInstantRetries >= 0 && maxInstantRetries < INSTANT_RETRY_MAX ) {
238- INSTANT_RETRY_AMOUNT = maxInstantRetries ;
239- }
240- }
241-
242- /**
243- * Get the number of retries before performing a back off operation.
244- * @return Number of retries
245- */
246- public int getMaxInstantRetries () {
247- return INSTANT_RETRY_AMOUNT ;
248- }
217+
218+ @ Override
219+ public void onTransmissionSent (TransmissionHandlerArgs transmissionArgs ) {
220+ for (TransmissionHandler handler : this .transmissionHandlers ) {
221+ handler .onTransmissionSent (transmissionArgs );
222+ }
223+ }
224+
225+ @ Override
226+ public void addTransmissionHandler (TransmissionHandler handler ) {
227+ if (handler != null ) {
228+ this .transmissionHandlers .add (handler );
229+ }
230+ }
231+
232+ /**
233+ * Set the number of retries before performing a back off operation.
234+ * @param maxInstantRetries Number of retries
235+ */
236+ public void setMaxInstantRetries (int maxInstantRetries ) {
237+ if (maxInstantRetries > 0 && maxInstantRetries < INSTANT_RETRY_MAX ) {
238+ instantRetryAmount = maxInstantRetries ;
239+ }
240+ }
241+
242+ /**
243+ * Get the number of retries before performing a back off operation.
244+ * @return Number of retries
245+ */
246+ public int getMaxInstantRetries () {
247+ return instantRetryAmount ;
248+ }
249249}
0 commit comments