platform/shared/rubyJVM/src/com/rho/sync/SyncNotify.java in rhodes-2.0.2 vs platform/shared/rubyJVM/src/com/rho/sync/SyncNotify.java in rhodes-2.0.3
- old
+ new
@@ -19,10 +19,12 @@
static class SyncNotification
{
String m_strUrl, m_strParams;
boolean m_bRemoveAfterFire;
+ SyncNotification(){m_bRemoveAfterFire = false;}
+
SyncNotification(String strUrl, String strParams, boolean bRemoveAfterFire)
{ m_strUrl = strUrl; m_strParams = strParams; m_bRemoveAfterFire = bRemoveAfterFire; }
};
public static final Integer enNone = new Integer(0), enDelete=new Integer(1), enUpdate=new Integer(2), enCreate=new Integer(3);
@@ -38,10 +40,11 @@
static Mutex m_mxObjectNotify = new Mutex();
Hashtable/*<int,SyncNotification>*/ m_mapSyncNotifications = new Hashtable();
SyncNotification m_pSearchNotification;
SyncNotification m_bulkSyncNotify;
+ SyncNotification m_emptyNotify = new SyncNotification();
Mutex m_mxSyncNotifications = new Mutex();
ISyncStatusListener m_syncStatusListener = null;
boolean m_bEnableReporting = false;
@@ -251,13 +254,14 @@
void onSyncSourceEnd( int nSrc, Vector/*Ptr<CSyncSource*>&*/ sources )
{
SyncSource src = (SyncSource)sources.elementAt(nSrc);
- fireSyncNotification( src, true, src.m_nErrCode, "");
if ( getSync().getState() == SyncEngine.esStop )
- fireAllSyncNotifications(true, src.m_nErrCode, "", sources );
+ fireAllSyncNotifications(true, src.m_nErrCode, src.m_strError, sources, nSrc );
+ else
+ fireSyncNotification( src, true, src.m_nErrCode, "");
cleanCreateObjectErrors();
}
void setSyncNotification(int source_id, String strUrl, String strParams )throws Exception
@@ -344,18 +348,10 @@
m_syncStatusListener.reportStatus( status, error);
}
}
}
- void fireAllSyncNotifications( boolean bFinish, int nErrCode, String strMessage, Vector/*Ptr<CSyncSource*>&*/ sources )
- {
- for( int i = 0; i < sources.size(); i++ )
- {
- doFireSyncNotification( (SyncSource)sources.elementAt(i), bFinish, nErrCode, strMessage );
- }
- }
-
void fireBulkSyncNotification( boolean bFinish, String status, String partition, int nErrCode )
{
if ( getSync().getState() == SyncEngine.esExit )
return;
@@ -412,11 +408,45 @@
{
LOG.ERROR("Fire bulk notification failed.", exc);
}
}
-
+
+ void fireAllSyncNotifications( boolean bFinish, int nErrCode, String strError, Vector/*Ptr<CSyncSource*>&*/ sources, int nCurSrc )
+ {
+ synchronized(m_mxSyncNotifications)
+ {
+ if ( nCurSrc >= 0 )
+ {
+ SyncSource src = (SyncSource)sources.elementAt(nCurSrc);
+ SyncNotification pSN = getSyncNotifyBySrc(src);
+ if ( pSN != null )
+ {
+ src.m_strError = strError;
+ src.m_nErrCode = nErrCode;
+
+ fireSyncNotification( src, bFinish, nErrCode, "" );
+ return;
+ }
+ }
+
+ //find any source with notify
+ for( int i = 0; i < (int)sources.size(); i++ )
+ {
+ SyncSource src = (SyncSource)sources.elementAt(i);
+ SyncNotification pSN = getSyncNotifyBySrc(src);
+ if ( pSN != null )
+ {
+ src.m_strError = strError;
+ src.m_nErrCode = nErrCode;
+ fireSyncNotification( src, bFinish, nErrCode, "" );
+ break;
+ }
+ }
+ }
+ }
+
void fireSyncNotification( SyncSource src, boolean bFinish, int nErrCode, String strMessage )
{
if ( getSync().getState() == SyncEngine.esExit )
return;
@@ -429,29 +459,38 @@
reportSyncStatus(strMessage,nErrCode,src!= null?src.m_strError:"");
}
}
- doFireSyncNotification(src, bFinish, nErrCode, strMessage );
+ doFireSyncNotification(src, bFinish, nErrCode, "" );
}
- void doFireSyncNotification( SyncSource src, boolean bFinish, int nErrCode, String strMessage )
+ SyncNotification getSyncNotifyBySrc(SyncSource src)
{
+ SyncNotification pSN = null;
+ if ( src.isSearch() )
+ pSN = m_pSearchNotification;
+ else
+ pSN = (SyncNotification)m_mapSyncNotifications.get(src.getID());
+
+ if ( pSN == null )//&& !getSync().isNoThreadedMode() )
+ return null;
+
+ return pSN != null ? pSN : m_emptyNotify;
+ }
+
+ void doFireSyncNotification( SyncSource src, boolean bFinish, int nErrCode, String strError )
+ {
if ( src == null || getSync().isStoppedByUser() )
return; //TODO: implement all sources callback
try{
String strBody = "", strUrl;
boolean bRemoveAfterFire = bFinish;
{
synchronized(m_mxSyncNotifications){
- SyncNotification sn = null;
- if ( src.isSearch() )
- sn = m_pSearchNotification;
- else
- sn = (SyncNotification)m_mapSyncNotifications.get(src.getID());
-
+ SyncNotification sn = getSyncNotifyBySrc(src);
if ( sn == null )
return;
strUrl = sn.m_strUrl;
strBody += "total_count=" + src.getTotalCount();
@@ -472,10 +511,14 @@
if ( getSync().isStoppedByUser() )
nErrCode = RhoRuby.ERR_CANCELBYUSER;
strBody += "error";
strBody += "&error_code=" + nErrCode;
- strBody += "&error_message=" + URI.urlEncode(src.m_strError);
+
+ if ( strError != null && strError.length() > 0 )
+ strBody += "&error_message=" + URI.urlEncode(strError);
+ else
+ strBody += "&error_message=" + URI.urlEncode(src.m_strError);
}
}
else
strBody += "in_progress";