Ejemplo n.º 1
0
        public override void run()
        {
            LOG.INFO("ClientRegister start");
            while (!isStopping())
            {
                try
                {
                    if (SyncThread.getInstance() != null)
                    {
                        if (doRegister(SyncThread.getSyncEngine()))
                        {
                            m_nPollInterval = POLL_INTERVAL_INFINITE;
                            //break;
                        }
                    }
                }catch (Exception exc)
                {
                    LOG.ERROR("doRegister failed", exc);
                }

                LOG.INFO("Waiting for " + m_nPollInterval + " sec to try again to register client");
                wait(m_nPollInterval);
            }
            LOG.INFO("ClientRegister thread shutdown");
        }
Ejemplo n.º 2
0
        public String getRegisterBody(String strClientID)
        {
            int port = RhoConf.getInstance().getInt("push_port");

            return(SyncThread.getSyncEngine().getProtocol().getClientRegisterBody(strClientID, m_strDevicePin,
                                                                                  port > 0 ? port : DEFAULT_PUSH_PORT, RHODESAPP().getPlatform()));
        }
Ejemplo n.º 3
0
        public static SyncThread Create()
        {
            if (m_pInstance != null)
            {
                return(m_pInstance);
            }

            m_pInstance = new SyncThread();
            return(m_pInstance);
        }
Ejemplo n.º 4
0
        void processSyncCommand(String strCmd, JSONEntry oCmdEntry, boolean bCheckUIRequest)
        {
            JSONStructIterator objIter = new JSONStructIterator(oCmdEntry);

            for ( ; !objIter.isEnd() && getSync().isContinueSync(); objIter.next())
            {
                String             strObject = objIter.getCurKey();
                JSONStructIterator attrIter  = new JSONStructIterator(objIter.getCurValue());

                try
                {
                    if (m_bSchemaSource)
                    {
                        processServerCmd_Ver3_Schema(strCmd, strObject, attrIter);
                    }
                    else
                    {
                        for ( ; !attrIter.isEnd() && getSync().isContinueSync(); attrIter.next())
                        {
                            String strAttrib = attrIter.getCurKey();
                            String strValue  = attrIter.getCurString();

                            processServerCmd_Ver3(strCmd, strObject, strAttrib, strValue);
                        }
                    }
                }catch (DBException exc)
                {
                    LOG.ERROR("Sync of server changes failed for " + getName() + ";object: " + strObject, exc);
                }

                if (getSyncType().compareTo("none") == 0)
                {
                    continue;
                }

                if (bCheckUIRequest)
                {
                    int nSyncObjectCount = getNotify().incLastSyncObjectCount(getID());
                    if (getProgressStep() > 0 && (nSyncObjectCount % getProgressStep() == 0))
                    {
                        getNotify().fireSyncNotification(this, false, RhoAppAdapter.ERR_NONE, "");
                    }

                    if (getDB().isUIWaitDB())
                    {
                        LOG.INFO("Commit transaction because of UI request.");
                        getDB().endTransaction();
                        SyncThread.sleep(1000);
                        getDB().startTransaction();
                    }
                }
            }
        }
Ejemplo n.º 5
0
        public void Destroy()
        {
            m_oSyncEngine.exitSync();
            stop(SYNC_WAIT_BEFOREKILL_SECONDS);

            if (ClientRegister.getInstance() != null)
            {
                ClientRegister.getInstance().Destroy();
            }

            DBAdapter.closeAll();

            m_pInstance = null;
        }
Ejemplo n.º 6
0
        void loadBulkPartition(String strPartition)
        {
            DBAdapter dbPartition = getDB(strPartition);
            String    serverUrl = RhoConf.getInstance().getPath("syncserver");
            String    strUrl = serverUrl + "bulk_data";
            String    strQuery = "?client_id=" + m_clientID + "&partition=" + strPartition;
            String    strDataUrl = "", strCmd = "", strCryptKey = "";

            getNotify().fireBulkSyncNotification(false, "start", strPartition, RhoAppAdapter.ERR_NONE);

            while (strCmd.length() == 0 && isContinueSync())
            {
                NetResponse resp = getNet().pullData(strUrl + strQuery, this);
                if (!resp.isOK() || resp.getCharData() == null)
                {
                    LOG.ERROR("Bulk sync failed: server return an error.");
                    stopSync();
                    getNotify().fireBulkSyncNotification(true, "", strPartition, RhoAppAdapter.getErrorFromResponse(resp));
                    return;
                }

                LOG.INFO("Bulk sync: got response from server: " + resp.getCharData());

                String    szData     = resp.getCharData();
                JSONEntry oJsonEntry = new JSONEntry(szData);
                strCmd = oJsonEntry.getString("result");
                if (oJsonEntry.hasName("url"))
                {
                    strDataUrl = oJsonEntry.getString("url");
                }

                if (strCmd.compareTo("wait") == 0)
                {
                    int nTimeout = RhoConf.getInstance().getInt("bulksync_timeout_sec");
                    if (nTimeout == 0)
                    {
                        nTimeout = 5;
                    }

                    SyncThread.getInstance().wait(nTimeout);
                    strCmd = "";
                }
            }

            if (strCmd.compareTo("nop") == 0)
            {
                LOG.INFO("Bulk sync return no data.");
                getNotify().fireBulkSyncNotification(true, "", strPartition, RhoAppAdapter.ERR_NONE);
                return;
            }

            if (!isContinueSync())
            {
                return;
            }

            getNotify().fireBulkSyncNotification(false, "download", strPartition, RhoAppAdapter.ERR_NONE);

            String fDataName     = makeBulkDataFileName(strDataUrl, dbPartition.getDBPath(), "");
            String strZip        = ".rzip";
            String strSqlDataUrl = CFilePath.join(getHostFromUrl(serverUrl), strDataUrl) + strZip;

            LOG.INFO("Bulk sync: download data from server: " + strSqlDataUrl);
            {
                NetResponse resp1 = getNet().pullFile(strSqlDataUrl, fDataName + strZip, this, null);
                if (!resp1.isOK())
                {
                    LOG.ERROR("Bulk sync failed: cannot download database file.");
                    stopSync();
                    getNotify().fireBulkSyncNotification(true, "", strPartition, RhoAppAdapter.getErrorFromResponse(resp1));
                    return;
                }
            }

            if (!isContinueSync())
            {
                return;
            }

            LOG.INFO("Bulk sync: unzip db");

            if (!RHODESAPP().unzip_file(fDataName + strZip))
            {
                CRhoFile.deleteFile(fDataName + strZip);
                LOG.ERROR("Bulk sync failed: cannot unzip database file.");
                stopSync();
                getNotify().fireBulkSyncNotification(true, "", strPartition, RhoAppAdapter.ERR_UNEXPECTEDSERVERRESPONSE);
                return;
            }
            CRhoFile.deleteFile(fDataName + strZip);

            LOG.INFO("Bulk sync: start change db");
            getNotify().fireBulkSyncNotification(false, "change_db", strPartition, RhoAppAdapter.ERR_NONE);

            dbPartition.setBulkSyncDB(fDataName, strCryptKey);
            processServerSources("{\"partition\":\"" + strPartition + "\"}");

            LOG.INFO("Bulk sync: end change db");
            getNotify().fireBulkSyncNotification(false, "", strPartition, RhoAppAdapter.ERR_NONE);
        }
Ejemplo n.º 7
0
	    public void Destroy()
	    {
	        m_oSyncEngine.exitSync();
	        stop(SYNC_WAIT_BEFOREKILL_SECONDS);
		
	        if ( ClientRegister.getInstance() != null )
	    	    ClientRegister.getInstance().Destroy();
	    
	        DBAdapter.closeAll();
	    
	        m_pInstance = null;
	    }
Ejemplo n.º 8
0
	    public static SyncThread Create()
	    {
	        if ( m_pInstance != null) 
	            return m_pInstance;
	
	        m_pInstance = new SyncThread();
	        return m_pInstance;
	    }