mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-16 15:41:16 +01:00
use max backoff time if no relay games
This commit is contained in:
parent
edcafe1c45
commit
f394bcef64
2 changed files with 45 additions and 13 deletions
|
@ -414,6 +414,34 @@ public class DBUtils {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static int countOpenGamesUsingRelay( Context context )
|
||||||
|
{
|
||||||
|
int result = 0;
|
||||||
|
String[] columns = { DBHelper.CONTYPE };
|
||||||
|
String selection = String.format( "%s = 0", DBHelper.GAME_OVER );
|
||||||
|
|
||||||
|
initDB( context );
|
||||||
|
synchronized( s_dbHelper ) {
|
||||||
|
SQLiteDatabase db = s_dbHelper.getReadableDatabase();
|
||||||
|
Cursor cursor = db.query( DBHelper.TABLE_NAME_SUM, columns,
|
||||||
|
selection, null, null, null, null );
|
||||||
|
int indx = cursor.getColumnIndex( DBHelper.CONTYPE );
|
||||||
|
while ( cursor.moveToNext() ) {
|
||||||
|
CommsConnTypeSet typs = new CommsConnTypeSet( cursor.getInt(indx) );
|
||||||
|
if ( typs.contains( CommsConnType.COMMS_CONN_RELAY ) ) {
|
||||||
|
++result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
cursor.close();
|
||||||
|
db.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
// DbgUtils.logd( DBUtils.class, "countOpenGamesUsingRelay() => %d", result );
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
public static class SentInvitesInfo {
|
public static class SentInvitesInfo {
|
||||||
public long m_rowid;
|
public long m_rowid;
|
||||||
private ArrayList<InviteMeans> m_means;
|
private ArrayList<InviteMeans> m_means;
|
||||||
|
|
|
@ -1392,22 +1392,26 @@ public class RelayService extends XWService
|
||||||
|
|
||||||
private int figureBackoffSeconds() {
|
private int figureBackoffSeconds() {
|
||||||
// DbgUtils.printStack();
|
// DbgUtils.printStack();
|
||||||
long diff;
|
int result = 60 * 60; // default if no games
|
||||||
synchronized ( RelayService.class ) {
|
if ( 0 < DBUtils.countOpenGamesUsingRelay( this ) ) {
|
||||||
long now = Utils.getCurSeconds();
|
long diff;
|
||||||
if ( s_curNextTimer <= now ) {
|
synchronized ( RelayService.class ) {
|
||||||
if ( 0 == s_curBackoff ) {
|
long now = Utils.getCurSeconds();
|
||||||
s_curBackoff = 15;
|
if ( s_curNextTimer <= now ) {
|
||||||
|
if ( 0 == s_curBackoff ) {
|
||||||
|
s_curBackoff = 15;
|
||||||
|
}
|
||||||
|
s_curBackoff = Math.min( 2 * s_curBackoff, result );
|
||||||
|
s_curNextTimer += s_curBackoff;
|
||||||
}
|
}
|
||||||
s_curBackoff = Math.min( 2 * s_curBackoff, 60*60 );
|
|
||||||
s_curNextTimer += s_curBackoff;
|
|
||||||
}
|
|
||||||
|
|
||||||
diff = s_curNextTimer - now;
|
diff = s_curNextTimer - now;
|
||||||
|
}
|
||||||
|
Assert.assertTrue( diff < Integer.MAX_VALUE );
|
||||||
|
DbgUtils.logd( getClass(), "figureBackoffSeconds() => %d", diff );
|
||||||
|
result = (int)diff;
|
||||||
}
|
}
|
||||||
Assert.assertTrue( diff < Integer.MAX_VALUE );
|
return result;
|
||||||
DbgUtils.logd( getClass(), "figureBackoffSeconds() => %d", diff );
|
|
||||||
return (int)diff;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private class PacketHeader {
|
private class PacketHeader {
|
||||||
|
|
Loading…
Reference in a new issue