Loading app/src/main/java/io/eelo/drive/operations/UploadFileOperation.java +9 −6 Original line number Diff line number Diff line Loading @@ -27,8 +27,6 @@ import io.eelo.drive.database.DbHelper; import io.eelo.drive.models.SyncedFileState; import io.eelo.drive.utils.CommonUtils; /** * @author Vincent Bourgmayer * High level Operation which upload a local file to a remote cloud storage Loading @@ -51,7 +49,6 @@ public class UploadFileOperation extends RemoteOperation { * @param targetPath target path to upload filte. must not be null. * @param syncedFolderId needed for new file to upload * @param context executing context */ public UploadFileOperation(File file, String targetPath, Long syncedFolderId, Context context){ this.mFile = file; Loading Loading @@ -133,6 +130,7 @@ public class UploadFileOperation extends RemoteOperation { RemoteOperationResult uploadResult = uploadRemoteFileOperation.execute( client ); RemoteOperationResult.ResultCode mResultCode; boolean mustRestart = true; //if upload is a success if( uploadResult.isSuccess() ){ // get new Etag of the file on the server Loading Loading @@ -176,8 +174,14 @@ public class UploadFileOperation extends RemoteOperation { String remoteFoldersPath = mTargetPath.substring( 0, mTargetPath.lastIndexOf(FileUtils.PATH_SEPARATOR)+1 ); mResultCode = RemoteOperationResult.ResultCode.FILE_NOT_FOUND; CreateRemoteFolderOperation createFolderOperation = new CreateRemoteFolderOperation( remoteFoldersPath, true ); try{ createFolderOperation.execute( client ); }catch(Exception e){ return new RemoteOperationResult(e); } }else if(uploadResult.getCode() == RemoteOperationResult.ResultCode.QUOTA_EXCEEDED){ return new RemoteOperationResult( uploadResult.getCode() ); }else{ //Upload failed Log.e(TAG, "UploadRemoteFileOperation for : " + mFile.getName() + " failed => code: " + uploadResult.getCode()); Loading Loading @@ -210,5 +214,4 @@ public class UploadFileOperation extends RemoteOperation { public File getFile() { return mFile; } } app/src/main/java/io/eelo/drive/services/OperationManagerService.java +16 −14 Original line number Diff line number Diff line Loading @@ -111,18 +111,18 @@ public class OperationManagerService extends Service implements OnRemoteOperatio Log.e(TAG, "my OwnCloudClient is null: stop here."); return; } for(int i =0; i < workerAmount; ++i){ for(int i =-1; ++i < workerAmount;){ this.startWork(i); } } /** * retrieve an operation from queue and execute it. * @param index index of thread which execute job. * @param threadIndex index of thread which execute job. */ private void startWork( int index ){ Log.i(TAG, "startWork("+index+")" ); if( !mThreadWorkingState[index] ) { private void startWork( int threadIndex ){ Log.i(TAG, "startWork("+threadIndex+")" ); if( !mThreadWorkingState[threadIndex] ) { RemoteOperation operation = this.mOperationsQueue.poll(); if (operation != null) { Log.v(TAG, " an operation has been poll from queue"); Loading @@ -138,9 +138,9 @@ public class OperationManagerService extends Service implements OnRemoteOperatio //Try to add a "lock" on file localPath. it will fail if there is already a "lock" on this file. if ( lockedfilePath.add( localPath) ) { mStartedOperations.put(operation, index); this.mThreadPool[index] = operation.execute( mClient, this, this.mHandler ); this.mThreadWorkingState[index] = true; mStartedOperations.put(operation, threadIndex); this.mThreadPool[threadIndex] = operation.execute( mClient, this, this.mHandler ); this.mThreadWorkingState[threadIndex] = true; }else{ Log.d(TAG, " File local path is already locked for synchronisation. current operation go back to queue."); mOperationsQueue.add(operation); Loading @@ -152,7 +152,7 @@ public class OperationManagerService extends Service implements OnRemoteOperatio } /** * Tell if there is at least on thread that can be start * Tell if there is at least one thread that can get new job * @return boolean true is is there is a free thread place else return false */ private boolean isThereAFreeThreadPlace(){ Loading Loading @@ -204,6 +204,10 @@ public class OperationManagerService extends Service implements OnRemoteOperatio case FORBIDDEN: Log.e(TAG, " Upload: Forbidden : Can't get syncedFileState, no remote path defined"); break; case QUOTA_EXCEEDED: CommonUtils.sendNotification(this, notificationID, "Remote storage is nearly full",android.R.drawable.stat_sys_warning ); break; } //free place for starting a new operation on this file Loading Loading @@ -242,7 +246,7 @@ public class OperationManagerService extends Service implements OnRemoteOperatio if( result.isSuccess() ) { DbHelper.manageSyncedFileStateDB(sf, "DELETE", this); CommonUtils.sendNotification(this,notificationID, sf.getName()+" has been remotly removed", android.R.drawable.ic_delete ); }//don't care if failed, it will be retry on next sync } this.lockedfilePath.remove( removeOperation.getSyncedFileState().getLocalPath() ); } } Loading @@ -259,7 +263,6 @@ public class OperationManagerService extends Service implements OnRemoteOperatio */ class OperationManagerBinder extends Binder { private final String TAG = OperationManagerBinder.class.getSimpleName(); OperationManagerService getService(){ Log.i(TAG, "getService()"); return OperationManagerService.this; Loading @@ -280,12 +283,11 @@ public class OperationManagerService extends Service implements OnRemoteOperatio @Override public void handleMessage(Message msg) { Log.i(TAG, "handler.handleMessage()"); boolean tWorking = msg.getData().getBoolean("mThreadWorkingState"); int tIndex = msg.getData().getInt("thread index"); mOperationServiceWeakRef.get().mThreadWorkingState[tIndex] = tWorking; mOperationServiceWeakRef.get() .mThreadWorkingState[tIndex] = tWorking; } } Loading Loading
app/src/main/java/io/eelo/drive/operations/UploadFileOperation.java +9 −6 Original line number Diff line number Diff line Loading @@ -27,8 +27,6 @@ import io.eelo.drive.database.DbHelper; import io.eelo.drive.models.SyncedFileState; import io.eelo.drive.utils.CommonUtils; /** * @author Vincent Bourgmayer * High level Operation which upload a local file to a remote cloud storage Loading @@ -51,7 +49,6 @@ public class UploadFileOperation extends RemoteOperation { * @param targetPath target path to upload filte. must not be null. * @param syncedFolderId needed for new file to upload * @param context executing context */ public UploadFileOperation(File file, String targetPath, Long syncedFolderId, Context context){ this.mFile = file; Loading Loading @@ -133,6 +130,7 @@ public class UploadFileOperation extends RemoteOperation { RemoteOperationResult uploadResult = uploadRemoteFileOperation.execute( client ); RemoteOperationResult.ResultCode mResultCode; boolean mustRestart = true; //if upload is a success if( uploadResult.isSuccess() ){ // get new Etag of the file on the server Loading Loading @@ -176,8 +174,14 @@ public class UploadFileOperation extends RemoteOperation { String remoteFoldersPath = mTargetPath.substring( 0, mTargetPath.lastIndexOf(FileUtils.PATH_SEPARATOR)+1 ); mResultCode = RemoteOperationResult.ResultCode.FILE_NOT_FOUND; CreateRemoteFolderOperation createFolderOperation = new CreateRemoteFolderOperation( remoteFoldersPath, true ); try{ createFolderOperation.execute( client ); }catch(Exception e){ return new RemoteOperationResult(e); } }else if(uploadResult.getCode() == RemoteOperationResult.ResultCode.QUOTA_EXCEEDED){ return new RemoteOperationResult( uploadResult.getCode() ); }else{ //Upload failed Log.e(TAG, "UploadRemoteFileOperation for : " + mFile.getName() + " failed => code: " + uploadResult.getCode()); Loading Loading @@ -210,5 +214,4 @@ public class UploadFileOperation extends RemoteOperation { public File getFile() { return mFile; } }
app/src/main/java/io/eelo/drive/services/OperationManagerService.java +16 −14 Original line number Diff line number Diff line Loading @@ -111,18 +111,18 @@ public class OperationManagerService extends Service implements OnRemoteOperatio Log.e(TAG, "my OwnCloudClient is null: stop here."); return; } for(int i =0; i < workerAmount; ++i){ for(int i =-1; ++i < workerAmount;){ this.startWork(i); } } /** * retrieve an operation from queue and execute it. * @param index index of thread which execute job. * @param threadIndex index of thread which execute job. */ private void startWork( int index ){ Log.i(TAG, "startWork("+index+")" ); if( !mThreadWorkingState[index] ) { private void startWork( int threadIndex ){ Log.i(TAG, "startWork("+threadIndex+")" ); if( !mThreadWorkingState[threadIndex] ) { RemoteOperation operation = this.mOperationsQueue.poll(); if (operation != null) { Log.v(TAG, " an operation has been poll from queue"); Loading @@ -138,9 +138,9 @@ public class OperationManagerService extends Service implements OnRemoteOperatio //Try to add a "lock" on file localPath. it will fail if there is already a "lock" on this file. if ( lockedfilePath.add( localPath) ) { mStartedOperations.put(operation, index); this.mThreadPool[index] = operation.execute( mClient, this, this.mHandler ); this.mThreadWorkingState[index] = true; mStartedOperations.put(operation, threadIndex); this.mThreadPool[threadIndex] = operation.execute( mClient, this, this.mHandler ); this.mThreadWorkingState[threadIndex] = true; }else{ Log.d(TAG, " File local path is already locked for synchronisation. current operation go back to queue."); mOperationsQueue.add(operation); Loading @@ -152,7 +152,7 @@ public class OperationManagerService extends Service implements OnRemoteOperatio } /** * Tell if there is at least on thread that can be start * Tell if there is at least one thread that can get new job * @return boolean true is is there is a free thread place else return false */ private boolean isThereAFreeThreadPlace(){ Loading Loading @@ -204,6 +204,10 @@ public class OperationManagerService extends Service implements OnRemoteOperatio case FORBIDDEN: Log.e(TAG, " Upload: Forbidden : Can't get syncedFileState, no remote path defined"); break; case QUOTA_EXCEEDED: CommonUtils.sendNotification(this, notificationID, "Remote storage is nearly full",android.R.drawable.stat_sys_warning ); break; } //free place for starting a new operation on this file Loading Loading @@ -242,7 +246,7 @@ public class OperationManagerService extends Service implements OnRemoteOperatio if( result.isSuccess() ) { DbHelper.manageSyncedFileStateDB(sf, "DELETE", this); CommonUtils.sendNotification(this,notificationID, sf.getName()+" has been remotly removed", android.R.drawable.ic_delete ); }//don't care if failed, it will be retry on next sync } this.lockedfilePath.remove( removeOperation.getSyncedFileState().getLocalPath() ); } } Loading @@ -259,7 +263,6 @@ public class OperationManagerService extends Service implements OnRemoteOperatio */ class OperationManagerBinder extends Binder { private final String TAG = OperationManagerBinder.class.getSimpleName(); OperationManagerService getService(){ Log.i(TAG, "getService()"); return OperationManagerService.this; Loading @@ -280,12 +283,11 @@ public class OperationManagerService extends Service implements OnRemoteOperatio @Override public void handleMessage(Message msg) { Log.i(TAG, "handler.handleMessage()"); boolean tWorking = msg.getData().getBoolean("mThreadWorkingState"); int tIndex = msg.getData().getInt("thread index"); mOperationServiceWeakRef.get().mThreadWorkingState[tIndex] = tWorking; mOperationServiceWeakRef.get() .mThreadWorkingState[tIndex] = tWorking; } } Loading