com.backendless.utils.timeout.TimeOutManagerImpl Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of java-sdk-common Show documentation
Show all versions of java-sdk-common Show documentation
Provides access to Backendless API
The newest version!
package com.backendless.utils.timeout;
public class TimeOutManagerImpl implements TimeOutManager
{
private static final int INITIAL_TIMEOUT = 200;
private static final int MAX_TIMEOUT = 60 * 1000; //1 min
private static final int REPEAT_TIMES_BEFORE_INCREASE = 10;
private int repeatedTimes;
private int currentTimeOut;
public TimeOutManagerImpl()
{
reset();
}
@Override
public int nextTimeout()
{
if( currentTimeOut > MAX_TIMEOUT )
return MAX_TIMEOUT;
if( repeatedTimes++ > 0 && ( repeatedTimes % REPEAT_TIMES_BEFORE_INCREASE ) == 0 )
{
currentTimeOut *= 2;
}
return currentTimeOut;
}
@Override
public int repeatedTimes()
{
return repeatedTimes;
}
@Override
public void reset()
{
repeatedTimes = 0;
currentTimeOut = INITIAL_TIMEOUT;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy