Skip to content

Commit

Permalink
Do not use a job in the FileInfoReader
Browse files Browse the repository at this point in the history
The FileInfoReader currently creates a job just to join its execution,
as the job is also marked as a system job to hide it from the users this
does not seem very useful and only complicates the flow and increased
the workload.

This now removes the job extension and also making the monitor field
obsolete now.
  • Loading branch information
laeubi committed Jan 7, 2025
1 parent 1d1d416 commit acf77b6
Showing 1 changed file with 19 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,61 +33,41 @@
* from ECF (there is currently no way to wait on a BrowseRequest job, as this is internal to
* ECF). If such support is added, this class is easily modified.
*/
public class FileInfoReader extends Job implements IRemoteFileSystemListener {
class FileInfoReader {
private Exception exception;
private IProgressMonitor theMonitor;
private final int connectionRetryCount;
private final long connectionRetryDelay;
private final IConnectContext connectContext;
private final Boolean[] barrier = new Boolean[1];
private IRemoteFile[] remoteFiles;
private IRemoteFileSystemRequest browseRequest;

@Override
protected IStatus run(IProgressMonitor monitor) {
/**
* Waits until request is processed (barrier[0] is non null).
*/
private void waitOnSelf(IProgressMonitor monitor) {
synchronized (barrier) {
while (barrier[0] == null) {
try {
barrier.wait(1000);
if (theMonitor.isCanceled() && browseRequest != null)
if (monitor.isCanceled() && browseRequest != null) {
browseRequest.cancel();
}
} catch (InterruptedException e) {
//ignore
Thread.currentThread().interrupt();
LogHelper.log(new Status(IStatus.WARNING, Activator.ID,
"Unexpected interrupt while waiting on ECF browse request", e)); //$NON-NLS-1$
return;
}
}
}
return Status.OK_STATUS;
}

/**
* Waits until request is processed (barrier[0] is non null).
* This is a bit of a hack, as it would be better if the ECFBrowser worked in similar fashion to
* file transfer were a custom job can be supplied.
* TODO: log an issue for ECF.
*/
private void waitOnSelf() {
schedule();
while (barrier[0] == null) {
boolean logged = false;
try {
join();
} catch (InterruptedException e) {
if (!logged)
LogHelper.log(new Status(IStatus.WARNING, Activator.ID, "Unexpected interrupt while waiting on ECF browse request", e)); //$NON-NLS-1$
}
}
}

/**
* Create a new FileInfoReader that will retry failed connection attempts and sleep some amount of time between each
* attempt.
*/
FileInfoReader(IConnectContext aConnectContext) {
super(Messages.repo_loading); // job label - TODO: this is a bad label
barrier[0] = null;
// Hide this job.
setSystem(true);
setUser(false);
connectionRetryCount = RepositoryPreferences.getConnectionRetryCount();
connectionRetryDelay = RepositoryPreferences.getConnectionMsRetryDelay();
connectContext = aConnectContext;
Expand All @@ -107,7 +87,7 @@ private IRemoteFile[] getRemoteFiles(URI location, IProgressMonitor monitor)
monitor.beginTask(location.toString(), 1);
try {
sendBrowseRequest(location, monitor);
waitOnSelf();
waitOnSelf(monitor);
// throw any exception received in a callback
checkException(location, connectionRetryCount);

Expand All @@ -134,27 +114,26 @@ long getLastModified(URI location, IProgressMonitor monitor) throws Authenticati
return file.getInfo().getLastModified();
}

@Override
public void handleRemoteFileEvent(IRemoteFileSystemEvent event) {
private void handleRemoteFileEvent(IRemoteFileSystemEvent event, IProgressMonitor monitor) {
exception = event.getException();
if (exception != null) {
synchronized (barrier) {
barrier[0] = Boolean.TRUE;
barrier.notify();
barrier.notifyAll();
}
} else if (event instanceof IRemoteFileSystemBrowseEvent) {
IRemoteFileSystemBrowseEvent fsbe = (IRemoteFileSystemBrowseEvent) event;
remoteFiles = fsbe.getRemoteFiles();
if (theMonitor != null)
theMonitor.worked(1);
if (monitor != null)
monitor.worked(1);
synchronized (barrier) {
barrier[0] = Boolean.TRUE;
barrier.notify();
barrier.notifyAll();
}
} else {
synchronized (barrier) {
barrier[0] = Boolean.FALSE; // ended by unknown reason
barrier.notify();
barrier.notifyAll();
}
}
}
Expand All @@ -176,14 +155,13 @@ private void sendBrowseRequest(URI uri, IProgressMonitor monitor)
adapter.setConnectContextForAuthentication(connectContext);

this.exception = null;
this.theMonitor = monitor;
for (int retryCount = 0;; retryCount++) {
if (monitor != null && monitor.isCanceled())
throw new OperationCanceledException();

try {
IFileID fileID = FileIDFactory.getDefault().createFileID(adapter.getBrowseNamespace(), uri.toString());
browseRequest = adapter.sendBrowseRequest(fileID, this);
browseRequest = adapter.sendBrowseRequest(fileID, e -> handleRemoteFileEvent(e, monitor));
} catch (RemoteFileSystemException e) {
exception = e;
} catch (FileCreateException e) {
Expand Down

0 comments on commit acf77b6

Please sign in to comment.