예제 #1
0
  void clearNotification(SyncSource src) {
    LOG.INFO("Clear notification. Source : " + (src != null ? src.getName() : ""));

    synchronized (m_mxSyncNotifications) {
      if (getSync().isSearch()) m_pSearchNotification = null;
      else m_mapSyncNotifications.remove(src.getID());
    }
  }
예제 #2
0
  void processSingleObject() {
    if (m_strSingleObjectSrcName.length() == 0) return;

    SyncSource Src = getSync().findSourceByName(m_strSingleObjectSrcName);
    if (Src != null) {
      Integer nSrcID = Src.getID();
      addObjectNotify(nSrcID, m_strSingleObjectID);
    }

    m_strSingleObjectSrcName = "";
    m_strSingleObjectID = "";
  }
예제 #3
0
  SyncNotification getSyncNotifyBySrc(SyncSource src) {
    SyncNotification pSN = null;
    if (getSync().isSearch()) pSN = m_pSearchNotification;
    else {
      if (src != null) pSN = (SyncNotification) m_mapSyncNotifications.get(src.getID());

      if (pSN == null) pSN = m_pAllNotification;
    }

    if (pSN == null && !getSync().isNoThreadedMode()) return null;

    return pSN != null ? pSN : m_emptyNotify;
  }
예제 #4
0
  void fireSyncNotification(SyncSource src, boolean bFinish, int nErrCode, String strMessage) {
    if (getSync().getState() == SyncEngine.esExit) return;

    if (strMessage.length() > 0 || nErrCode != RhoAppAdapter.ERR_NONE) {
      if (!getSync().isSearch()) {
        if (src != null && (strMessage == null || strMessage.length() == 0))
          strMessage = RhoAppAdapter.getMessageText("sync_failed_for") + src.getName() + ".";

        reportSyncStatus(strMessage, nErrCode, src != null ? src.m_strError : "");
      }
    }

    doFireSyncNotification(src, bFinish, nErrCode, "", "", "");
  }
예제 #5
0
  void doFireSyncNotification(
      SyncSource src,
      boolean bFinish,
      int nErrCode,
      String strError,
      String strParams,
      String strServerError) {
    if (getSync().isStoppedByUser()) return;

    try {
      SyncNotification pSN = null;

      String strBody = "";
      boolean bRemoveAfterFire = bFinish;
      {
        synchronized (m_mxSyncNotifications) {
          pSN = getSyncNotifyBySrc(src);
          if (pSN == null) return;

          strBody = "";

          if (src != null) {
            strBody += "total_count=" + src.getTotalCount();
            strBody += "&processed_count=" + src.getCurPageCount();
            strBody += "&processed_objects_count=" + getLastSyncObjectCount(src.getID());
            strBody += "&cumulative_count=" + src.getServerObjectsCount();
            strBody += "&source_id=" + src.getID();
            strBody += "&source_name=" + src.getName();
          }

          if (strParams.length() > 0) strBody += (strBody.length() > 0 ? "&" : "") + strParams;
          else strBody += (strBody.length() > 0 ? "&" : "") + "sync_type=incremental";

          strBody += "&status=";
          if (bFinish) {
            if (nErrCode == RhoAppAdapter.ERR_NONE) {
              if (getSync().isSchemaChanged()) strBody += "schema_changed";
              else strBody += (src == null && strParams.length() == 0) ? "complete" : "ok";
            } else {
              if (getSync().isStoppedByUser()) nErrCode = RhoAppAdapter.ERR_CANCELBYUSER;

              strBody += "error";
              strBody += "&error_code=" + nErrCode;

              if (strError != null && strError.length() > 0)
                strBody += "&error_message=" + URI.urlEncode(strError);
              else if (src != null) strBody += "&error_message=" + URI.urlEncode(src.m_strError);

              if (strServerError != null && strServerError.length() > 0)
                strBody += "&" + strServerError;
              else if (src != null
                  && src.m_strServerError != null
                  && src.m_strServerError.length() > 0) strBody += "&" + src.m_strServerError;
            }

            if (src != null) strBody += makeCreateObjectErrorBody(src.getID());
          } else strBody += "in_progress";

          strBody += "&rho_callback=1";
          if (pSN.m_strParams != null && pSN.m_strParams.length() > 0) {
            if (!pSN.m_strParams.startsWith("&")) strBody += "&";

            strBody += pSN.m_strParams;
          }

          bRemoveAfterFire = bRemoveAfterFire && pSN.m_bRemoveAfterFire;
        }
      }
      if (bRemoveAfterFire) clearNotification(src);

      LOG.INFO(
          "Fire notification. Source : "
              + (src != null ? (src).getName() : "")
              + "; "
              + pSN.toString());

      if (callNotify(pSN, strBody)) clearNotification(src);
    } catch (Exception exc) {
      LOG.ERROR("Fire notification failed.", exc);
    }
  }