Bug 501970 - Do not log/throw FileNotOnServerException but treat as
cancelled
Change-Id: I7d2b5057d3dae43aa8b540f5e3cdcecb06894f06
Signed-off-by: Johannes Faltermeier <jfaltermeier@eclipsesource.com>
diff --git a/bundles/org.eclipse.emf.emfstore.client/src/org/eclipse/emf/emfstore/internal/client/model/filetransfer/FileDownloadJob.java b/bundles/org.eclipse.emf.emfstore.client/src/org/eclipse/emf/emfstore/internal/client/model/filetransfer/FileDownloadJob.java
index 5d43da6..0968247 100644
--- a/bundles/org.eclipse.emf.emfstore.client/src/org/eclipse/emf/emfstore/internal/client/model/filetransfer/FileDownloadJob.java
+++ b/bundles/org.eclipse.emf.emfstore.client/src/org/eclipse/emf/emfstore/internal/client/model/filetransfer/FileDownloadJob.java
@@ -94,6 +94,10 @@
// download file chunk to retrieve filesize (file chunk is discarded)
FileChunk fileChunk = null;
fileChunk = getConnectionManager().downloadFileChunk(getSessionId(), getProjectId(), getFileInformation());
+ if (fileChunk == null) {
+ status.transferCancelled();
+ return false;
+ }
getFileInformation().setFileSize(fileChunk.getFileSize());
initializeMonitor(monitor);
diff --git a/bundles/org.eclipse.emf.emfstore.client/src/org/eclipse/emf/emfstore/internal/client/model/filetransfer/FileDownloadStatus.java b/bundles/org.eclipse.emf.emfstore.client/src/org/eclipse/emf/emfstore/internal/client/model/filetransfer/FileDownloadStatus.java
index 9494948..5b8a660 100644
--- a/bundles/org.eclipse.emf.emfstore.client/src/org/eclipse/emf/emfstore/internal/client/model/filetransfer/FileDownloadStatus.java
+++ b/bundles/org.eclipse.emf.emfstore.client/src/org/eclipse/emf/emfstore/internal/client/model/filetransfer/FileDownloadStatus.java
@@ -35,6 +35,7 @@
private final ProjectSpace transferringProjectSpace;
private final Observable finishedObservable = new Obs();
private final Observable failedObservable = new Obs();
+ private final Observable cancelledObservable = new Obs();
private final FileTransferStatistics statistics = new FileTransferStatistics(this);
private Status status;
@@ -55,7 +56,7 @@
*
* @author jfinis
*/
- public static enum Status {
+ public enum Status {
/**
* The file transfer was not yet started.
*/
@@ -127,6 +128,16 @@
}
}
+ private void addTransferCancelledObserver(Observer o) {
+ // Add
+ cancelledObservable.addObserver(o);
+
+ // Instantly notify if the transfer is already finished
+ if (status == Status.CANCELLED) {
+ o.update(cancelledObservable, this);
+ }
+ }
+
/**
* Adds an observer which is notified if the transfer fails due to an
* exception. The getException method can then be used to retrieve the
@@ -225,7 +236,6 @@
* in case of an error during transfer
*/
public File getTransferredFile(boolean block) throws FileTransferException {
-
if (!isTransferFinished() && block) {
/**
* TODO: Double-check this code
@@ -240,6 +250,7 @@
};
addTransferFailedObserver(observer);
addTransferFinishedObserver(observer);
+ addTransferCancelledObserver(observer);
try {
synchronized (observer) {
observer.wait();
@@ -279,6 +290,7 @@
}
statistics.registerStop();
status = Status.CANCELLED;
+ cancelledObservable.notifyObservers(this);
}
/**
diff --git a/bundles/org.eclipse.emf.emfstore.server/src/org/eclipse/emf/emfstore/internal/server/connection/xmlrpc/XmlRpcEmfStoreImpl.java b/bundles/org.eclipse.emf.emfstore.server/src/org/eclipse/emf/emfstore/internal/server/connection/xmlrpc/XmlRpcEmfStoreImpl.java
index aafa8b4..9292013 100644
--- a/bundles/org.eclipse.emf.emfstore.server/src/org/eclipse/emf/emfstore/internal/server/connection/xmlrpc/XmlRpcEmfStoreImpl.java
+++ b/bundles/org.eclipse.emf.emfstore.server/src/org/eclipse/emf/emfstore/internal/server/connection/xmlrpc/XmlRpcEmfStoreImpl.java
@@ -22,6 +22,7 @@
import org.eclipse.emf.emfstore.internal.server.accesscontrol.AccessControl;
import org.eclipse.emf.emfstore.internal.server.connection.xmlrpc.util.ShareProjectAdapter;
import org.eclipse.emf.emfstore.internal.server.exceptions.AccessControlException;
+import org.eclipse.emf.emfstore.internal.server.exceptions.FileNotOnServerException;
import org.eclipse.emf.emfstore.internal.server.exceptions.InvalidVersionSpecException;
import org.eclipse.emf.emfstore.internal.server.filetransfer.FileChunk;
import org.eclipse.emf.emfstore.internal.server.filetransfer.FileTransferInformation;
@@ -153,7 +154,11 @@
public FileChunk downloadFileChunk(SessionId sessionId, ProjectId projectId,
FileTransferInformation fileInformation)
throws ESException {
- return getEmfStore().downloadFileChunk(sessionId, projectId, fileInformation);
+ try {
+ return getEmfStore().downloadFileChunk(sessionId, projectId, fileInformation);
+ } catch (final FileNotOnServerException ex) {
+ return null;
+ }
}
/**
diff --git a/bundles/org.eclipse.emf.emfstore.server/src/org/eclipse/emf/emfstore/internal/server/core/subinterfaces/FileTransferSubInterfaceImpl.java b/bundles/org.eclipse.emf.emfstore.server/src/org/eclipse/emf/emfstore/internal/server/core/subinterfaces/FileTransferSubInterfaceImpl.java
index 9f607d5..da3040d 100644
--- a/bundles/org.eclipse.emf.emfstore.server/src/org/eclipse/emf/emfstore/internal/server/core/subinterfaces/FileTransferSubInterfaceImpl.java
+++ b/bundles/org.eclipse.emf.emfstore.server/src/org/eclipse/emf/emfstore/internal/server/core/subinterfaces/FileTransferSubInterfaceImpl.java
@@ -22,7 +22,6 @@
import org.eclipse.emf.emfstore.internal.server.core.AbstractSubEmfstoreInterface;
import org.eclipse.emf.emfstore.internal.server.core.MonitorProvider;
import org.eclipse.emf.emfstore.internal.server.exceptions.FatalESException;
-import org.eclipse.emf.emfstore.internal.server.exceptions.FileNotOnServerException;
import org.eclipse.emf.emfstore.internal.server.exceptions.FileTransferException;
import org.eclipse.emf.emfstore.internal.server.exceptions.InvalidInputException;
import org.eclipse.emf.emfstore.internal.server.filetransfer.FileChunk;
@@ -86,7 +85,8 @@
try {
file = findFile(fileInformation, projectId);
} catch (final FileNotFoundException e) {
- throw new FileNotOnServerException(projectId, fileInformation.getFileIdentifier());
+ // throw new FileNotOnServerException(projectId, fileInformation.getFileIdentifier());
+ return null;
}
return FilePartitionerUtil.readChunk(file, fileInformation);