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

Commit

Permalink
Rename AsyncHandle to AsyncTaskHandle.
Browse files Browse the repository at this point in the history
  • Loading branch information
Carlos A. Munoz committed Aug 21, 2013
1 parent e61464e commit 1a3e26d
Show file tree
Hide file tree
Showing 19 changed files with 63 additions and 88 deletions.
@@ -1,6 +1,5 @@
package org.zanata.action;

import java.io.InputStream;
import java.io.Serializable;

import org.jboss.seam.ScopeType;
Expand All @@ -12,13 +11,9 @@
import org.jboss.seam.annotations.security.Restrict;
import org.jboss.seam.security.Identity;
import org.zanata.ApplicationConfiguration;
import org.zanata.async.AsyncHandle;
import org.zanata.async.AsyncTaskHandle;
import org.zanata.async.tasks.ZipFileBuildTask;
import org.zanata.dao.ProjectIterationDAO;
import org.zanata.process.IterationZipFileBuildProcess;
import org.zanata.process.IterationZipFileBuildProcessHandle;
import org.zanata.process.ProcessHandle;
import org.zanata.service.ProcessManagerService;
import org.zanata.service.impl.AsyncTaskManagerServiceImpl;

@Name("projectIterationZipFileAction")
Expand All @@ -43,7 +38,7 @@ public class ProjectIterationZipFileAction implements Serializable

private String localeId;

private AsyncHandle<String> zipFilePrepHandle;
private AsyncTaskHandle<String> zipFilePrepHandle;

@Begin(join = true)
@Restrict("#{s:hasPermission(projectIterationZipFileAction.projectIteration, 'download-all')}")
Expand Down Expand Up @@ -104,12 +99,12 @@ public void setLocaleId(String localeId)
this.localeId = localeId;
}

public AsyncHandle<String> getZipFilePrepHandle()
public AsyncTaskHandle<String> getZipFilePrepHandle()
{
return zipFilePrepHandle;
}

public void setZipFilePrepHandle(AsyncHandle<String> zipFilePrepHandle)
public void setZipFilePrepHandle(AsyncTaskHandle<String> zipFilePrepHandle)
{
this.zipFilePrepHandle = zipFilePrepHandle;
}
Expand Down
Expand Up @@ -14,7 +14,7 @@
import org.joda.time.Period;
import org.joda.time.format.PeriodFormatter;
import org.joda.time.format.PeriodFormatterBuilder;
import org.zanata.async.AsyncHandle;
import org.zanata.async.AsyncTaskHandle;

@Name("reindexAction")
@Scope(ScopeType.APPLICATION)
Expand Down Expand Up @@ -114,7 +114,7 @@ public String getCurrentClass()

public boolean isError()
{
AsyncHandle<Boolean> taskHandle = reindexAsync.getProcessHandle();
AsyncTaskHandle<Boolean> taskHandle = reindexAsync.getProcessHandle();
if( taskHandle == null )
{
return false;
Expand Down
17 changes: 7 additions & 10 deletions zanata-war/src/main/java/org/zanata/action/ReindexAsyncBean.java
Expand Up @@ -18,9 +18,8 @@
import org.jboss.seam.annotations.Scope;
import org.jboss.seam.annotations.Startup;
import org.jboss.seam.log.Log;
import org.zanata.async.AsyncHandle;
import org.zanata.async.AsyncTaskHandle;
import org.zanata.async.AsyncTask;
import org.zanata.async.SimpleAsyncTask;
import org.zanata.model.HAccount;
import org.zanata.model.HGlossaryEntry;
import org.zanata.model.HGlossaryTerm;
Expand All @@ -34,8 +33,6 @@
import org.zanata.search.SimpleClassIndexingStrategy;
import org.zanata.service.impl.AsyncTaskManagerServiceImpl;

import lombok.AllArgsConstructor;

@Name("reindexAsync")
@Scope(ScopeType.APPLICATION)
@Startup
Expand All @@ -59,7 +56,7 @@ public class ReindexAsyncBean implements Serializable
private LinkedHashMap<Class<?>, ReindexClassOptions> indexingOptions = new LinkedHashMap<Class<?>, ReindexClassOptions>();
private Class<?> currentClass;

private AsyncHandle<Boolean> handle;
private AsyncTaskHandle<Boolean> handle;

@Create
public void create()
Expand Down Expand Up @@ -119,7 +116,7 @@ public List<ReindexClassOptions> getReindexOptions()
return result;
}

public AsyncHandle<Boolean> getProcessHandle()
public AsyncTaskHandle<Boolean> getProcessHandle()
{
return handle;
}
Expand Down Expand Up @@ -192,16 +189,16 @@ ClassIndexer getIndexer(Class<?> clazz)
* Private reindex Asynchronous task.
* NB: Separate from the main Bean class as it is not recommended to reuse async tasks.
*/
private class ReindexTask implements AsyncTask<Boolean, AsyncHandle<Boolean>>
private class ReindexTask implements AsyncTask<Boolean, AsyncTaskHandle<Boolean>>
{
private AsyncHandle<Boolean> handle;
private AsyncTaskHandle<Boolean> handle;

@Override
public AsyncHandle<Boolean> getHandle()
public AsyncTaskHandle<Boolean> getHandle()
{
if( handle == null )
{
handle = new AsyncHandle<Boolean>();
handle = new AsyncTaskHandle<Boolean>();
handle.setMaxProgress( getTotalOperations() );
}
return handle;
Expand Down
Expand Up @@ -31,12 +31,12 @@
import org.jboss.seam.annotations.security.Restrict;
import org.jboss.seam.faces.FacesMessages;
import org.jboss.seam.framework.EntityHome;
import org.zanata.async.AsyncTaskHandle;
import org.zanata.async.SimpleAsyncTask;
import org.zanata.dao.TransMemoryDAO;
import org.zanata.model.tm.TransMemory;
import org.zanata.process.ProcessHandle;
import org.zanata.process.RunnableProcess;
import org.zanata.service.ProcessManagerService;
import org.zanata.service.SlugEntityService;
import org.zanata.service.impl.AsyncTaskManagerServiceImpl;
import com.google.common.base.Optional;

import lombok.AllArgsConstructor;
Expand All @@ -60,7 +60,7 @@ public class TranslationMemoryAction extends EntityHome<TransMemory>
private SlugEntityService slugEntityServiceImpl;

@In
private ProcessManagerService processManagerServiceImpl;
private AsyncTaskManagerServiceImpl asyncTaskManagerServiceImpl;

private List<TransMemory> transMemoryList;

Expand Down Expand Up @@ -91,17 +91,17 @@ public boolean validateSlug(String slug, String componentId)

public void clearTransMemory(final String transMemorySlug)
{
processManagerServiceImpl.startProcess(
new RunnableProcess<ProcessHandle>()
asyncTaskManagerServiceImpl.startTask(
new SimpleAsyncTask<Void>()
{
@Override
protected void run(ProcessHandle handle) throws Throwable
public Void call() throws Exception
{
TransMemoryDAO transMemoryDAO = (TransMemoryDAO) Component.getInstance(TransMemoryDAO.class);
transMemoryDAO.deleteTransMemoryContents(transMemorySlug);
return null;
}
},
new ProcessHandle(),
new ClearTransMemoryProcessKey(transMemorySlug)
);

Expand All @@ -125,8 +125,9 @@ public void deleteTransMemory(String transMemorySlug)

public boolean isTransMemoryBeingCleared(String transMemorySlug)
{
ProcessHandle handle = processManagerServiceImpl.getProcessHandle( new ClearTransMemoryProcessKey(transMemorySlug) );
return handle != null && !handle.isFinished();
AsyncTaskHandle<Void> handle =
asyncTaskManagerServiceImpl.getHandleByKey(new ClearTransMemoryProcessKey(transMemorySlug));
return handle != null && !handle.isDone();
}

public boolean deleteTransMemoryDisabled(String transMemorySlug)
Expand Down
2 changes: 1 addition & 1 deletion zanata-war/src/main/java/org/zanata/async/AsyncTask.java
Expand Up @@ -25,7 +25,7 @@
/**
* @author Carlos Munoz <a href="mailto:camunoz@redhat.com">camunoz@redhat.com</a>
*/
public interface AsyncTask<V, H extends AsyncHandle<V>> extends Callable<V>
public interface AsyncTask<V, H extends AsyncTaskHandle<V>> extends Callable<V>
{

H getHandle();
Expand Down
Expand Up @@ -33,7 +33,7 @@
*
* @author Carlos Munoz <a href="mailto:camunoz@redhat.com">camunoz@redhat.com</a>
*/
public class AsyncHandle<V> extends AbstractFuture<V>
public class AsyncTaskHandle<V> extends AbstractFuture<V>
{
@Getter @Setter
public int maxProgress = 100;
Expand Down
6 changes: 3 additions & 3 deletions zanata-war/src/main/java/org/zanata/async/AsyncUtils.java
Expand Up @@ -39,7 +39,7 @@ public class AsyncUtils
{
private static final String ASYNC_HANDLE_NAME = "__ASYNC_HANDLE__";

public static final void outject( AsyncHandle<?> handle, ScopeType scopeType)
public static final void outject( AsyncTaskHandle<?> handle, ScopeType scopeType)
{
if(scopeType.isContextActive())
{
Expand All @@ -51,12 +51,12 @@ public static final void outject( AsyncHandle<?> handle, ScopeType scopeType)
}
}

public static final <H extends AsyncHandle> Optional<H> getEventAsyncHandle( Class<H> type )
public static final <H extends AsyncTaskHandle> Optional<H> getEventAsyncHandle( Class<H> type )
{
return getAsyncHandle(ScopeType.EVENT, type);
}

public static final <H extends AsyncHandle> Optional<H> getAsyncHandle(ScopeType scopeType, Class<H> type)
public static final <H extends AsyncTaskHandle> Optional<H> getAsyncHandle(ScopeType scopeType, Class<H> type)
{
if(scopeType.isContextActive())
{
Expand Down
Expand Up @@ -21,7 +21,6 @@
package org.zanata.async;

import java.security.Principal;
import java.util.Collection;

import javax.security.auth.Subject;

Expand All @@ -30,7 +29,6 @@
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;
import org.jboss.seam.annotations.async.Asynchronous;
import org.jboss.seam.contexts.Context;
import org.jboss.seam.security.Identity;
import org.jboss.seam.security.RunAsOperation;

Expand All @@ -49,7 +47,7 @@
public class AsynchronousTaskExecutor
{
@Asynchronous
public <V, H extends AsyncHandle<V>> void runAsynchronously(final AsyncTask<V, H> task, final Identity runAs)
public <V, H extends AsyncTaskHandle<V>> void runAsynchronously(final AsyncTask<V, H> task, final Identity runAs)
{
AsyncUtils.outject(task.getHandle(), ScopeType.EVENT);

Expand Down
Expand Up @@ -24,12 +24,12 @@

/**
* Simple default partial implementation of an async task that produces a bare bones
* {@link AsyncHandle} that tracks progress.
* {@link AsyncTaskHandle} that tracks progress.
*
* @author Carlos Munoz <a href="mailto:camunoz@redhat.com">camunoz@redhat.com</a>
*/
public abstract class SimpleAsyncTask<V> implements AsyncTask<V, AsyncHandle<V>>
public abstract class SimpleAsyncTask<V> implements AsyncTask<V, AsyncTaskHandle<V>>
{
@Getter
private final AsyncHandle<V> handle = new AsyncHandle<V>();
private final AsyncTaskHandle<V> handle = new AsyncTaskHandle<V>();
}
7 changes: 1 addition & 6 deletions zanata-war/src/main/java/org/zanata/async/TaskExecutor.java
Expand Up @@ -20,18 +20,13 @@
*/
package org.zanata.async;

import java.util.Set;

import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.AutoCreate;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;
import org.jboss.seam.contexts.Context;
import org.jboss.seam.security.Identity;

import com.google.common.collect.Sets;

import lombok.extern.slf4j.Slf4j;

/**
Expand All @@ -53,7 +48,7 @@ public class TaskExecutor
*
* @param handle The handle to be used for the running process.
*/
public <V, H extends AsyncHandle<V>> AsyncHandle<V> startTask(AsyncTask<V, H> task)
public <V, H extends AsyncTaskHandle<V>> AsyncTaskHandle<V> startTask(AsyncTask<V, H> task)
{
H handle = task.getHandle();
if( handle == null )
Expand Down
Expand Up @@ -20,16 +20,14 @@
*/
package org.zanata.async;

import lombok.AccessLevel;
import lombok.Getter;
import lombok.Setter;

/**
* An Asynchronous handle that has facility methods to time the duration of the task.
*
* @author Carlos Munoz <a href="mailto:camunoz@redhat.com">camunoz@redhat.com</a>
*/
public class TimedAsyncHandle<V> extends AsyncHandle<V>
public class TimedAsyncHandle<V> extends AsyncTaskHandle<V>
{
@Getter
private long startTime;
Expand Down
Expand Up @@ -24,7 +24,6 @@

import org.jboss.seam.Component;
import org.jboss.seam.security.Identity;
import org.zanata.async.AsyncHandle;
import org.zanata.async.AsyncTask;
import org.zanata.async.TimedAsyncHandle;
import org.zanata.model.HCopyTransOptions;
Expand All @@ -36,7 +35,6 @@
import org.zanata.service.impl.CopyTransServiceImpl;
import org.zanata.service.impl.LocaleServiceImpl;

import lombok.AccessLevel;
import lombok.Getter;
import lombok.Setter;

Expand Down
Expand Up @@ -21,11 +21,10 @@
package org.zanata.async.tasks;

import com.google.common.base.Optional;
import lombok.AllArgsConstructor;
import org.jboss.seam.Component;
import org.zanata.ApplicationConfiguration;
import org.zanata.adapter.po.PoWriter2;
import org.zanata.async.AsyncHandle;
import org.zanata.async.AsyncTaskHandle;
import org.zanata.async.AsyncTask;
import org.zanata.common.LocaleId;
import org.zanata.dao.DocumentDAO;
Expand All @@ -43,9 +42,7 @@
import org.zanata.service.impl.FileSystemServiceImpl;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
Expand All @@ -59,7 +56,7 @@
*
* @author Carlos Munoz <a href="mailto:camunoz@redhat.com">camunoz@redhat.com</a>
*/
public class ZipFileBuildTask implements AsyncTask<String, AsyncHandle<String>>
public class ZipFileBuildTask implements AsyncTask<String, AsyncTaskHandle<String>>
{

private final String projectSlug;
Expand All @@ -68,7 +65,7 @@ public class ZipFileBuildTask implements AsyncTask<String, AsyncHandle<String>>
private final String userName;
private final boolean isOfflinePo;

private AsyncHandle<String> handle;
private AsyncTaskHandle<String> handle;

public ZipFileBuildTask(String projectSlug, String iterationSlug, String localeId, String userName, boolean offlinePo)
{
Expand All @@ -80,7 +77,7 @@ public ZipFileBuildTask(String projectSlug, String iterationSlug, String localeI
}

@Override
public AsyncHandle<String> getHandle()
public AsyncTaskHandle<String> getHandle()
{
if( handle == null )
{
Expand All @@ -89,9 +86,9 @@ public AsyncHandle<String> getHandle()
return handle;
}

private AsyncHandle<String> buildHandle()
private AsyncTaskHandle<String> buildHandle()
{
AsyncHandle<String> newHandle = new AsyncHandle<String>();
AsyncTaskHandle<String> newHandle = new AsyncTaskHandle<String>();

// Max documents to process
DocumentDAO documentDAO = (DocumentDAO) Component.getInstance(DocumentDAO.class);
Expand Down

0 comments on commit 1a3e26d

Please sign in to comment.