Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
Change async process key generating algorithm to not reuse keys.
Browse files Browse the repository at this point in the history
Other minor name and documentation changes.
  • Loading branch information
Carlos A. Munoz committed Aug 26, 2013
1 parent 235bba8 commit 0981b7d
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 25 deletions.
Expand Up @@ -407,7 +407,7 @@ public String getCopyTransStartTime()
public String getCopyTransEstimatedTimeLeft()
{
CopyTransTaskHandle handle = copyTransManager.getCopyTransProcessHandle(getProjectIteration());
return formatTimePeriod(handle.getEstimatedTimeInMillis());
return formatTimePeriod(handle.getEstimatedTimeRemaining());
}

// FIXME this is not localizable
Expand Down
Expand Up @@ -49,7 +49,7 @@ public void finishTiming()
* @return The estimated time (in milliseconds) remaining for completion of the process.
* If the system is not able to provide an estimate, this method returns -1.
*/
public long getEstimatedTimeInMillis()
public long getEstimatedTimeRemaining()
{
if( this.startTime > 0 && currentProgress > 0 )
{
Expand Down
Expand Up @@ -129,7 +129,6 @@ public String call() throws Exception
String downloadId = fileSystemService.createDownloadDescriptorFile(downloadFile,
projectSlug + "_" + iterationSlug + "_" + localeId + ".zip",
userName);
//zipHandle.setDownloadId(downloadId);

// Add the config file at the root of the project directory
String configFilename = projectDirectory + configurationService.getConfigurationFileName();
Expand Down
Expand Up @@ -172,7 +172,7 @@ public Void call() throws Exception
(DocumentService)Component.getInstance(DocumentServiceImpl.class);
documentServiceImpl.saveDocument(
projectSlug, iterationSlug, resource, extensions, copytrans, true);
getHandle().setCurrentProgress( getHandle().getMaxProgress() ); // TODO This should update with real progress
// TODO This should update with real progress
return null;
}
};
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright 2010, Red Hat, Inc. and individual contributors as indicated by the
* Copyright 2013, Red Hat, Inc. and individual contributors as indicated by the
* @author tags. See the copyright.txt file in the distribution for a full
* listing of individual contributors.
*
Expand Down Expand Up @@ -65,17 +65,16 @@ public class AsyncTaskManagerServiceImpl implements AsyncTaskManagerService
private ConcurrentMap<Serializable, AsyncTaskHandle> handlesByKey =
Maps.newConcurrentMap();

private long lastAssignedKey = 1;

@Override
public <V, H extends AsyncTaskHandle<V>> String startTask(AsyncTask<V, H> task)
{
TaskExecutor taskExecutor = (TaskExecutor) Component.getInstance(TaskExecutor.class);
AsyncTaskHandle<V> handle = taskExecutor.startTask(task);
Long taskKey;
synchronized (handlesById)
{
taskKey = generateNextAvailableKey();
handlesById.put(taskKey, handle);
}
taskKey = generateNextAvailableKey();
handlesById.put(taskKey, handle);
return taskKey.toString();
}

Expand Down Expand Up @@ -138,22 +137,9 @@ public Collection<AsyncTaskHandle> getAllHandles()
return handlesById.asMap().values();
}

private Long generateNextAvailableKey()
private synchronized long generateNextAvailableKey()
{
// Sorted set of keys (to find an available one)
Set<Long> keys = new TreeSet<Long>( handlesById.asMap().keySet() );

// Find the next available key
long keyCandidate = 1;
for( Long key : keys )
{
if( keyCandidate != key.longValue() )
{
return keyCandidate;
}
keyCandidate++;
}
return keyCandidate;
return lastAssignedKey++;
}

}

0 comments on commit 0981b7d

Please sign in to comment.