Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[#486] - Change Sync Timing Logic; Fixed Android build

  • Loading branch information...
commit 3eec9b549e4a7b87cb4ffd44ffa334ae472f97c3 1 parent 91bceef
@genywind genywind authored
View
2  .gitignore
@@ -50,7 +50,7 @@ platform/android/Rhodes/assets
platform/android/Rhodes/bin
platform/android/Rhodes/libs
platform/android/**/bin
-
+platform/android/bin
platform/shared/*/bin
#*.jar
View
5 platform/android/Rhodes/src/com/rhomobile/rhodes/db/SqliteDBResult.java
@@ -228,6 +228,11 @@ public int getIntByIdx(int col) {
return val != null ? Integer.parseInt(val) : 0;
}
+ public long getLongByIdx(int col) {
+ String val = getValueByIdx(curIndex,col);
+ return val != null ? Long.parseLong(val) : 0;
+ }
+
public String getUInt64ByIdx(int nCol)
{
return getStringByIdx(nCol);
View
1  platform/android/build/RubyVM_build.files
@@ -35,6 +35,7 @@ platform/shared/rubyJVM/src/com/rho/sync/JSONEntry.java
platform/shared/rubyJVM/src/com/rho/sync/SyncEngine.java
platform/shared/rubyJVM/src/com/rho/sync/SyncSource.java
platform/shared/rubyJVM/src/com/rho/sync/SyncThread.java
+platform/shared/rubyJVM/src/com/rho/sync/ISyncStatusListener.java
platform/shared/rubyJVM/src/com/rho/TestProfiler.java
platform/shared/rubyJVM/src/com/rho/TestRhoLog.java
platform/shared/rubyJVM/src/com/rho/TimeInterval.java
View
4 platform/bb/.BB.jdw/BB.jdw
@@ -1,9 +1,5 @@
## RIM Java Development Environment
# RIM Workspace file
-#
-# This file is generated and managed by BlackBerry developer tools.
-# It SHOULD NOT BE modified manually.
-#
[BuildConfigurations
Debug
Release
View
7 platform/bb/Hsqldb/src/com/rho/db/HsqlDBResult.java
@@ -174,6 +174,12 @@ public int getIntByIdx(int nCol)
return val != null ? Number.intValue(val) : 0;
}
+ public long getLongByIdx(int nCol)
+ {
+ Object val = m_current.data[nCol];
+ return val != null ? Number.longValue(val) : 0;
+ }
+
public String getUInt64ByIdx(int nCol)
{
return getStringByIdx(nCol);
@@ -203,6 +209,7 @@ public RubyValue getRubyValueByIdx(int nCol)
case Types.BIGINT :
return ObjectFactory.createInteger(Number.longValue(val));
+
case Types.REAL :
case Types.FLOAT :
case Types.DOUBLE :
View
6 platform/bb/Hsqldb/src/org/hsqldb/Types.java
@@ -468,9 +468,9 @@
static {
typeAliases = new IntValueHashMap(50);
- typeAliases.put("INTEGER", Types.INTEGER);
- typeAliases.put("INT", Types.INTEGER);
- typeAliases.put("int", Types.INTEGER);
+ typeAliases.put("INTEGER", Types.BIGINT);
+ typeAliases.put("INT", Types.BIGINT);
+ typeAliases.put("int", Types.BIGINT);
typeAliases.put("java.lang.Integer", Types.INTEGER);
typeAliases.put("IDENTITY", Types.INTEGER);
typeAliases.put("DOUBLE", Types.DOUBLE);
View
2  platform/bb/RubyVM/RubyVM.jdp
@@ -49,11 +49,11 @@ ExcludeFromBuildAll=0
..\..\shared\rubyJVM\src\com\rho\RhoThread.java
..\..\shared\rubyJVM\src\com\rho\SimpleFile.java
..\..\shared\rubyJVM\src\com\rho\StringScanner.java
+..\..\shared\rubyJVM\src\com\rho\sync\ISyncStatusListener.java
..\..\shared\rubyJVM\src\com\rho\sync\JSONArrayIterator.java
..\..\shared\rubyJVM\src\com\rho\sync\JSONEntry.java
..\..\shared\rubyJVM\src\com\rho\sync\SyncEngine.java
..\..\shared\rubyJVM\src\com\rho\sync\SyncSource.java
-..\..\shared\rubyJVM\src\com\rho\sync\SyncStatusListener.java
..\..\shared\rubyJVM\src\com\rho\sync\SyncThread.java
..\..\shared\rubyJVM\src\com\rho\TestProfiler.java
..\..\shared\rubyJVM\src\com\rho\TestRhoLog.java
View
2  platform/bb/build/RubyVM_build.files
@@ -33,7 +33,7 @@ platform\shared\rubyJVM\src\com\rho\StringScanner.java
platform\shared\rubyJVM\src\com\rho\sync\JSONArrayIterator.java
platform\shared\rubyJVM\src\com\rho\sync\JSONEntry.java
platform\shared\rubyJVM\src\com\rho\sync\SyncEngine.java
-platform\shared\rubyJVM\src\com\rho\sync\SyncStatusListener.java
+platform\shared\rubyJVM\src\com\rho\sync\ISyncStatusListener.java
platform\shared\rubyJVM\src\com\rho\sync\SyncSource.java
platform\shared\rubyJVM\src\com\rho\sync\SyncThread.java
platform\shared\rubyJVM\src\com\rho\TestProfiler.java
View
4 platform/bb/rhodes/src/rhomobile/RhodesApplication.java
@@ -48,12 +48,12 @@
import com.rho.location.GeoLocation;
import com.rho.net.RhoConnection;
import com.rho.sync.SyncThread;
-import com.rho.sync.SyncStatusListener;
+import com.rho.sync.ISyncStatusListener;
/**
*
*/
-final public class RhodesApplication extends UiApplication implements RenderingApplication, SystemListener, SyncStatusListener
+final public class RhodesApplication extends UiApplication implements RenderingApplication, SystemListener, ISyncStatusListener
{
// Menu Labels
public static final String LABEL_HOME = "Home";
View
1  platform/shared/rubyJVM/src/com/rho/db/IDBResult.java
@@ -24,6 +24,7 @@
public abstract void next();
public abstract String getStringByIdx(int nCol);
public abstract int getIntByIdx(int nCol);
+ public abstract long getLongByIdx(int nCol);
public abstract String getUInt64ByIdx(int nCol);
public abstract RubyValue getRubyValueByIdx(int nCol);
View
2  .../rubyJVM/src/com/rho/sync/SyncStatusListener.java → ...rubyJVM/src/com/rho/sync/ISyncStatusListener.java
@@ -1,5 +1,5 @@
package com.rho.sync;
-public interface SyncStatusListener {
+public interface ISyncStatusListener {
public abstract void reportStatus(String status);
}
View
4 platform/shared/rubyJVM/src/com/rho/sync/SyncEngine.java
@@ -58,9 +58,9 @@
Mutex m_mxNotifications = new Mutex();
String m_strSession = "";
- SyncStatusListener m_statusListener = null;
+ ISyncStatusListener m_statusListener = null;
- public void setStatusListener(SyncStatusListener listener) { m_statusListener = listener; }
+ public void setStatusListener(ISyncStatusListener listener) { m_statusListener = listener; }
private void reportStatus(String status) {
if (m_statusListener != null) {
m_statusListener.reportStatus(status);
View
4 platform/shared/rubyJVM/src/com/rho/sync/SyncSource.java
@@ -98,7 +98,7 @@ boolean isTokenMoreThanOne()
m_nDeleted = 0;
}
- void sync(SyncStatusListener statusListener) throws Exception
+ void sync(ISyncStatusListener statusListener) throws Exception
{
String status_report = "Completed synchronization of the data source #" + getID();
@@ -373,7 +373,7 @@ void processToken(String token)throws DBException
}
- private void reportStatus(SyncStatusListener statusListener, String status) {
+ private void reportStatus(ISyncStatusListener statusListener, String status) {
if (statusListener != null) {
statusListener.reportStatus(status);
}
View
39 platform/shared/rubyJVM/src/com/rho/sync/SyncThread.java
@@ -81,16 +81,47 @@ public void Destroy()
void addSyncCommand(int curCommand){ m_curCommand = curCommand; stopWait(); }
void addSyncCommand(int curCommand, int nCmdParam){ m_curCommand = curCommand; m_nCmdParam = nCmdParam; stopWait(); }
+ int getLastSyncInterval()
+ {
+ try{
+ TimeInterval nowTime = TimeInterval.getCurrentTime();
+
+ IDBResult res = m_oSyncEngine.getDB().executeSQL("SELECT last_updated from sources");
+ long latestTimeUpdated = 0;
+ for ( ; !res.isEnd(); res.next() )
+ {
+ long timeUpdated = res.getLongByIdx(0);
+ if ( latestTimeUpdated < timeUpdated )
+ latestTimeUpdated = timeUpdated;
+ }
+
+ return latestTimeUpdated > 0 ? (int)(nowTime.toULong()-latestTimeUpdated) : 0;
+ }catch(Exception exc)
+ {
+ LOG.ERROR("isStartSyncNow failed.", exc);
+ }
+ return 0;
+ }
+
public void run()
{
LOG.INFO( "Starting sync engine main routine..." );
+ int nLastSyncInterval = getLastSyncInterval();
while( m_oSyncEngine.getState() != SyncEngine.esExit )
{
int nWait = m_nPollInterval > 0 ? m_nPollInterval : SYNC_POLL_INTERVAL_INFINITE;
- LOG.INFO( "Sync engine blocked for " + nWait + " seconds..." );
- wait(nWait);
-
+
+ if ( m_nPollInterval > 0 && nLastSyncInterval > 0 )
+ nWait = (m_nPollInterval*1000 - nLastSyncInterval)/1000;
+
+ if ( nWait >= 0 )
+ {
+ LOG.INFO( "Sync engine blocked for " + nWait + " seconds..." );
+ wait(nWait);
+ }
+ nLastSyncInterval = 0;
+
if ( m_oSyncEngine.getState() != SyncEngine.esExit )
{
try{
@@ -128,7 +159,7 @@ void processCommand()throws Exception
m_curCommand = scNone;
}
- public boolean setStatusListener(SyncStatusListener listener) {
+ public boolean setStatusListener(ISyncStatusListener listener) {
if (m_oSyncEngine != null) {
m_oSyncEngine.setStatusListener(listener);
return true;
View
3  platform/shared/sync/SyncEngine.h
@@ -86,8 +86,9 @@ class CSyncEngine
void fireNotification( CSyncSource& src, boolean bFinish );
-private:
db::CDBAdapter& getDB(){ return m_dbAdapter; }
+
+private:
net::INetRequest& getNet(){ return *m_NetRequest;}
CSyncSource* CSyncEngine::findSourceByID(int nSrcId);
View
36 platform/shared/sync/syncthread.cpp
@@ -1,8 +1,11 @@
#include "SyncThread.h"
+#include "common/RhoTime.h"
namespace rho {
namespace sync {
+using namespace rho::common;
+
IMPLEMENT_LOGCLASS(CSyncThread,"Sync");
CSyncThread* CSyncThread::m_pInstance = 0;
db::CDBAdapter CSyncThread::m_oDBAdapter;
@@ -36,15 +39,42 @@ CSyncThread::CSyncThread(common::IRhoClassFactory* factory) : CRhoThread(factory
start(epLow);
}
+int CSyncThread::getLastSyncInterval()
+{
+ CTimeInterval nowTime = CTimeInterval::getCurrentTime();
+
+ DBResult( res, m_oSyncEngine.getDB().executeSQL("SELECT last_updated from sources") );
+ uint64 latestTimeUpdated = 0;
+ for ( ; !res.isEnd(); res.next() )
+ {
+ uint64 timeUpdated = res.getUInt64ByIdx(0);
+ if ( latestTimeUpdated < timeUpdated )
+ latestTimeUpdated = timeUpdated;
+ }
+
+ return latestTimeUpdated > 0 ? (int)(nowTime.toULong()-latestTimeUpdated) : 0;
+}
+
void CSyncThread::run()
{
LOG(INFO) + "Starting sync engine main routine...";
+ int nLastSyncInterval = getLastSyncInterval();
while( m_oSyncEngine.getState() != CSyncEngine::esExit )
{
- int nWait = m_nPollInterval ? m_nPollInterval : SYNC_POLL_INTERVAL_INFINITE;
- LOG(INFO) + "Sync engine blocked for " + nWait + " seconds...";
- wait(nWait);
+ int nWait = m_nPollInterval > 0 ? m_nPollInterval : SYNC_POLL_INTERVAL_INFINITE;
+
+ if ( m_nPollInterval > 0 && nLastSyncInterval > 0 )
+ nWait = (m_nPollInterval*1000 - nLastSyncInterval)/1000;
+ if ( nWait <= 0 )
+ nWait = SYNC_STARTUP_INTERVAL_SECONDS;
+
+ if ( nWait >= 0 )
+ {
+ LOG(INFO) + "Sync engine blocked for " + nWait + " seconds...";
+ wait(nWait);
+ }
+ nLastSyncInterval = 0;
if ( m_oSyncEngine.getState() != CSyncEngine::esExit )
processCommand();
View
2  platform/shared/sync/syncthread.h
@@ -13,6 +13,7 @@ namespace sync {
#define SYNC_POLL_INTERVAL_SECONDS 300
#define SYNC_POLL_INTERVAL_INFINITE (unsigned int)(-1)
#define SYNC_WAIT_BEFOREKILL_SECONDS 3
+#define SYNC_STARTUP_INTERVAL_SECONDS 10
class CSyncThread : public common::CRhoThread
{
@@ -48,6 +49,7 @@ class CSyncThread : public common::CRhoThread
void setPollInterval(int nInterval);
private:
CSyncThread(common::IRhoClassFactory* factory);
+ int getLastSyncInterval();
void processCommand();
};
Please sign in to comment.
Something went wrong with that request. Please try again.